Skip to content

fix(node,cache): sample decdn_probe_hold_slots_used at scrape time - #2245

Merged
alpergundogdu merged 1 commit into
mainfrom
fix/probe-hold-gauge-scrape-sample
Sep 30, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
fix/probe-hold-gauge-scrape-sample

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Problem

decdn_probe_hold_slots_used was 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, although PROBE_HOLD_DURATION is 35 s. Found in review 5360334012 on #2239.

Fix

  • Metrics holds the cache engine (attach_probe_holds, called right after build_cache in runtime bring-up) and samples CacheEngine::probe_hold_slots_used() in encode(). This reuses the existing scrape-time recompute path that already sets node_uptime_seconds and the watcher *_down_seconds gauges, so no new timer. The read sweeps expired holds, so the gauge drops to 0 once holds lapse with no probe traffic.
  • The probe handler no longer writes the gauge, and the probe_hold_slots recorder is gone. The stake-lane gate still takes its own sample.
  • Probe-hold expiries now use 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 the DecdnProbeHoldsSaturated alert read the gauge value, and the metric name and type are the same. The alert now can't fire on a stale value. The decdn_probe_hold_slots_used == 0 drain check in adr/appendix-operator-upgrade-path.md and appendix-operator-key-rotation.md works as written now. Before, it could stay non-zero indefinitely.

Test

metrics::tests::probe_hold_slots_used_drops_to_zero_after_hold_expires runs on a paused clock. It takes a hold, checks that the scrape reads 1, advances past PROBE_HOLD_DURATION with no further probe, and checks that the scrape reads 0.

Gates

  • cargo nextest run -p decdn-node -p decdn-cache: 1973 passed, 0 failed
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: clean
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items: clean
  • cargo test --no-run -p decdn-e2e --features anvil-e2e: compiles

🤖 Generated with Claude Code

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]>
Copilot AI balanced review requested due to automatic review settings September 30, 2026 08:39

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

🟢 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:

  • Metrics now holds the cache engine in a OnceLock (attached at runtime bring-up via attach_probe_holds) and samples CacheEngine::probe_hold_slots_used() in encode(); the probe handler's gauge write and the probe_hold_slots recorder are removed.
  • Probe-hold expiries now use tokio::time::Instant in 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 the StubOrigin fixture 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.

@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit c9fa461 in the fix/probe-hold-gauge... branch remains at 87%, unchanged from commit e4eff4e in the main branch.

Show a line coverage summary of the most impacted files.
File main e4eff4e fix/probe-hold-gauge... c9fa461 +/-
crates/incentiv...eth_identity.rs 99% 98% -1%
crates/node/src...ndlers/probe.rs 88% 87% -1%
crates/node/src/dht/publish.rs 92% 92% 0%
crates/client/src/lib.rs 92% 92% 0%
crates/cache/src/engine.rs 94% 94% 0%
crates/client/src/streamer.rs 91% 91% 0%
crates/node/src/metrics.rs 96% 96% 0%
crates/protocol/src/framing.rs 97% 97% 0%
crates/node/src...gin/pull_leg.rs 90% 90% 0%
crates/node/src/runtime/mod.rs 53% 53% 0%

@alpergundogdu
alpergundogdu merged commit 5aa68b3 into main Sep 30, 2026
31 checks passed
@alpergundogdu
alpergundogdu deleted the fix/probe-hold-gauge-scrape-sample branch September 30, 2026 09:19
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