bitfab 0.21.2 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bitfab/constants.rb +4 -0
- data/lib/bitfab/replay.rb +20 -7
- data/lib/bitfab/version.rb +1 -1
- data/lib/bitfab.rb +23 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d3286f80b5a55bff760f454480b1a3662fdf984174ee65d6f195dcbca5d456ed
|
|
4
|
+
data.tar.gz: d1d8bc8e244075f56cc6c06d42dae614da95b4531ea8bafc21de2b84b1d2526a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2ffbf4c36e417d4bf391eb9509a0136bc29dda1e54e191c84b51a59c400821fe7c21dbb796d272eaaca30f72502160d3aa8cb93efe1159304778422ac70ca9c1
|
|
7
|
+
data.tar.gz: 2dac975acb96571c6e7303ac7632cf3b099f3884ce3bf7f499dbfb35c71c357674868210906ebc6864dabb3a6645b7f82e41b4b8559553ab2a93304e2d106871
|
data/lib/bitfab/constants.rb
CHANGED
|
@@ -3,4 +3,8 @@
|
|
|
3
3
|
module Bitfab
|
|
4
4
|
DEFAULT_SERVICE_URL = "https://bitfab.ai"
|
|
5
5
|
REPLAY_CONTEXT_KEY = :__bitfab_replay_context
|
|
6
|
+
|
|
7
|
+
# Wire prefix the Bitfab plugin scans for on stderr to report live progress
|
|
8
|
+
# while a replay runs. One trailing space, then the progress object as JSON.
|
|
9
|
+
BITFAB_PROGRESS_PREFIX = "@@bitfab:progress "
|
|
6
10
|
end
|
data/lib/bitfab/replay.rb
CHANGED
|
@@ -102,8 +102,12 @@ module Bitfab
|
|
|
102
102
|
# that item's :error rather than crashing the run.
|
|
103
103
|
# @param on_progress [#call, nil] optional callback invoked once per item as
|
|
104
104
|
# it finishes, with a running-totals hash { completed:, total:, succeeded:,
|
|
105
|
-
# errored: }
|
|
106
|
-
#
|
|
105
|
+
# errored:, item: } where item is { trace_id:, error:, duration_ms: } for
|
|
106
|
+
# the single item that just settled. trace_id is the SOURCE (historical)
|
|
107
|
+
# trace that was replayed, error is that item's replay error or nil, and
|
|
108
|
+
# duration_ms is how long that one trace took to replay. Use it to
|
|
109
|
+
# render replay progress (e.g. a per-trace log). A raising callback never
|
|
110
|
+
# crashes the run.
|
|
107
111
|
# @return [Hash] with :items, :test_run_id, :test_run_url
|
|
108
112
|
def run(client, receiver, method_name, trace_function_key:, limit: nil, trace_ids: nil, max_concurrency: 10,
|
|
109
113
|
code_change_description: nil, code_change_files: nil, experiment_group_id: nil, dataset_id: nil, mock: "none",
|
|
@@ -254,14 +258,23 @@ module Bitfab
|
|
|
254
258
|
completed = 0
|
|
255
259
|
succeeded = 0
|
|
256
260
|
errored = 0
|
|
257
|
-
|
|
261
|
+
# Each event carries the single item that just settled so a progress UI
|
|
262
|
+
# can render per-trace pass/fail as the run streams. trace_id is the
|
|
263
|
+
# SOURCE (historical) trace that was replayed, taken from the server
|
|
264
|
+
# item: the result's own :trace_id at this stage is the new replay
|
|
265
|
+
# trace id (assigned in run() after complete_replay), not the source.
|
|
266
|
+
report = lambda do |result, source_trace_id|
|
|
258
267
|
return unless on_progress
|
|
259
268
|
|
|
260
269
|
progress_mutex.synchronize do
|
|
261
270
|
completed += 1
|
|
262
|
-
result[:error]
|
|
271
|
+
error = result[:error]
|
|
272
|
+
error.nil? ? (succeeded += 1) : (errored += 1)
|
|
263
273
|
begin
|
|
264
|
-
on_progress.call({
|
|
274
|
+
on_progress.call({
|
|
275
|
+
completed:, total:, succeeded:, errored:,
|
|
276
|
+
item: {trace_id: source_trace_id, error:, duration_ms: result[:duration_ms]}
|
|
277
|
+
})
|
|
265
278
|
rescue => e
|
|
266
279
|
warn "Bitfab: replay on_progress callback raised: #{e.message}"
|
|
267
280
|
end
|
|
@@ -272,7 +285,7 @@ module Bitfab
|
|
|
272
285
|
server_items.map do |item|
|
|
273
286
|
result = process_single_item(http_client, item, receiver, method_name, test_run_id, mock_strategy,
|
|
274
287
|
adapt_inputs, include_db_branch_lease)
|
|
275
|
-
report.call(result)
|
|
288
|
+
report.call(result, item["traceId"])
|
|
276
289
|
result
|
|
277
290
|
end
|
|
278
291
|
else
|
|
@@ -290,7 +303,7 @@ module Bitfab
|
|
|
290
303
|
result = process_single_item(http_client, item, receiver, method_name, test_run_id, mock_strategy,
|
|
291
304
|
adapt_inputs, include_db_branch_lease)
|
|
292
305
|
results_mutex.synchronize { results[idx] = result }
|
|
293
|
-
report.call(result)
|
|
306
|
+
report.call(result, item["traceId"])
|
|
294
307
|
end
|
|
295
308
|
end
|
|
296
309
|
end
|
data/lib/bitfab/version.rb
CHANGED
data/lib/bitfab.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
3
5
|
require_relative "bitfab/version"
|
|
4
6
|
require_relative "bitfab/constants"
|
|
5
7
|
require_relative "bitfab/warn_once"
|
|
@@ -103,5 +105,26 @@ module Bitfab
|
|
|
103
105
|
|
|
104
106
|
CurrentTrace.new(entry[:trace_id])
|
|
105
107
|
end
|
|
108
|
+
|
|
109
|
+
# A ready-made on_progress callback for replay: writes one @@bitfab:progress
|
|
110
|
+
# line per trace to stderr, which the Bitfab plugin polls to report live
|
|
111
|
+
# progress while the replay runs in the background, so replay scripts never
|
|
112
|
+
# hand-format the protocol. stdout stays the ReplayResult JSON. Never raises
|
|
113
|
+
# (progress must not crash a run). The progress hash's item ({ trace_id:,
|
|
114
|
+
# error:, duration_ms: }) is forwarded verbatim through to_json, so the
|
|
115
|
+
# plugin sees the source trace id, error, and duration of the item that just
|
|
116
|
+
# settled.
|
|
117
|
+
#
|
|
118
|
+
# @example
|
|
119
|
+
# Bitfab.client.replay(..., on_progress: Bitfab.method(:report_replay_progress))
|
|
120
|
+
#
|
|
121
|
+
# @param progress [Hash] running totals with keys completed, total,
|
|
122
|
+
# succeeded, errored, and item (the object replay already passes to
|
|
123
|
+
# on_progress)
|
|
124
|
+
def report_replay_progress(progress)
|
|
125
|
+
warn "#{BITFAB_PROGRESS_PREFIX}#{progress.to_json}"
|
|
126
|
+
rescue
|
|
127
|
+
nil
|
|
128
|
+
end
|
|
106
129
|
end
|
|
107
130
|
end
|