Repository navigation
fix(node,cache): sample decdn_probe_hold_slots_used at scrape time - #2245
Conversation
The gauge was written only by the probe handler, so it held the last probe's value until the next probe arrived (nbg1 read 8 for ~10 h on testnet). The node now attaches its cache engine to Metrics and samples probe_hold_slots_used() in encode(), next to the existing scrape-time uptime and watcher down-seconds recomputes. The read sweeps expired holds, so the gauge returns to 0 once holds lapse with no probe traffic. The per-probe gauge writes are gone. Probe-hold expiries run on the tokio clock so a paused test clock can drive them; the new test takes a hold, advances past PROBE_HOLD_DURATION, and asserts the scrape reads 0. Found in review 5360334012 on #2239. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The scrape-time sampling and the tokio::time::Instant migration are internally consistent (all probe_holds reads/writes use the tokio clock, access_times is never cross-compared, and production timing is unchanged), no dangling references to the removed recorder remain, and the new behavior is covered by a paused-clock test.
Review effort: Balanced
Findings: None
What changed in this PR
This PR fixes a staleness bug in the decdn_probe_hold_slots_used gauge. Previously the gauge was written only by the probe handler, so between probes it held the last probe's value indefinitely (observed reading a non-zero value for hours on testnet despite the 35s PROBE_HOLD_DURATION). The fix moves the gauge to a scrape-time sample of the cache engine's live hold count, reusing the existing Metrics::encode recompute path that already refreshes node_uptime_seconds and the watcher *_down_seconds gauges. This aligns the gauge with the operator drain checks (decdn_probe_hold_slots_used == 0) documented in the upgrade/key-rotation appendices and prevents the DecdnProbeHoldsSaturated alert from firing on a stale value.
Changes:
Metricsnow holds the cache engine in aOnceLock(attached at runtime bring-up viaattach_probe_holds) and samplesCacheEngine::probe_hold_slots_used()inencode(); the probe handler's gauge write and theprobe_hold_slotsrecorder are removed.- Probe-hold expiries now use
tokio::time::Instantin the cache engine so a paused test clock can drive expiry (identical to the monotonic clock outside tests), and the read path sweeps expired holds so the gauge drops to 0 with no probe traffic. - Adds a paused-clock test (
probe_hold_slots_used_drops_to_zero_after_hold_expires) and hoists theStubOriginfixture to test-module scope for reuse.
| File | Description |
|---|---|
crates/node/src/runtime/mod.rs |
Attaches the cache to Metrics right after build_cache so scrapes can sample live hold counts. |
crates/node/src/metrics.rs |
Adds probe_holds OnceLock, attach_probe_holds, scrape-time gauge sampling in encode; removes the probe_hold_slots recorder; hoists StubOrigin and adds the drop-to-zero test. |
crates/node/src/handlers/probe.rs |
Removes the probe-handler gauge write and the now-unused slots_used reuse variable; keeps the stake-lane gating sample. |
crates/cache/src/engine.rs |
Migrates the probe_holds map and its now-reads to tokio::time::Instant; updates docs and an expired-hold test. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Code Coverage OverviewLanguages: Rust Rust / code-coverage/cargo-llvm-covThe overall line coverage in commit c9fa461 in the Show a line coverage summary of the most impacted files.
|
Problem
decdn_probe_hold_slots_usedwas written only by the probe handler, so between probes it held the last probe's value. On testnet nbg1 read 8 for about 10 h, and read 11 for over 10 minutes after a run with zero active streams, althoughPROBE_HOLD_DURATIONis 35 s. Found in review 5360334012 on #2239.Fix
Metricsholds the cache engine (attach_probe_holds, called right afterbuild_cachein runtime bring-up) and samplesCacheEngine::probe_hold_slots_used()inencode(). This reuses the existing scrape-time recompute path that already setsnode_uptime_secondsand the watcher*_down_secondsgauges, so no new timer. The read sweeps expired holds, so the gauge drops to 0 once holds lapse with no probe traffic.probe_hold_slotsrecorder is gone. The stake-lane gate still takes its own sample.tokio::time::Instant, so a paused tokio clock can drive them. Outside tests this is the same monotonic clock.Monitoring
Nothing to change. The dashboards (
grafana-dashboard.json,dashboard-node.json) and theDecdnProbeHoldsSaturatedalert read the gauge value, and the metric name and type are the same. The alert now can't fire on a stale value. Thedecdn_probe_hold_slots_used == 0drain check inadr/appendix-operator-upgrade-path.mdandappendix-operator-key-rotation.mdworks as written now. Before, it could stay non-zero indefinitely.Test
metrics::tests::probe_hold_slots_used_drops_to_zero_after_hold_expiresruns on a paused clock. It takes a hold, checks that the scrape reads 1, advances pastPROBE_HOLD_DURATIONwith no further probe, and checks that the scrape reads 0.Gates
cargo nextest run -p decdn-node -p decdn-cache: 1973 passed, 0 failedcargo clippy --workspace --all-targets --all-features -- -D warnings: cleanRUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items: cleancargo test --no-run -p decdn-e2e --features anvil-e2e: compiles🤖 Generated with Claude Code