Repository navigation
fix(go): preserve benchmark results in pipe filtering - #4927
TechWizard9999 wants to merge 5 commits into
Conversation
Co-authored-by: Copilot <[email protected]>
📊 Automated PR Analysis
SummaryFixes Go test JSON filtering so benchmark result lines (from go test -json/-bench output) are buffered and preserved instead of being dropped or leaked as raw JSON. Adds logic to detect benchmark test names/result lines, flush trailing buffered output, and format benchmark summaries alongside passing, failing, and fuzz results. Review Checklist
Linked issues: #4862 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
Benchmark result lines were deduplicated per package, so a -count=N run that printed identical samples collapsed them into one and dropped benchmark output. Keep every result line, and add regression tests for -count samples and the issue rtk-ai#4862 quiet-mode b.Log stream.
KuSh
left a comment
There was a problem hiding this comment.
Round 1 — CHANGES REQUESTED
Claim: rtk pipe -f go-test keeps the benchmark result lines of a go test -json -bench stream instead of reducing it to test counts (#4862).
Scope: accept (round 1, frozen); maintainer PRs: none overlap.
Ran: real go test -json -bench streams from Go 1.24.6 and 1.26.1 (quiet -v=false and chatty; -benchmem; -count 2; sub-benchmarks; b.Skip; b.Log; a failing benchmark; failing unit test; 2 packages; -fuzz + -bench; a benchmark printing to stdout; 19 streams) and the captured fixtures in tests/fixtures/go_test_pipe/, through rtk pipe -f go-test and auto mode, develop vs this branch merged on develop; plain rtk go test on a package without benchmarks; invariants: every decision, merge with latest develop; savings 92–96% vs 20% floor (CONTRIBUTING.md).
Pins: 22 decisions, 22 mutated, 11 survived the suite (benchmark names added on fail/output/run, skipped benchmark counted as skip, each classifier branch alone, empty-rest guard, \r trim, fuzz-path append, package sort, empty-package filter); 3 more are killed only by tests built on benchmark pass events, which Go does not emit.
Matrix: executed this round; pin check: executed this round
CI @1d3e20f7: all green on the branch; 8 tests fail after merging develop (item 3).
Splitting the line across events is needed. With -v=false, Go prints BenchmarkX-24 \t before the run and 10\t 6719 ns/op\n after it, and test2json emits the two halves as separate output events (same on 1.24.6 and 1.26.1). In that mode the Test field is also wrong: BenchmarkSub results are tagged BenchmarkX-24, and BenchmarkGood results are tagged BenchmarkFail. So per-package reassembly is the right level. In chatty mode the line comes in one event.
Blocks merge (3, frozen at round 1)
-
src/cmds/go/go_cmd.rs:592— the benchmark count does not count benchmarks.benchmark_countismax(distinct Test names, result rows). Names come fromrun/output/skip/failevents, so they include the parent of sub-benchmarks and skipped benchmarks. Evidence: on Go 1.26.1, one run ofBenchmarkX,BenchmarkSub/{n=0,n=1}andBenchmarkSkipprints1 passed, 5 benchmarksabove 3 rows in chatty mode, and3 benchmarksin quiet mode. The skip arm also moves a skipped benchmark out of, N skipped. Thepassarm never fires, because benchmarks get nopassevent on either Go version. The result rows are already the summary, so the smallest fix is to dropbenchmark_namesand the five arms that feed it, and count rows. Test must: the quiet and chatty captures of the same run report the same count, equal to the number of rows. -
src/cmds/go/go_cmd.rs:569,:625— every output byte of every package goes through benchmark reassembly, and a substring decides what counts as a result. This also runs on plainrtk go test, which never carries benchmarks:run_testsends-bench*runs through raw.- Regression on develop's main path: a passing test that prints
Benchmarks loaded from /srv/data(matches/s) andBenchmarkConfig 3 2givesGo test: 1 passed, 2 benchmarks in 1 packagesand prints both lines as rows. Develop printsGo test: 1 passed in 1 packages. - The claimed quiet case is still lost when a benchmark writes to stdout during its run. Real 1.26.1 stream:
BenchmarkPrint-24 \t, thenwarming cache\n, then10\t 2663 ns/op\n. The name joins the unrelated line, and the output is stillGo test: No tests found. - The buffer keeps a copy of all output and rescans it for each chunk: 9.7 MB of output without newlines takes 0.557 s against 0.021 s on develop.
All 47 real result lines across both Go versions have the shape
name, integer iterations, value, unit…, so the substring branch never accepts a real line that the numeric branch would refuse. What a fix has to satisfy: hold only a pending fragment that is a bare benchmark name (Benchmark…plus whitespace, no newline), and join it with the next fragment that starts with the iteration count. Classify by that layout, and only on events with noTestor aBenchmark…Test. Test must: the stdout lines above stay out of plainrtk go testoutput (mutation: drop the scope or layout check), and theBenchmarkPrintquiet stream keeps its row. - Regression on develop's main path: a passing test that prints
-
Fails on develop after merge: develop's
tests/go_test_pipe_test.rs(8 tests) pins the old output on real captured streams that contain a benchmark, for examplecaptured_core_events_are_consumed_not_returned_rawexpectsGo test: 3 passed in 2 packages. The new output on those fixtures is correct (3 passed, 1 benchmark+ theBenchmarkLogged-9row). Please rebase and update those expectations, including the "the existing reducer counts tests only" assertion onlegacy_bench.jsonl. Those fixtures andcapture.share real producer output; a-v=falsecapture added there would cover the quiet case the issue is about.
Optional — will not hold merge
- Tests:
test_go_test_wrapper_benchmark_json(pipe_cmd.rs:374) andpipe_go_test_preserves_benchmark_split_chunks(tests/pipeline_stdin_test.rs:64) repeat the input oftest_filter_go_test_bench_vfalse_split_chunksword for word.go_test_wrapperis a one-line call, and no mutation was caught by those two alone. Three more unit tests (…_bench_only_no_unit_tests,…_vfalse_with_b_log_issue_4862,…_vfalse_split_chunks) cover the same quiet split.…_suppresses_passing_b_log_noise,…_benchmark_pass_is_not_unit_test_passand…_with_unit_failure_preserves_benchmarkare built on benchmarkpassevents. With item 1 most of these go away; a few captured streams (quiet, chatty,-count, failing benchmark next to a passing one) would replace them. …_buffers_and_sorts_packagespasses with the sort removed (HashMap order), so it pins nothing. The fuzz-path append has no test, and1.26.1-fuzz+-benchprints the package heading twice with no blank line between the blocks..trim_end_matches('\r')is dead:add_go_benchmark_output_linetrims the line again. The_ => {} // run, pause, cont, etc.comment still listsrun.
Follow-ups
- #5215 Quiet-mode failing benchmark shows
goos: linuxas failure context — pre-existing (v1.2.1 and develop), outside this PR's hunks; filed.
Checked and correct — no need to re-verify
- Quiet and chatty, single and multiple packages,
-benchmem,-count 2(every sample kept), sub-benchmarks, final tail without a newline, failing benchmark next to a passing one, auto mode (rtk pipewithout-f): rows match Go's output on both versions. - fmt and clippy are clean on the merge; apart from item 3, the full suite passes (5819 tests).
Next
Items 1–3: count result rows instead of names, scope the reassembly to a pending benchmark-name fragment classified by layout, rebase and update develop's pipe tests.
Rounds: 1. Threads: 3 open (waiting on the author), 0 resolved this round.
…erve-benchmark-results
The benchmark count now counts result rows: Go sends no pass event for a benchmark, a parent of sub-benchmarks prints no row, and a skipped benchmark stays in the skip count. Instead of buffering every output byte, only a bare benchmark name fragment is held and joined with the half that completes it into a row, so stdout printed between the halves no longer loses the row. Rows are classified by layout (name, integer iterations, value and unit pairs, or no pairs when the run was too fast to time) and only from package-level or Benchmark events, so a unit test's own stdout is never a row. With -fuzz, the rows sit under the fuzzed package's heading. Adds real Go 1.27.4 captures of one run in chatty and quiet mode and of -fuzz with -bench, and updates the captured-stream tests whose benchmark row is now kept.
|
@KuSh Round 1 addressed in 11fd14f (develop merged in a63c8f8). Two Go behaviours from the new captures (Go 1.27.4, windows/arm64) differ from the round-1 notes:
Also: the pending name is kept only when the next fragment completes a valid row, so stdout between the halves ( |
KuSh
left a comment
There was a problem hiding this comment.
Round 2 — CHANGES REQUESTED
Claim: rtk pipe -f go-test keeps the benchmark result lines of a go test -json -bench stream instead of reducing it to test counts (#4862).
Scope: accept (round 1, frozen); maintainer PRs: none overlap.
Ran: real go test -json -bench streams from Go 1.24.6 and 1.26.1, chatty and -v=false (sub-benchmarks, b.Skip, b.Log, -count with -benchmem, 2 packages, a failing benchmark beside a passing one, stdout during a run, ReportMetric/SetBytes, -benchtime 1x, -fuzz with -bench, fmt.Println(b.N), func Benchmark with -cpu 1; 36 streams) plus the PR's go_test_pipe fixtures, through rtk pipe -f go-test and auto mode, develop vs this branch merged on develop; plain rtk go test on packages whose tests or TestMain print Benchmark… lines; 9.6 MB of output without newlines. Invariants: split streams, every decision, merge with latest develop. Savings 90–97% vs the 20% floor (CONTRIBUTING.md).
Pins: 24 decisions mutated, 3 survived: keeping whole-row samples undeduplicated (item 2); the fuzz package sort (develop's existing behaviour, rewritten); replacing a pending name (no captured stream reaches it).
Matrix: executed this round; pin check: executed this round
CI @11fd14f4: all green (16/16); merged on develop: fmt, clippy, 5964 tests pass.
Round 1's three items are closed. The count now equals the rows: chatty and quiet captures of the same run agree (3 = 3, 6 = 6, 2 = 2). Unit-test stdout no longer becomes a row. The no-newline stream takes 0.024 s (develop 0.029 s). The develop tests carry real captures. Both Go behaviours from your comment are confirmed in bench_chatty.jsonl, and the new rows handle them.
Blocks merge (2: round 1 items closed; +1 new in 11fd14f, +1 unpinned)
-
src/cmds/go/go_cmd.rs:737— lines Go did not print as rows are read as rows (new in 11fd14f). Package-level output reachesis_go_benchmark_result_line(theTest-less scope I asked for in round 1), andname + integeris now a row. Two real Go 1.26.1 cases:- plain
rtk go teston a package whoseTestMainprintsBenchmarks: 3:Go test: 1 passed, 1 benchmark in 1 packageswith that line as a row; develop printsGo test: 1 passed in 1 packages. - quiet
-benchon a benchmark that runsfmt.Println(b.N): the10it prints completes the pending name, so the output is the rowBenchmarkN-24 \t10and the real10 1178 ns/opis dropped (with-benchtime 100ms:100instead of573299739 0.2005 ns/op).
What Go prints, measured on every captured row: the name is
Benchmarkalone or followed by an identifier whose first letter is not lowercase (cmd/go refusesBenchmarklower), then-Nand/subparts; the name ends with spaces and a tab; a row with no measurement has its count right-aligned in eight columns (%8d,2). Rows a fix must pass: the two cases above give1 passed in 1 packagesand the real measurement; every other captured stream (the 36 above and the PR's fixtures) is unchanged,BenchmarkSub/n=1-12 \t 2included. - plain
-
src/cmds/go/go_cmd.rs:713— unpinned behaviour (whole rows keep identical samples). Evidence: adding a dedup toadd_go_benchmark_rowpasses every test; the existing identical-sample test only goes through the quiet join. Real case: chatty-count 6 -benchtime 1xsends whole rows (the later ones at package level) and two are byte-identical (1 130.0 ns/op). Test must: that stream reports6 benchmarksand both identical rows; the dedup mutation turns it red.
Follow-ups
- #5215 (quiet failing benchmark shows
goos: linuxas failure context) — pre-existing, unchanged by this PR.
Checked and correct — no need to re-verify
- Counts and rows on all 36 Go streams and the PR's fixtures, including
-countrepeats,-benchmem,MB/sand custom metrics,-cpu 1, the fuzz heading, the stdout line between a quiet row's halves. - Plain
rtk go testwithBenchmark…-shaped stdout from a test, in chatty mode. - The develop pipe tests updated to the new output; the duplicated wrapper and stdin tests removed.
Your questions
- "Chatty mode also splits a row" → confirmed in your capture (Linux 1.24.6/1.26.1 send it whole); both forms are handled.
- "A run shorter than the timer resolves prints no measurement" → confirmed; keep that form, with the eight-column count from item 1.
Next
Items 1 and 2; after that this merges.
A row is the name ended by a tab, the iteration count, then value and unit pairs, or a count alone padded by %8d. A TestMain printing "Benchmarks: 3" or a benchmark printing its own b.N is no longer a row. Whole and rejoined rows share one push, so identical -count samples are pinned by a real chatty -count=6 capture.
Summary
rtk pipe -f go-testreduced ago test -json -benchstream to test counts and dropped every benchmark result (#4862). It now keeps the result rows Go prints, under their package, and counts them:outputevents (quiet mode; chatty repeats on Windows). Stdout the benchmark writes between the two does not break the row.%8d, when the run was too fast for the timer. ATestMainprintingBenchmarks: 3, or a benchmark printing its ownb.N, is not a row. A unit test's stdout never is.-count(benchstat needs each one).Closes #4862
Tests
Real Go 1.27.4 streams in
tests/fixtures/go_test_pipe/(capture_bench.sh), each with a whole-output assertion intests/go_test_pipe_test.rs, through-f go-testand auto mode:bench_chatty.jsonl,bench_quiet.jsonl: one run, chatty and quiet. Sub-benchmarks, a skip, stdout between a row's halves, a row with no measurement. Both count 4 rows.bench_fuzz.jsonl:-fuzzwith-bench, one package heading.bench_count.jsonl: chatty-count=6 -benchtime=1x: 6 benchmarks, two of them byte-identical.bench_print_n.jsonl: quiet, the benchmark prints100…468991822; only the real row is kept.testmain_stdout.jsonl: plaingo test -json,TestMainprintsBenchmarks: 3:1 passed in 1 packages.Unit tests in
src/cmds/go/go_cmd.rspin the row layout,-benchmem, a failing benchmark, unit-test stdout, and package order.cargo fmt --all --check,cargo clippy --all-targets(0 warnings)cargo test(full suite)