Repository navigation
feat(prom): export arbitrary-command hits/misses as new counter series - #484
Merged
Merged
Conversation
Closes #483. The exporter (#468) reported memtier_hits_total / memtier_misses_total from the GET path only; arbitrary-command (--command) hits/misses tracked in run_stats m_arbitrary_misses[] were never surfaced, so a --command workload showed 0 in /metrics while console/JSON showed nonzero. Add two new aggregate COUNTER series — memtier_arbitrary_hits_total and memtier_arbitrary_misses_total (Option B: additive, GET series values unchanged, no per-command label per the v1 cardinality rule). A combined total is one PromQL sum(); folding into the existing series (Option A) was rejected because it would silently redefine a shipped monotonic counter and destroy GET-vs-arbitrary decomposability. Race-free by construction: new client_group/run_stats accessors sum only the per-command scalar totals in m_arbitrary_misses[] (never the per-key vectors the worker grow-resizes), read at the single off-worker producer point (prom_read_cg_counters) alongside the GET totals, so they inherit the monotonic accumulator and the cross-run/restart fold with no new publish site and no new hot-path work. - prometheus_metrics.{h,cpp}: MT_ARBITRARY_HITS/MISSES enum slots before MT_NUM_COUNTERS; two kMetricDefs rows inserted in the contiguous counter block (after retried_ops_total, before connections) so the render loop's def-vs-enum lockstep holds; counter_metric_name cases; GET HELP reworded to forward-reference the new series (values unchanged); render comments made range-relative. - run_stats / client_group: get_total_arbitrary_hits/misses (unsigned long long; the source fields are 64-bit). - memtier_benchmark.cpp: fill the two slots in prom_read_cg_counters. Tests: - Unit U10: positional placement guard, full sentinel render proving every counter index renders its own value (GET series NOT folded; new series at their enum index), and HELP honesty. - Integration F21 (surfaced + exact Option-B leak guard: GET series stay 0 under an arbitrary-only workload), F22 (arbitrary series present and 0 without --command), F23 (cluster aggregation), F24 (accumulation across run boundary via memtier_run). Verified: make check (U1-U10), prometheus RLTest standalone 24/25 (F19 fails only on local redis rejecting DEBUG SLEEP), --disable-prometheus builds and links, clang-format clean. Co-Authored-By: Claude Opus 4.8 <[email protected]>
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
The new race-free producer read of m_arbitrary_misses[] (#483) trips ThreadSanitizer the same way every other live counter getter does: the main thread sums total_hits/total_misses while workers bump them in update_arbitrary_op_misses. Verified locally (TSan build, setarch -R) that without these entries TSan reports the race at run_stats::get_total_arbitrary_hits (run_stats.cpp:501), get_total_arbitrary_misses (:509) and the writer (:412-413), and that adding them yields a clean run. It is benign by the same reasoning as the existing getter suppressions: the read touches only the monotonic scalar totals (never the grow-resized per_key_* vectors; the outer m_arbitrary_misses vector is sized once in setup_arbitrary_commands and not resized mid-run), live values are approximate, and authoritative totals merge race-free post-join. Co-Authored-By: Claude Opus 4.8 <[email protected]>
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.
Closes #483. Follow-up to the built-in Prometheus exporter (#468).
Problem
The exporter reports
memtier_hits_total/memtier_misses_totalfrom the GET path only. Arbitrary-command (--command) hits/misses are tracked separately inrun_stats m_arbitrary_misses[]and were never surfaced — a--command "GET __key__"workload showed0in/metricswhile the console and JSON output showed nonzero counts.Approach — Option B (additive), chosen over folding
Add two new aggregate COUNTER series;
memtier_hits_total/memtier_misses_totalvalues are unchanged (only their HELP text gains a forward reference):Aggregate, no per-command label (respects the v1 cardinality decision). A grand total is one PromQL expression:
sum(memtier_hits_total) + sum(memtier_arbitrary_hits_total).Folding arbitrary into the existing series (Option A) was rejected: it silently redefines a shipped monotonic counter's meaning across a binary upgrade (stepping every
rate()/hit-ratio rule with no series rename to signal it) and destroys GET-vs---commanddecomposability. B costs two enum slots + two def rows + two accessors and never breaks a scraper; the race-safety work is identical either way.This design was produced by 7 independent implementation proposals, synthesized, then vetted by 7 adversarial maintainer-persona reviews (using the repo's review bars).
Race safety
New
client_group/run_statsaccessors sum only the per-command scalar totals inm_arbitrary_misses[](never theper_key_*vectors the worker grow-resizes), read at the single off-worker producer pointprom_read_cg_countersalongside the GET totals. They therefore inherit the monotonic accumulator and the cross-run/restart fold with no new publish site and no new hot-path work — the same TSan-documented benign-race class as the existing scalar getters.Changes
prometheus_metrics.{h,cpp}:MT_ARBITRARY_HITS/MT_ARBITRARY_MISSESenum slots beforeMT_NUM_COUNTERS; twokMetricDefsrows inserted in the contiguous counter block (aftermemtier_retried_ops_total, beforememtier_connections) so the render loop's def-vs-enum lockstep holds;counter_metric_namecases; GET HELP reworded to forward-reference the new series (values unchanged); render ordinal comments made range-relative.run_stats/client_group:get_total_arbitrary_hits/misses(unsigned long long— the source fields are 64-bit).memtier_benchmark.cpp: fill the two slots inprom_read_cg_counters.Notes for review (intentional)
run_statsstate, not theclient.hflat-scalar block).0without a miss-trackable--command(stable presence beats appearing/disappearing).HAVE_EVHTTPproducer (verified--disable-prometheusstill links).HMGETincrements per element), matching howm_arbitrary_missesis recorded.Tests
prom::metric_defs(); a full sentinel render (counters[m] = 1000+m) asserting every counter index renders its own value — proving the GET series are NOT folded and the new series render at their enum index; HELP honesty.F21(series populated + exact Option-B leak guard: GET series stay0under an arbitrary-only workload),F22(arbitrary series present and0without--command),F23(cluster aggregation — no partial-shard loss / no double-count),F24(accumulation across the run boundary, tracked viamemtier_run).F5(the exporter dies with the process, so the last pre-exit scrape lags the final JSON by the in-flight second; an exact scrape==JSON identity would be flaky — the exactness lives in U10 and the leak guard).Verified locally:
make check(U1–U10), prometheus RLTest standalone 24/25 (the one miss isF19, which needsDEBUG SLEEPthe local redis rejects; it passes in CI),--disable-prometheusbuilds and links,clang-formatclean.🤖 Generated with Claude Code
Note
Low Risk
Observability-only additive metrics sampled off the worker path; existing GET counter values and semantics are preserved.
Overview
Adds
memtier_arbitrary_hits_totalandmemtier_arbitrary_misses_totalso--commandmiss-trackable workloads show up in/metricswithout changingmemtier_hits_total/memtier_misses_total(GET-only; HELP text now points at the new series).run_stats/client_groupgain aggregators that sum per-command scalar totals inm_arbitrary_misses[](not per-key vectors). The 1 Hz Prometheus producer fills the newMT_ARBITRARY_*slots inprom_read_cg_counters, with TSan suppressions for the same benign read-while-worker-update pattern as other live getters.Tests: unit U10 (metric def order + sentinel render), integration F21–F24 (isolation from GET series, cluster, cross-run accumulation), and updated counter name lists.
Reviewed by Cursor Bugbot for commit b238820. Bugbot is set up for automated code reviews on this repo. Configure here.