Repository navigation
Disambiguate duplicate per-command JSON keys and HDR file names when --command lines share a name - #588
Merged
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the diff, and the fix looks right to me. Names that occur only once keep their current key and file name, so the usual case doesn't change for anyone reading the JSON. The tests run the exact broken case (two
Neither nitpick blocks anything. The core fix looks solid to me. (I'd post this as a comment, not a formal block.) |
Two --command lines with the same name (e.g. two "GET __key__" lines) were written to the JSON output under the same object key: "Gets" twice in ALL STATS with --command-stats-breakdown=line, "GET" twice for the per-line latency histograms, and "GET" twice in "Per-Key Misses" (in both breakdown modes) and "Arbitrary Read Routing". JSON parsers keep only the last duplicate key, so a whole row was silently dropped and the per-command rows no longer added up to Totals. Names that occur once keep their existing key, so the common case is unchanged for consumers. Each occurrence of a repeated name gets a " #N" suffix (1-based, in --command order, matching the row order of the text table), e.g. "Gets #1"/"Gets #2" and "GET #1"/"GET #2". The text table and CSV are unchanged. Fixes #587 Co-Authored-By: Claude Opus 5.5 <[email protected]>
save_hdr_arbitrary_commands() named each per-command HDR file after
command_name, so two --command lines with the same name (e.g. two
"GET __key__" lines) both wrote <prefix>_GET_command_run_N.{txt,hgrm} and
the second silently overwrote the first, losing one line's histogram.
This happens in both --command-stats-breakdown modes.
Reuse the JSON-key disambiguation (renamed make_unique_labels /
unique_command_labels and moved above its first user): unique names keep
their file name, repeated names get the same " #N" suffix as their JSON
keys, e.g. <prefix>_GET #1_command_run_1.hgrm.
Fixes #587
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tests " #N" is fine as a JSON key, but in a file name an unquoted "#" starts a shell comment (and a URL fragment): `hdr-plot histogram_GET #1_...` receives just "histogram_GET". Keep " #N" for JSON keys and use "_N" for the per-command --hdr-file-prefix files, e.g. <prefix>_GET_1_command_run_1.hgrm. Unique names are unchanged. Tests: - Run the first GET line with --command-ratio=3 so the two lines have different counts, and assert exact per-key Counts plus the decoded histogram sample totals, so a reversed numbering or swapped rows fail. - Cover the "Arbitrary Read Routing" site in test_read_preference_modes.py (replica cluster cell). - Cover a repeated __monitor_line1__. Fixes #587 Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira
force-pushed
the
fix/command-stats-breakdown-json-keys
branch
from
October 14, 2026 03:04
cd9b021 to
139ba83
Compare
Collaborator
Author
|
Thanks for the review. Here is what changed for each point, as of head 139ba83:
Other changes from the follow-up review:
|
This was referenced Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When two
--commandlines share a name, the JSON output repeats the same object key. Two examples:--command="GET __key__" --command="GET __key__"--command="SET foo ..." --command="SET bar ..."On master,
ALL STATShas the keys['Runtime', 'CPU', 'Gets', 'Gets', 'Per-Key Misses', 'Totals', 'CPU Stats', 'GET', 'GET']. JSON parsers keep only the last duplicate, so a whole per-command row disappears and the rows no longer add up toTotals. A review run showed 1676 against 2694.Per-Key Missesrepeats"GET"even in the default--command-stats-breakdown=commandmode.The per-command
--hdr-file-prefixfiles have the same problem. Both lines write<prefix>_GET_command_run_N.{txt,hgrm}, and the second overwrites the first. On master, the surviving.hgrmheld only the second line's 20 samples, and the first line's 60 were lost.Root cause
command_list[i].command_nameis used as an identifier. For a plain--commandit is just the upper-cased first word, so it is not unique per line. It is used at five places:print_json()(pluralized,"Gets")print_histogram()("GET")Per-Key MissesArbitrary Read Routingsave_hdr_arbitrary_commands()Fix
A small helper,
make_unique_labels(names, sep), used throughunique_command_labels(), leaves names that occur once unchanged. Each occurrence of a repeated name getssepplus a 1-based ordinal in output-row order. For user lines, that is--commandorder." #N":"Gets #1","Gets #2","GET #1","GET #2"."_N":<prefix>_GET_1_command_run_1.hgrm. An unquoted#would start a shell comment or a URL fragment.command) rows are already unique by type, so they are unchanged.__monitor_line@__stats slotGETnext to a userGET, or a repeated__monitor_lineN__, is disambiguated the same way.Tests
In all tests the first GET line runs at
--command-ratio=3, so the two lines have different counts and a reversed numbering or swapped rows cannot pass. JSON is loaded with anobject_pairs_hookthat collects duplicate keys.test_monitor_input.py::test_command_stats_breakdown_line_duplicate_json_keys(GET×2 +SET, 300 requests) checks:Gets/GETCounts areGets #1=180,Gets #2=60 andSets=60Totals=300GET #1,GET #2andSEThistogram arrays existPer-Key Misseshits plus misses are 180 forGET #1and 60 forGET #2..._command_duplicate_json_keys(default mode) checks:Gets=240 andSets=60Per-Key MissesisGET #1=180 andGET #2=60..._line_duplicate_monitor_linesuses__monitor_line1__twice (ratio 3/1) and checks:Get (line 1)s #1=225 and#2=75, with matching histogram totalstest_hdr_histogram.py::test_hdr_files_for_duplicate_command_nameschecks:GET_1,GET_2andSETeach have a.txtand a.hgrm.hgrmdecodes to that line's own sample count (60/20/20)GETfile, and no file name contains#or a spacetest_read_preference_modes.py::test_arbitrary_read_routing_duplicate_command_names(replica cluster cell,--read-preference=secondary) checks:Arbitrary Read Routinghas exactlyGET #1andGET #2, with 150 and 50 routed opsResults with RLTest:
['GET', 'GET'] == [])A run on the earlier head e4d14e8 also passed the 3-shard OSS cluster, in 3/3 runs.
Mutation check: all 12 hand-made mutants of
run_stats.cppare killed.#NRegression suites on this branch:
test_monitor_input.pytest_hdr_histogram.pytest_arbitrary_command_misses.pytests_oss_simple_flow.py::test_default_set_get_with_print_percentilestest_read_preference_modes.py(replicas)make format-check-stagedis clean.Note on the review's "first row Misses/sec 0.00 vs 14837": the per-line hit/miss counters are correct. That asymmetry comes from per-command options (
--command-key-pattern,--command-ratio) that attach only to the preceding--command, so the two lines were not really identical. The duplicateGetslabels hid that.Out of scope: a command named
CPUcolliding with the fixedCPUkey will be tracked separately.Fixes #587
Affected versions
1.2.16 (7cdbaff, #72) through 2.5.2 and master.
Getsand histogram duplicates need--command-stats-breakdown=line.Per-Key Misses(2.4.0) is duplicated in both modes.save_hdr_arbitrary_commands()).🤖 Generated with Claude Code