Skip to content

feat(metrics,monitoring): meter the serve-path cache hit rate; surface the failure residual - #2071

Merged
thiras merged 2 commits into
mainfrom
feat/serve-path-cache-hit-metering
Sep 20, 2026
Merged

thiras merged 2 commits into
mainfrom
feat/serve-path-cache-hit-metering

Conversation

@thiras

@thiras thiras commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Why

The paid serve path streams through CacheEngine::export_bao_range_stream and never calls CacheEngine::get. decdn_cache_hits_total, decdn_cache_misses_total and decdn_cache_bytes_returned_total are all get-scoped, so on a node serving paying clients they sit at a permanent zero however full its store is.

The live fleet shows exactly that. Over 24h across the three nodes:

Series 24h
decdn_bytes_served_total 170 GB
decdn_cache_pull_through_bytes_total 32 GB
decdn_cache_bytes_returned_total 0
decdn_cache_hits_total 0
decdn_cache_bytes (stored) 71 GB

So the fleet overview's hit-ratio panel read a permanent 0%, and its headline throughput panel plotted cache_bytes_returned_total as "served" — a flat-zero line — while real egress was 170 GB/day. This is the "a name that resolves can still sit at a permanent zero" trap the monitoring gate explicitly does not catch.

What

Exporter. Add decdn_serve_cache_{hit,partial_hit,miss}_total, bumped at the blob-availability gate in handlers::client::dispatch. Counted ahead of the load-shed admission, so the ratio stays a property of the store rather than of current pressure — a node shedding hard would otherwise report a hit rate that collapses exactly when an operator most needs to read it. Exactly one of the three fires per request reaching the gate; a withdrawn hash (operator evict, corruption quarantine) is refused before it and counts in none.

serve_cache_partial_hit is a sibling rather than a fold-in: it is the payoff of partial-holder advertisement (ADR 038 § Serve side), and folding it into the plain hit would hide whether that mechanism carries any traffic. Both are hits for hit-rate purposes.

The get-scoped counters keep their meaning and their XOR contract — the registry rows and the cache crate's operator ratios now say which counter answers which question, instead of pointing operators at the dead one.

Dashboards. Overview throughput reads decdn_bytes_served_total; both hit-ratio panels read the new family. Two panels land that make standing failures legible:

  • Unattributed stream failures — rate(decdn_streams_failed_total{direction="inbound"}) minus the 22 seller-leg counters that each end exactly one inbound stream (decdn_serve_economics_refused_total is excluded: it is a per-candidate buyer-leg gate and ends no inbound stream). A standing positive floor is expected (early client close and the free header handshake count as failures by design and have no reason counter), so the panel description says to read the shape, not the level. On the live fleet this evaluates to ~297/day.
  • Pull success rate — promoted to the overview, because a pull leg failing every attempt reads as "low traffic" in the funnel counts but as a ratio pinned at zero here. It currently reads 0.

decdn_serve_stream_rejected_bad_binding_total and decdn_node_pull_pool_open_failures_total join the breakdowns they were missing from — the latter is the dominant pull failure cause on the live fleet and was on no panel. Eleven further exported-but-unplotted series (probe read faults, the fee-shares watcher downtime/restart pair, the reconciled-redemption skip, the per-peer rate-limit prune sweeps, the iroh path-composition family) land on their existing panels, taking live-series dashboard coverage from 94% to 100%.

Verification

  • cargo clippy --workspace --all-targets — clean
  • cargo fmt -- --check — clean
  • cargo nextest run -p decdn-node — full suite passes (incl. the 33 metrics gate tests and 118 client_loopback)
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items — clean
  • Every Prometheus target in all four dashboards executed against live Grafana Cloud: no syntax errors, no unexpected empties. The only empty results are the three serve_cache_* targets, which have no data until the fleet runs this binary.

New behavioural coverage: assert_one_completed_inbound_stream now pins serve_cache_hit_total 1 with both siblings at zero, and serve_cache_hit_family_exports_and_records pins the zero floor plus one bump per recorder.

Deploy note

The two hit-ratio panels render (no data) until the nodes run this binary. Everything else is live on publish. Dashboards are not published yet — monitoring/*.json here is the source of truth to push after merge.

Out of scope — filed separately

The live fleet has a node-to-node pull leg failing 100% of attempts, and ~297/day of stream failures no counter names. Both are pre-existing and are what these panels now make visible; issues filed rather than fixed here.

🤖 Generated with Claude Code


Review round 2 (commit fcc62570)

A multi-agent review found the metering placement sound — no bypass, no double-count, no other delivery entry point, all three bumps consistently pre-shed — but several written claims wrong. Corrected:

  • decdn_cache_misses_total is not get-scoped. It is also bumped by populate/populate_local and pull_through_range, which the serve-path fill tiers call. Only hits and bytes_returned are get-exclusive, so the pair reads as a populated permanent 0% rather than an empty series. The cache module doc had begun contradicting its own field doc.
  • serve_cache_miss does not imply a fill tier ran — the bump precedes the shed gate, the floor reservation and the pull_authorized check every tier is gated on, and it absorbs a store fault in the partial-coverage lookup that .ok()? renders as absence.
  • "Exactly one of the three" omitted two carve-outs, not one: withdrawn and the serve_audit store fault.
  • Partial-hit row cited the wrong ADR — the mechanism is ADR 022 § Range-keyed partial-holder discovery, not ADR 038 § Serve side.
  • Origin-egress amplification does not reach exactly 1.0 on pure pass-through: bytes_served is the bao wire form over chunk-group-aligned ranges and includes downstream-node egress; pull_through_bytes is raw origin content.
  • The residual subtracts 22, not 23 — serve_economics_refused is a per-candidate buyer-leg gate that ends no inbound stream, so subtracting it drove the residual structurally low. Caught and fixed before this round.

Coverage for the two branches that had none: the partial branch is pinned in partial_serve.rs where no origin is wired (a covering partial is the only thing that could have served), its sibling pins the decline, origin_range_pull pins the miss beside the tier counter, and cache_hit_refused_under_egress_saturation pins the pre-shed ordering — every other test runs a permissive limiter, so moving the bump into the admission arm would otherwise pass the whole suite.

Verified by mutation: swapping the partial-hit bump to the hit sibling fails the new assertion with decdn_serve_cache_hit_total should be 0 for a serve_cache_partial_hit classification, got 1. Full suite 1172/1172.

…e the failure residual

The paid serve path streams through `export_bao_range_stream` and never calls
`CacheEngine::get`, so `decdn_cache_{hits,misses,bytes_returned}_total` sit at a
permanent zero on a node serving paying clients however full its store is. The
fleet dashboard inherited that: its hit-ratio panel read 0% against 71 GB of
cached content, and its headline throughput panel plotted `bytes_returned` as
"served" while the real egress counter showed 170 GB a day.

Add `decdn_serve_cache_{hit,partial_hit,miss}_total`, bumped at the
blob-availability gate ahead of the load-shed admission so the ratio stays a
property of the store rather than of current pressure. The partial hit is a
sibling rather than a fold-in: it is the payoff of partial-holder
advertisement, and folding it into the plain hit would hide whether that
mechanism carries traffic. Correct the registry rows and the cache crate's
operator ratios to say which counter answers which question.

On the dashboards: the overview throughput panel reads `decdn_bytes_served_total`,
both hit-ratio panels read the new family, and two panels land that make
standing failures legible — a residual of seller-leg failures no reason counter
claims (live fleet: ~297/day), and node-to-node pull success rate, which reads
as a ratio pinned at zero rather than as low traffic. `bad_binding` and
`pool_open_failures` join the breakdowns they were missing from, and eleven
further exported-but-unplotted series land on their existing panels.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

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.

Copilot review overview

🔵 Needs a closer look

Residual dashboards mix unrelated counters and omit pool-exhaustion failures.

Review effort: Lite
Findings: None

What changed in this PR

Adds serve-path cache hit metrics and expands Grafana monitoring for delivery, pull success, and failure residuals.

Changes:

  • Adds complete, partial-hit, and miss counters with tests.
  • Updates throughput and hit-ratio dashboards.
  • Adds coverage for previously unplotted metrics.
File Summary
monitoring/​grafana-dashboard.json Updates overview panels and residual queries.
monitoring/​dashboard-node.json Adds node transport, probe, and rate-limit metrics.
monitoring/​dashboard-delivery.json Adds delivery metrics, hit ratios, and residual queries.
monitoring/​dashboard-chain.json Adds watcher and redemption metrics.
crates/​node/​tests/​client_loopback.rs Verifies serve-cache metrics.
crates/​node/​src/​metrics.rs Defines and tests serve-cache metrics.
crates/​node/​src/​handlers/​client/​dispatch.rs Records serve-path classifications.
crates/​cache/​src/​metrics.rs Clarifies cache metric scope.
CHANGELOG.md Documents observability changes.
adr/​appendix-observability.md Updates the metric registry.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 83.16% (was 83.16%, ● 0.00%) — 81725/98274 lines

File Coverage Lines Δ
crates/node/src/handlers/client/dispatch.rs 81.06% 518/639 ▲ +0.09%
crates/node/src/metrics.rs 95.67% 1082/1131 ▲ +0.07%
History
Commit Total Δ vs base
5d475d4 83.17% ● 0.00%
fcc6257 (HEAD) 83.16% ● 0.00%

…partial and miss branches

Review of the previous commit found the metering placement sound but several
of its written claims wrong. The claims are the part operators act on, so they
get the same standard as the code.

`decdn_cache_misses_total` is not `get`-scoped. It is also bumped by
`populate`/`populate_local` and `pull_through_range`, which the serve-path fill
tiers do call. Only `hits` and `bytes_returned` are `get`-exclusive, so the
pair reads as a populated permanent 0% on a serving node, not as an empty
series — a sharper statement of the bug than the one it replaces, and the
cache module doc had begun contradicting its own field doc.

`decdn_serve_cache_miss_total` does not imply a fill tier ran. The bump
precedes the shed gate, the floor reservation and the `pull_authorized` check
every tier is gated on, so a shed refusal, a floor refusal and an unbound
request all count with no origin and no peer asked. It also absorbs a store
fault during the partial-coverage lookup, which `.ok()?` renders as absence.

"Exactly one of the three per request" omitted two carve-outs, not one: a
withdrawn hash and a `serve_audit` store fault both reach the gate and are
refused without an availability classification.

The partial-hit row cited ADR 038 § Serve side, which covers bao proof sources.
The mechanism the counter measures the payoff of is ADR 022 § Range-keyed
partial-holder discovery.

Origin-egress amplification does not reach exactly 1.0 on a pure pass-through:
`bytes_served` is the bao wire form over chunk-group-aligned ranges and
includes downstream-node egress, while `pull_through_bytes` is raw origin
content. Stated as a trend with the gap named, rather than as a calibration
point operators would anchor on.

Tests now cover the two branches that had none. The partial branch is pinned in
`partial_serve.rs` where no origin is wired, so a covering partial is the only
thing that could have served; its sibling pins the decline. `origin_range_pull`
pins the miss beside the tier counter that proves a fill ran. And
`cache_hit_refused_under_egress_saturation` pins the pre-shed ordering — every
other test runs a permissive limiter, so moving the bump inside the admission
arm would otherwise pass the whole suite.

Also corrects the residual to 22 subtracted counters in the CHANGELOG, matching
the panel, and drops changelog voice from a panel description operators read.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@thiras
thiras merged commit 53ec098 into main Sep 20, 2026
25 checks passed
@thiras
thiras deleted the feat/serve-path-cache-hit-metering branch September 20, 2026 07:14
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.

2 participants