Skip to content

fix(node): serve /metrics during boot and export decdn_node_boot_ready - #2821

Merged
thiras merged 2 commits into
mainfrom
fix/2819-metrics-before-boot
Nov 1, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/2819-metrics-before-boot

Conversation

@thiras

@thiras thiras commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What

decdn-node bound /metrics in spawn_background_tasks, after the RPC preflight, the deployment preflight and the fail-closed boot chain reads. A node stuck in boot exported nothing. On 2026-11-01 the whole fleet showed no decdn_* samples for about 22 min.

  • Metrics listener first. run binds and serves the metrics listener before build_infra. The serve task sits in the runtime JoinSet, which run now creates and hands to spawn_background_tasks. metrics_stop_tx goes straight from run into ShutdownHandles. If bring-up fails, the dropped stop sender ends the accept loop and the listening socket closes. The shutdown order is the same as before: the metrics stop is still the first send.
  • decdn_rpc_healthy is seeded right after the preflight passes. Before, it was seeded after the boot chain reads. With /metrics live during boot, the default 0 would otherwise page the critical DecdnRpcUnhealthy alert (== 0 for 2 m) on every slow boot.
  • New gauge decdn_node_boot_ready. It reads 0 from process start and 1 just before the node runtime ready banner.
  • ADR appendix-observability.
    • A registry row for the gauge.
    • A recommended alert: max_over_time(decdn_node_boot_ready[15m]) == 0 for 10 m. On a first boot it fires at 10 m, which matches the boot-read budget.
    • The decdn_chain_boot_read_retries_total row is corrected, and its list of retried reads now includes the deployment preflight.
  • Stale "metrics binds after boot" text fixed in the boot_retry.rs docs, the metrics.rs field doc, docs/runbook.md and the runtime comments.

Closes #2819

Reviewer notes

  • Read run, the end of build_infra's preflight, and the end of spawn_background_tasks in crates/node/src/runtime/mod.rs first.
  • Alerting gap until the devops companion PR ships. A node stuck in boot no longer fires DecdnNodeDown, because the scrape now succeeds. The decdn/devops companion (decdn/devops#202) adds the DecdnNodeBootStuck rule and a dashboard target, and has to ship with the release that carries this change. On a stuck boot, DecdnNoActiveStreams (15 m) and DecdnDhtRoutingTableEmpty (30 m) now fire too, which is accurate for a node that serves nothing.
  • What node_boot_ready covers. It flips after the fail-closed reads and the admin bind. The admin server's start (in its spawned task), the deferred buyer bootstrap and the ALPN router registration come after the flip. The comment at the call site says so.
  • Not changed, out of scope:
    • The RPC preflight's own retries are counted by no metric. They show only in WARN lines, and the docs now say so.
    • metrics::serve never returns Err, so the exited with error branch is unreachable. That predates this PR.
    • The snapshot fallback for pruned state and the fail-fast on a fatal preflight, as the issue says.

Verification

  • runtime::tests, all new:

    • metrics_listener_serves_during_boot: red on main, green now.
    • metrics_listener_closes_after_bring_up_error: wiremock sends a delayed fatal 400; the test scrapes during the delay, then sees the port refuse connections.
    • rpc_healthy_is_seeded_once_the_preflight_passes: catches the mutant that drops the seed.
    • The scrape helper fails fast with run's own error.
  • anvil_bringup_shutdown_e2e scrapes /metrics over HTTP and asserts decdn_node_boot_ready 1. It passes, and it fails when the node_boot_ready() call is removed.

  • cargo nextest run -p decdn-node: 1895 passed.

  • cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo fmt -- --check, CARGO_BUILD_WARNINGS=deny cargo doc -p decdn-node --no-deps --document-private-items and make -C adr check-refs are all clean, and the pre-commit hooks pass. The cargo-deny crypto-bigint advisory is unrelated and warn-only.

  • adr/: make -C adr check-refs. architecture.md needs no change.

  • A metric name: the devops dashboard and alert are tracked in monitoring: alert and panel for decdn_node_boot_ready (decdn#2821) devops#202.

🤖 Generated with Claude Code

`run` now binds and serves the metrics listener before `build_infra`, so a
node that retries its RPC preflight, deployment preflight or boot chain
reads still answers scrapes, and `decdn_chain_boot_read_retries_total` is
live while those reads retry. The serve task sits in the runtime's
`JoinSet`, so a bring-up error stops it and frees the port.

`decdn_node_boot_ready` reads 0 from process start and 1 once bring-up
finishes, just before the `node runtime ready` banner, so a node stuck in
boot can be alerted on directly. ADR appendix-observability gains its
registry row and a recommended alert.

Closes #2819

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras thiras self-assigned this Nov 1, 2026
Copilot AI balanced review requested due to automatic review settings November 1, 2026 15:49

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.

🟡 Changes recommended

The alert timing documentation needs to distinguish new targets that can alert after about 5 minutes from targets with a previous ready sample, rather than imply a guaranteed 15-minute boot allowance.

1 open issue
What changed in this PR

Makes node startup observable by serving /metrics before boot-time RPC checks, addressing the monitoring gap described in #2819.

Changes:

  • Starts the metrics server before infrastructure initialization while preserving shutdown handling.
  • Adds decdn_node_boot_ready to distinguish booting nodes from ready nodes.
  • Tests both readiness states and updates boot-metrics documentation and alert guidance.
File Description
crates/​node/​tests/​anvil_bringup_shutdown_e2e.rs Checks that successful bring-up sets the readiness gauge to 1.
crates/​node/​src/​runtime/​tests.rs Checks that metrics respond during boot with readiness 0.
crates/​node/​src/​runtime/​mod.rs Starts metrics before boot checks and marks completed bring-up.
crates/​node/​src/​metrics.rs Defines the readiness gauge and its recorder.
crates/​node/​src/​chain_events/​boot_retry.rs Updates module comments to describe metrics availability during boot.
adr/​appendix-observability.md Documents readiness, alert guidance, and boot retry visibility.

Review effort: Balanced

Comment thread adr/appendix-observability.md Resolved
@github-code-quality

github-code-quality Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main e7e67e6 fix/2819-metrics-bef... e2d64a9 +/-
77% 77% 0%
View coverage of the 4 most impacted files.
File main e7e67e6 fix/2819-metrics-bef... e2d64a9 +/-
crates/node/src/dht/publish.rs 80% 78% -2%
crates/client/src/scheduler.rs 94% 95% +1%
crates/protocol/src/framing.rs 92% 93% +1%
crates/node/src/runtime/mod.rs 26% 29% +3%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 01, 2026 16:10 UTC

… docs

`/metrics` serves during boot, so `decdn_rpc_healthy` read its default 0
until the boot chain reads finished, and the RPC alert would page on any
slow boot. `build_infra` now seeds it right after the reachability
preflight passes.

Tests: the listening socket closes after a bring-up error, rpc_healthy
reads 1 once the preflight passes, the boot scrape fails fast with run's
own error, and the bring-up e2e reads boot_ready over HTTP.

Docs: the boot-ready alert window matches the 10-minute boot budget
([15m] window, 10 m `for`), the retry counter lists the deployment
preflight, and the stale "metrics binds after boot" claims in comments,
the metrics field doc and the runbook describe the current order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 034f8a7 into main Nov 1, 2026
38 checks passed
@thiras
thiras deleted the fix/2819-metrics-before-boot branch November 1, 2026 16:15
thiras added a commit to decdn/devops that referenced this pull request Nov 1, 2026
* feat(monitoring): alert and panel for decdn_node_boot_ready

decdn/decdn#2821 serves /metrics during boot, so a node stuck in boot
scrapes fine and DecdnNodeDown no longer pages for it. Add
DecdnNodeBootStuck (max_over_time(decdn_node_boot_ready[15m]) == 0 for
10m, the appendix-observability recommendation) with promtool tests,
and plot min boot ready on the chain dashboard's chain RPC panel.

Closes #202

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(monitoring): pin DecdnNodeBootStuck's crash loop and resolve in tests

The crash-loop series used bare gaps, which the 5m lookback bridges, so
the bare gauge passed it too: model each failed scrape as a staleness
marker. Add a node that comes up, to pin the resolve. Name the for, not
the boot deadline, as the 10m, and reword the two older "before the
first scrape" rationales that #2821 no longer guarantees.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
thiras added a commit to decdn/devops that referenced this pull request Nov 1, 2026
* fix: readiness waits for decdn_node_boot_ready, not a 200

decdn/decdn#2821 serves /metrics from process start, with
decdn_node_boot_ready 0 until boot finishes, so a 200 no longer means
boot is done. One rule everywhere: ready is a 200 with the gauge at 1,
or a 200 with no gauge (older releases bind /metrics only after boot).

- Role: the readiness probe retries a 200 that says 0, and its
  advisory warning names which state it ended in.
- decdn-compose health: reports boot from the gauge (boot_state).
- Chart: the default startupProbe runs `decdn node health` (the admin
  RPC starts after boot), so the 5-minute budget restarts a stuck boot
  again and the pod goes Ready only after boot; the render refuses
  admin_port 0 with that probe and any probe with two handlers.
- Molecule: the stub boots with the gauge at 0 then 1 (stuck, legacy
  and no-metrics modes); slow-readiness covers a stuck boot and, in a
  side effect, a daemon that never binds; host-env covers a release
  without the gauge.

Closes #204

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: harden boot-readiness checks after review

- Role: a decdn_node_boot_ready sample that is not exactly `1` (0.0,
  labelled, timestamped) counts as booting, so a format change upstream
  cannot pass as ready; uri gets timeout: 5, and the warning prints the
  sample it saw or the last error. The warning is registered.
- decdn-compose: boot_state returns (ready, detail), reads labelled and
  timestamped samples, and no longer claims a gauge a release lacks.
- Chart: startupProbe budget 10 min (upstream's boot-read retry budget);
  the admin_port guard matches `sh -c "decdn node health"` and refuses a
  string command; NOTES.txt and the README describe the new ordering
  (the first ContentBlacklist sync is part of boot).
- Molecule: the stub's boot clock starts at the first scrape and gains
  an `error` mode; slow-readiness asserts the warning branch, that a
  never-binding daemon stayed up, and that a 500 fails the probe on its
  first attempt; default/host-env assert the probe stopped before its
  window with no warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

node: the metrics listener binds only after the boot chain reads, so a node stuck in boot exports nothing

2 participants