Repository navigation
fix: make the metrics registry tell the truth (#1517, #1513) - #1527
Conversation
Two issues from the #1510 review, both the same defect: the node's observability surface makes claims nobody checks. * fix(cache): a poisoned coalescing mutex no longer costs egress in silence The in-flight fill-coalescing map is what stops N concurrent requests for one missing blob from opening N origin pulls. Three of its five lock sites discarded the PoisonError — `get`'s loop and `populate_inner`'s fell through to a *direct* pull, `InflightGuard::drop` skipped its removal — while the two tee-path sites already recovered the guard with `PoisonError::into_inner`. Since std poison is sticky for the process lifetime, one panic permanently disabled coalescing: an unbounded egress multiplier on a metered http/s3 origin, and on the Peer origin reached via `populate` a double-spend of USDC vouchers upstream — the exact hazard `TeeOpen::InFlight` is documented to prevent. Nothing logged it, nothing counted it. All five sites now go through one `Inner::lock_inflight` choke point that recovers the guard. **Stronger than the issue proposed**, which was to keep the fall-through and merely report it: recovering means coalescing survives poison, so the hazard is removed rather than observed. That also matches the crate's dominant idiom (18 sites) and the rationale already written for `evicted` / `is_evicted`, where skipping the critical section breaks a load-bearing invariant. The dropped removal in `InflightGuard::drop` was a second, unrecorded bug: `notify_waiters()` wakes only *current* waiters, so a leaked entry left every later request for that hash parked on a Notify that would never fire again — the permanent hang the guard exists to prevent. New `decdn_cache_inflight_mutex_poisoned_total` plus one latched `tracing::error!`. The anti-panic policy makes poison close to unreachable, so any nonzero value is a bug report, not a threshold to tune — the runbook entry says exactly that, and that restart is the only way to clear it. Three tests, all confirmed to fail under injected mutants (drop-path revert; counter bump removed): coalescing holds at one origin fetch under poison, the log latches while the counter keeps counting, and the guard still clears its entry. The map is read with `into_inner`, not `lock().ok()` — the latter reports an empty map on a poisoned mutex and would make the orphan assertion vacuous. * fix(observability): every documented metric name now resolves, enforced `adr/appendix-observability.md` calls itself the canonical registry but had no way to say "specified, not built" — its only axis was the M/R *requirement* tier. So ~a third of its rows read as shipped while nothing exported them, and `monitoring/` had inherited the rot: `DecdnPeerTableThin` queried `decdn_peer_table_size` (the field is `gossip_peer_table_size`) and `DecdnHighStreamErrorRate` divided by `decdn_streams_completed_total`, which no field produces. Both shipped as coverage while permanently silent. The alerts file already said so in a comment, citing this issue, and the one existing name test called the blanket check impossible — 13 stale names blocked it. A new **Status** column (`live` / `planned`) is the root-cause fix: it gives the registry a way to be honest, and gives the gate its allowlist, so the check can be absolute instead of carrying a hand-maintained skip list that would rot the same way the names did. 33 live rows are now enforced; 17 planned rows are explicitly marked. Two gate tests parse the ADR registry and both monitoring files and assert every name resolves against the encoder's output. Both build the name set from *sample* lines, not `# TYPE` lines: OpenMetrics writes `# TYPE decdn_cache_hits counter` while the sample is `decdn_cache_hits_total`, so parsing TYPE would blind the gate to the `_total` suffix — the single most common way a documented name goes wrong here. Both were confirmed to fail against the pre-fix tree, and under mutants that restore a wrong name or promote a planned row to live. Deliberate scoping in the monitoring gate: full-line YAML comments are stripped before scanning. A retired series has to stay nameable in prose, or the next maintainer deletes the explanation instead of the rule. Also corrected: `decdn_gossip_announces_sent_total` → `..._published_total`; ADR 005/022's labelled `*_rejections_total`, which the exporter has never emitted (it emits sibling trios — now given real registry rows, 14 series that previously existed only as brace-expanded shorthand); `decdn_peer_table_evicted_registry_total`'s `reason` label, which contradicted the same appendix's claim that `probe_hold_unavailable{reason}` is the one labelled reason split; and the doc comments in dht/rate_limit.rs and probe_rate_limit.rs claiming `iroh_metrics` "has no per-field labels" — false, and contradicted by five other comments plus two live `Family<L, M>` fields. **Stated residual:** the gate proves a name resolves, not that anything increments it. A series exporting at a permanent zero still passes; the test comment says so rather than implying more coverage than exists. Verification: cargo fmt clean, clippy --all-targets clean, cargo doc clean, cargo deny clean, 2679/2679 nextest passing, pre-commit clean except a pre-existing markdownlint failure in .github/workflows/issue-triage.md (confirmed present on a stashed clean tree; not touched here). Closes #1517. Closes #1513. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Four reviewers (code, tests, silent-failure, comments) ran against 374cf9e. Every finding below was independently verified before acting; the ones I could not reproduce are listed at the end. * fix(cache): clear the poison instead of telling operators to restart The review's highest-value catch: `Mutex::clear_poison` has been stable since 1.77 and the workspace MSRV is 1.95 (verified by compiling it against the project toolchain). So "a std mutex poison is sticky for the process lifetime" was true of the *old code* only because nothing ever cleared it — not a property of the platform. I had written it as the latter in five places, and the runbook turned it into a wrong instruction: restart a node that the same section calls healthy. `lock_inflight` now calls `clear_poison()` after recovering the guard. This is not just a doc fix — it changes what the metric means. Before, one panic made `decdn_cache_inflight_mutex_poisoned_total` climb at request rate forever, so a `rate()` panel read as a raging ongoing incident long after a single event. Now one panic is one bump: the counter measures incidents. Clearing is justified by the same argument that justified recovering — the critical sections hold only `HashMap` get/insert/remove plus a `Notify` allocation, so the map cannot be torn — and it is pinned by three tests that fail if the clear is dropped. Runbook now says explicitly not to restart; the counter still does not reset without one, deliberately, so the evidence outlives the incident. * test(cache): cover the money path and the cross-path claim `populate_inner`'s coalescing loop is a near-verbatim copy of `get`'s, not a shared helper, and the pre-#1517 defect was per-copy. All three original tests drove `get` — which has no production caller in the daemon. The serve path fills via `populate`/`populate_local` and `open_tee_sink`, and `populate` is the one that walks the paid `Peer` origin. So the copy that spends USDC was the copy with no coverage: a mutation reverting only `populate_inner` survived the whole suite. Now it doesn't (verified). Added the cross-path test too, which is what actually maps onto the double-spend `TeeOpen::InFlight` exists to prevent. `open_tee_sink` already recovered poison before #1517, so it was never broken from its own side — it was defeated from the other: a poisoned `populate` fell through without inserting the claim, so a concurrent `open_tee_sink` saw an empty map, returned `Owner`, and opened a second paid pull. Neither site alone exhibits that. Writing it surfaced a flaw in my own test: an unbounded spin-wait for the claim to land *hangs* under exactly the regression it targets. Bounded to 5s so it fails loudly instead of blocking CI. Also: `poisoned_mutex_does_not_orphan_inflight_entry` could pass vacuously (it never proved the owner claimed the entry before asserting release — an empty map proves nothing if the 50ms timeout beat the pull); the latch test's `bumps > 1` became exact-value assertions; and the two pre-existing `.lock().ok()` reads now use the poison-safe helper written 30 lines below them. * fix(observability): the review found four factual errors in my own prose The commit's premise is that docs drifted from code, so these matter more than usual: - `crates/node/src/rate_limit.rs` still carried the exact "iroh-metrics backend does not support per-field labels" falsehood the CHANGELOG claimed to have removed. I fixed the two per-path files and missed the shared module — which the new ADR text now cites by path, and which contradicted its own enum doc 140 lines below. - Six lock sites, not five; three tee-path, not two. - Eleven stale monitoring names, not thirteen (13 was carried forward from a pre-existing comment that counted two non-series tokens the new test explicitly classifies as such). - The mutex taxonomy comment claimed `access_times` recovers silently; it recovers at 2 of 6 sites and skips at 4, and a poisoned `access_times` stops LRU eviction entirely. Restated per-site, and the two mutexes it omitted (`probe_holds`, `origin_probe_memo`) are named. `docs/runbook.md`'s hash-mismatch section was the worst of these: it told operators to grep logs because "no counter moves", when `node_pull_corruption`, `node_pull_through_upstream_verify_failed` and `node_pull_through_errors` all fire on the pull leg. The real gap is narrower and worse — `HashMismatch` is deliberately not a `HardFault`, so on the *serve* leg `miss_reason()` collapses it into `decdn_serve_stream_rejected_cache_miss_total`, laundering a data-integrity fault into the noisiest benign counter on the path. Section rewritten to say that. * fix(observability): close the gaps the gate left open - The commit added a metric and did not add its registry row, violating the rule it wrote three files away ("Adding a metric therefore means editing this table in the same change"). Row added, plus the `DecdnCacheInflightMutexPoisoned` alert the new test's own comment demanded. - The appendix marked two gauges `planned` while an unchanged threshold table nine lines below still prescribed alert thresholds for them, and the prose above called them "normally non-zero". Both corrected. - `adr/appendix-operator-upgrade-path.md` still sent operators to monitor `decdn_streams_failed_total`, now `planned` with its alerts deleted. - `exported_series` could never match a histogram (OpenMetrics emits only `_bucket`/`_sum`/`_count`), so the first `live` histogram row would fail with a message telling its author to mark a shipping metric `planned`. Folded. - Both gate floors were slack enough to tolerate a >50% silent coverage collapse (`checked > 20` against 47 real rows). Tightened to just under actual. - "a counter field must never spell `_total`" is contradicted by four `gossip_*_total` fields that export correctly; softened to the convention it is. The appendix's "cannot drift" claim now states the gate's two real limits: it skips labelled/templated rows, and it runs one-way — absence from the registry is not evidence a metric doesn't exist. Not acted on, deliberately: the reverse gate (exported ⊆ documented, ~124 undocumented series) and the pre-existing lost-wakeup window in the coalescing loop are both real but out of scope for a fix batch — better as their own issues. `decdn_cache_evictions_sweeps_total` in appendix-blob-cache-eviction.md is stale but pre-existing and outside the gated file. Verification: fmt/clippy --all-targets/doc/deny clean, 2681/2681 nextest passing, pre-commit clean except the pre-existing markdownlint failure in .github/workflows/issue-triage.md. Mutation-checked: removing `clear_poison` fails 3 tests; reverting only `populate_inner`'s loop fails 2. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Warning Review limit reached
Next review available in: 43 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (6)
WalkthroughThe cache engine now recovers poisoned in-flight mutexes while preserving request coalescing and recording incidents. Observability registries, exporter validation, alerts, dashboards, documentation, and runbooks were updated to use live metric names and revised counter conventions. ChangesCache recovery and observability
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant CacheEngine
participant InflightMutex
participant Origin
participant Metrics
CacheEngine->>InflightMutex: acquire in-flight claim
InflightMutex->>Metrics: record poisoned mutex
InflightMutex-->>CacheEngine: recover guard and clear poison
CacheEngine->>Origin: execute one coalesced fetch
CacheEngine-->>CacheEngine: remove claim and notify waiters
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Coverage reportTotal: 80.27% (was 80.17%, ▲ +0.10%) — 54643/68073 lines
History
|
There was a problem hiding this comment.
Pull request overview
This PR tightens deCDN’s observability contract by (1) making cache in-flight coalescing resilient to Mutex poisoning (and measurable), and (2) enforcing that documented and monitored metric series names actually exist in the exporter output, preventing “silent” alerts/dashboards that can never fire.
Changes:
- Cache: route all in-flight coalescing lock sites through a single poison-recovering
lock_inflight()path, clear poison, and add a counter + alerting/runbook guidance for poison incidents. - Observability: add a
live/plannedStatus axis to the ADR metric registry and add CI gates ensuringliveregistry rows andmonitoring/selectors resolve to exported series. - Monitoring assets: update Prometheus alert rules and Grafana panels to remove/replace queries for never-emitted series (notably peer table size and stream failure ratios).
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| monitoring/prometheus-alerts.yml | Removes permanently-silent rules; adds alerting around cache inflight mutex poisoning and fixes peer-table selector. |
| monitoring/grafana-dashboard.json | Updates panels to query only exported metrics; replaces blacklist and throughput panels accordingly. |
| docs/runbook.md | Updates operator guidance to match actual exported metrics and adds new sections for inflight-poison and hash-mismatch coverage realities. |
| crates/node/src/rate_limit.rs | Updates shared rate-limiter documentation and operator query guidance. |
| crates/node/src/metrics.rs | Adds tests/gates to ensure monitoring/ and ADR registry metric names resolve to exporter output. |
| crates/node/src/handlers/probe_rate_limit.rs | Updates probe rate-limit metrics documentation to reflect sibling-counter convention. |
| crates/node/src/dht/rate_limit.rs | Updates DHT rate-limit metrics documentation and related test comment to match sibling-counter convention. |
| crates/common/src/config/types.rs | Fixes documented peer-table metric name in config docs (decdn_gossip_peer_table_size). |
| crates/cache/src/metrics.rs | Adds decdn_cache_inflight_mutex_poisoned_total counter and documents semantics. |
| crates/cache/src/engine.rs | Implements Inner::lock_inflight() poison recovery + poison clearing; fixes orphan/leak behavior on poison; adds focused regression tests. |
| CHANGELOG.md | Records monitoring-breaking metric/rule/panel fixes and the cache inflight poison fix. |
| adr/appendix-peer-table-eviction.md | Fixes peer-table metric naming and updates eviction metrics description to sibling counters. |
| adr/appendix-operator-upgrade-path.md | Updates Tier-2 operator checklist metric reference. |
| adr/appendix-observability.md | Adds Status column (live/planned) and aligns registry rows with exporter reality; documents enforcement gates. |
| adr/022-content-discovery.md | Updates DHT rate-limit observability text to sibling counters. |
| adr/005-protocol.md | Updates probe rate-limit observability text to sibling counters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 1. **Read the release notes** for new operator-config flags introduced with the variant. Typically opt-in (e.g. `enable_keepalive = true`); defaults are conservative. | ||
| 2. **Pull and restart at your normal cadence,** per [§ Restarting a node safely](#restarting-a-node-safely). No Tier 2 release needs coordination beyond that standing procedure. | ||
| 3. **Monitor `decdn_streams_failed_total{reason="protocol_error"}`** for one rolling window after restart. A spike means a peer is rejecting the new variant — expected and benign for legacy peers, but a sustained rate from your own outbound streams suggests config drift. | ||
| 3. **Monitor `decdn_serve_stream_rejected_internal_error_total`** for one rolling window after restart. A spike means a peer is rejecting the new variant — expected and benign for legacy peers, but a sustained rate from your own outbound streams suggests config drift. |
There was a problem hiding this comment.
Right, and this was my error rather than a pre-existing one. The line originally read decdn_streams_failed_total{reason="protocol_error"}; that series is now marked planned and its alerts were deleted, so I swapped the name — and left the surrounding prose ("a spike means a peer is rejecting the new variant") attached to a counter that means this node refusing an inbound serve request. Opposite direction.
Checked what actually captures the Tier 2 fallback: nothing does. The UNSUPPORTED_MESSAGE close is handled at crates/node/src/dht/client.rs (BatchAttemptOutcome::Unsupported) with a tracing::debug! and no counter, and there is no app-error-code or unsupported-variant metric anywhere in crates/.
So rather than repoint it at another metric, 7ca0095 makes the step say the signal is unmetered, names the log line to grep, and records the missing per-variant fallback counter as the gap. Same treatment as the delivery-hash-mismatch gap earlier in this branch — when the signal does not exist, the doc says so instead of substituting a nearby one.
… path Both findings from the Copilot review of #1527 verified and correct. * PromQL brace expansion is not a thing `sum(rate(decdn_probe_rate_limit_rejected_{per_peer,per_ip,global}_total[1m]))` is not valid PromQL — braces are label matchers, so this parses as metric name `decdn_probe_rate_limit_rejected_` followed by a malformed matcher. Presented as "operators recover the rolled-up rate with ...", it read as copy-pasteable and was not. Switched to a `__name__` regex, which is the idiom the repo already uses (`monitoring/prometheus-alerts.yml`'s `{__name__=~"decdn_.+_task_panicked_total"}`). Copilot flagged three sites; the same defect existed at three more it did not see (`dht/rate_limit.rs`'s test comment, `metrics.rs`'s field doc, and the ADR appendix), all fixed together. Brace expansion stays where it is genuinely naming shorthand for a family rather than a query — the reason-splits table and registry rows — and the ADR now says which is which, since the two forms look identical. * the upgrade-path metric swap was wrong I replaced `decdn_streams_failed_total{reason="protocol_error"}` (now `planned`, alerts deleted) with `decdn_serve_stream_rejected_internal_error_total` and left the surrounding prose intact. That prose says "a spike means a peer is rejecting the new variant" — but the substituted counter is *this node* refusing an inbound serve request. Opposite direction, unrelated meaning. A mechanical name swap under prose I did not re-read. Checked what actually signals a peer rejecting a Tier 2 variant: nothing does. The `UNSUPPORTED_MESSAGE` fallback emits `tracing::debug!` (`crates/node/src/dht/client.rs`) and increments no counter — `grep -rn` over `crates/` for an app-error-code or unsupported-variant counter finds none. So the step now says to watch the log line and names the missing counter as the gap, rather than pointing at a metric that means something else. Same treatment as the hash-mismatch gap earlier in this branch: when the signal does not exist, say so. Verification: fmt/clippy --all-targets/doc/deny clean, 2681/2681 nextest passing, pre-commit clean except the pre-existing markdownlint failure in .github/workflows/issue-triage.md. Docs-only — no logic change, so no new tests. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Closes #1517. Closes #1513.
Two issues from the #1510 review, both the same defect: the node's observability surface makes claims nobody checks.
#1517 — a poisoned coalescing mutex cost egress and USDC in silence
CacheEngine's in-flight fill-coalescing map is what stops N concurrent requests for one missing blob from opening N origin pulls. Three of its six lock sites discarded thePoisonError—get's loop andpopulate_inner's fell through to a direct pull,InflightGuard::dropskipped its removal — while the three tee-path sites already recovered the guard. Nothing cleared the poison, so one panic permanently disabled coalescing: an unbounded egress multiplier on a meteredhttp/s3origin, and on thePeerorigin a double-spend of USDC vouchers upstream — the exact hazardTeeOpen::InFlightis documented to prevent. No log, no metric.All six sites now go through one
Inner::lock_inflightchoke point. This is stronger than the issue proposed (keep the fall-through, just report it): recovering means coalescing survives poison, so the hazard is removed rather than observed. Having established the critical sections hold no user code, it also callsMutex::clear_poison— so the new counter measures incidents, not requests-since-an-incident, and no restart is needed.Two bugs surfaced that neither issue recorded:
InflightGuard::dropswallowing the error leaked the map entry. Sincenotify_waiters()wakes only current waiters, every later request for that hash parked forever on a deadNotify— the permanent hang the guard exists to prevent.populate— the path that actually spends USDC — had no poison coverage at all.gethas no production caller in the daemon.#1513 — the registry documented series the exporter never emitted
The appendix had no way to say "specified, not built" — its only axis was the M/R requirement tier — so ~a third of its rows read as shipped.
monitoring/had inherited the rot:DecdnPeerTableThinqueried a name nothing has ever exported, and five other rules plus six panels were likewise permanently silent. The alerts file already said so in a comment, citing this issue.A new Status column (
live/planned) is the root-cause fix: it gives the registry a way to be honest and doubles as the gate's allowlist, so the check can be absolute instead of carrying a skip list that would rot the same way the names did. 47 live rows enforced, 18 planned marked.Three gate tests build the name set from sample lines, not
# TYPElines — OpenMetrics writes# TYPE decdn_cache_hits counterwhile the sample isdecdn_cache_hits_total, so parsing TYPE would blind the gate to the_totalsuffix, the most common way a name goes wrong here.Reviewed, then fixed
A four-agent review of the first commit found real errors in my own work, all fixed in
56bdca8f:Mutex::clear_poisonis available on MSRV 1.95. "Sticky for the process lifetime" was true of the old code only because nothing cleared it. I had written it as a platform property, and the runbook turned that into a wrong instruction: restart a node the same section calls healthy.crates/node/src/rate_limit.rsstill carried the falsehood the CHANGELOG claimed I'd removed. I fixed the two per-path files and missed the shared module — the one the new ADR text cites by path.HashMismatchis deliberately not aHardFault, so on the serve leg it collapses intodecdn_serve_stream_rejected_cache_miss_total, laundering a data-integrity fault into the noisiest benign counter on the path.access_timesrecovers silently when it recovers at 2 of 6 sites.Deliberately out of scope
The reverse gate (~124 exported-but-undocumented series) and a pre-existing lost-wakeup window in the coalescing loop are both real, but they are new work rather than defects in this diff — better as their own issues.
Verification
fmt/clippy --all-targets/doc/denyclean, 2681/2681 tests passing, pre-commit clean except a pre-existingmarkdownlintfailure in.github/workflows/issue-triage.md(confirmed present on a stashed clean tree).Every new test was mutation-checked: removing
clear_poisonfails 3; reverting onlypopulate_inner's loop fails 2; restoring a wrong ADR name or promoting aplannedrow tolivefails the gates. Writing the cross-path test surfaced a flaw in my own test — an unbounded spin-wait that hung under the very regression it targets — now bounded so it fails loudly instead of blocking CI.No wire, config, ABI, or contract change. Monitoring-breaking: forked dashboards need the
decdn_gossip_peer_table_sizerename; see the CHANGELOG for the full list of deleted and replaced rules.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Monitoring
Documentation