Skip to content

refactor(metrics): single source of truth for summary quantile ranks/labels#791

Merged
leoparente merged 1 commit into
developfrom
refactor/quantile-spec-table
Jun 26, 2026
Merged

refactor(metrics): single source of truth for summary quantile ranks/labels#791
leoparente merged 1 commit into
developfrom
refactor/quantile-spec-table

Conversation

@leoparente

Copy link
Copy Markdown
Contributor

Problem

The SLA quantiles pktvisor reports (0.50, 0.90, 0.95, 0.99) were restated in four places in src/Metrics.h, each positionally coupled to the order get_quantiles() produces:

  • the get_quantiles() helper (the rank list)
  • to_json()p50/p90/p95/p99 keys assigned to quantiles[0..3]
  • to_prometheus() — four hand-written LabelMaps "0.5"/"0.9"/"0.95"/"0.99"
  • to_opentelemetry() — a separate fractions[4]{0.50,0.90,0.95,0.99}

Nothing tied the emitted label to the value except array position, so changing or reordering the ranks at one site would silently mislabel the values at another. (This tidies up the get_quantiles() helper introduced when the bulk kll_sketch::get_quantiles(fractions, n) API was removed in the datasketches 5.x upgrade.)

Change

Introduce one ordered source of truth and drive every path from it:

struct QuantileSpec { double rank; const char *json_key; const char *prom_label; };
static constexpr std::array<QuantileSpec, 4> QUANTILES{{
    {0.50, "p50", "0.5"}, {0.90, "p90", "0.9"}, {0.95, "p95", "0.95"}, {0.99, "p99", "0.99"},
}};
  • get_quantiles() loops the table.
  • to_json / to_prometheus / to_opentelemetry loop the table for their key/label/rank, so values and labels can never desync.
  • The table carries each representation explicitly (the rank 0.50 maps to the Prometheus label "0.5", while 0.95 maps to "0.95"), so emitted strings are preserved exactly rather than re-derived by formatting.

Single file (src/Metrics.h). Also fixes a quatile typo in the helper param.

Behavior

No output change — JSON keys, Prometheus quantile labels, and OpenTelemetry set_quantile ranks are byte-identical, in the same order, including the _quantiles_sum (SUM-merge) path.

Testing

unit-tests-visor-core (sketches + metrics) and the handler suites that snapshot summary output — unit-tests-handler-{net,net-v2,dns,dns-v2,flow,netprobe} — all pass (7/7), confirming identical output.

🤖 Generated with Claude Code

…labels

The SLA quantile ranks {0.50,0.90,0.95,0.99} were restated in four places
(the get_quantiles helper, and the JSON/Prometheus/OpenTelemetry emit paths),
each positionally coupled to the helper's output order, so a change to one
site could silently mislabel the emitted values. Introduce a single ordered
QUANTILES table carrying each rank plus its JSON key and Prometheus label, and
drive every emit path (and the helper) from it. Output is byte-identical.
@leoparente

Copy link
Copy Markdown
Contributor Author

@codex review

@github-actions

Copy link
Copy Markdown

LCOV of commit 40c6936 during Debug Builds #186

  lines......: 82.5% (14321 of 17359 lines)
  functions..: 73.2% (1453 of 1984 functions)
  branches...: no data found

Files changed coverage rate: n/a

Full coverage report

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors Quantile summary emission to use a single, ordered quantile specification table so JSON keys, Prometheus quantile labels, and OpenTelemetry quantile ranks are all derived from the same source and cannot drift due to positional coupling.

Changes:

  • Introduces a QuantileSpec table (QUANTILES) defining rank + JSON key + Prometheus label in one place.
  • Updates get_quantiles(), JSON emission, Prometheus emission, OpenTelemetry emission, and SUM-merge accumulation to iterate QUANTILES.
  • Fixes the quatilequantile typo in the get_quantiles() helper parameter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 40c6936d42

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@leoparente leoparente marked this pull request as ready for review June 26, 2026 20:45
@leoparente leoparente merged commit 3eb47ea into develop Jun 26, 2026
24 checks passed
@leoparente leoparente deleted the refactor/quantile-spec-table branch June 26, 2026 22:12
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.

3 participants