Skip to content

feat(prom): export arbitrary-command hits/misses as new counter series - #484

Merged
fcostaoliveira merged 2 commits into
masterfrom
feat/prom-arbitrary-misses
Jun 17, 2026
Merged

fcostaoliveira merged 2 commits into
masterfrom
feat/prom-arbitrary-misses

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Jun 17, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #483. Follow-up to the built-in Prometheus exporter (#468).

Problem

The exporter reports memtier_hits_total / memtier_misses_total from the GET path only. Arbitrary-command (--command) hits/misses are tracked separately in run_stats m_arbitrary_misses[] and were never surfaced — a --command "GET __key__" workload showed 0 in /metrics while 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_total values are unchanged (only their HELP text gains a forward reference):

memtier_arbitrary_hits_total    counter
memtier_arbitrary_misses_total  counter

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---command decomposability. 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_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. 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_MISSES enum slots before MT_NUM_COUNTERS; two kMetricDefs rows inserted in the contiguous counter block (after memtier_retried_ops_total, before memtier_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 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 in prom_read_cg_counters.

Notes for review (intentional)

  • The accessor pair duplicates the existing GET pair deliberately (mirrors the established pattern; the source lives in per-command run_stats state, not the client.h flat-scalar block).
  • The arbitrary series are always present and read 0 without a miss-trackable --command (stable presence beats appearing/disappearing).
  • The new accessors are always-compiled but consumed only from the HAVE_EVHTTP producer (verified --disable-prometheus still links).
  • HELP says key lookups (a multi-key HMGET increments per element), matching how m_arbitrary_misses is recorded.

Tests

  • Unit U10: positional-placement guard via 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.
  • Integration: F21 (series populated + 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 — no partial-shard loss / no double-count), F24 (accumulation across the run boundary, tracked via memtier_run).
  • Cross-check vs final JSON uses the same tolerance band as the existing 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 is F19, which needs DEBUG SLEEP the local redis rejects; it passes in CI), --disable-prometheus builds and links, clang-format clean.

🤖 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_total and memtier_arbitrary_misses_total so --command miss-trackable workloads show up in /metrics without changing memtier_hits_total / memtier_misses_total (GET-only; HELP text now points at the new series).

run_stats / client_group gain aggregators that sum per-command scalar totals in m_arbitrary_misses[] (not per-key vectors). The 1 Hz Prometheus producer fills the new MT_ARBITRARY_* slots in prom_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.

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-ci

jit-ci Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ 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]>
@fcostaoliveira
fcostaoliveira merged commit 401108a into master Jun 17, 2026
123 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prometheus exporter: fold arbitrary-command hits/misses into memtier_hits_total/misses_total (PR2 follow-up)

1 participant