Skip to content

feat(node): add rpc connectivity watchdog with rpc_healthy gauge - #366

Merged
thiras merged 2 commits into
mainfrom
feat/rpc-watchdog
Apr 30, 2026
Merged

thiras merged 2 commits into
mainfrom
feat/rpc-watchdog

Conversation

@thiras

@thiras thiras commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds a periodic JSON-RPC reachability watchdog that drives a new decdn_rpc_healthy Prometheus gauge (1 = reachable, 0 = unreachable per the watchdog task).
  • Configurable via blockchain.rpc_watchdog_interval_sec (default 30s; 0 disables). Logs warn on the down transition and info on recovery; steady-state ticks are silent.
  • Shares the net_version probe with the existing startup check_rpc_reachability so success/failure semantics stay aligned, and plumbs clean shutdown through the existing oneshot + runtime drain pattern.

Test plan

  • cargo fmt -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo nextest run -p decdn-node (135/135 passing, including new runtime::tests::rpc_watchdog_tracks_endpoint_transitions covering healthy -> unhealthy -> healthy gauge transitions via wiremock)
  • cargo deny check
  • Manual: curl localhost:9090/metrics | grep rpc_healthy after starting a node against a reachable RPC

Closes #283

🤖 Generated with Claude Code

Periodically poll the configured JSON-RPC endpoint and expose the result
as `decdn_rpc_healthy` (1 = reachable, 0 = unreachable) so dashboards can
alert on a sustained outage rather than relying on the one-shot startup
check. Logs `warn` on the down transition and `info` on recovery; steady-
state ticks are silent.

Interval is configurable via `blockchain.rpc_watchdog_interval_sec`
(default 30, `0` disables). The watchdog shares its probe with the
existing startup `check_rpc_reachability` so success/failure semantics
stay aligned. Shutdown is plumbed via `oneshot` and awaited in the
runtime drain phase next to the gossip handles.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Closes #283
Copilot AI review requested due to automatic review settings April 30, 2026 20:16

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request implements an RPC connectivity watchdog that periodically probes the configured RPC endpoint and updates a health metric. It includes changes to the configuration system to support a probe interval, new metrics for monitoring reachability, and a background task to perform the checks. The review feedback suggests initializing the health metric regardless of whether the watchdog is enabled, removing redundant seeding logic within the task, and improving security by redacting raw RPC URLs from log messages to prevent potential credential leakage.

Comment thread crates/node/src/runtime/mod.rs Resolved
Comment thread crates/node/src/runtime/mod.rs Resolved
Comment thread crates/node/src/runtime/mod.rs Resolved
Comment thread crates/node/src/runtime/mod.rs Resolved

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.

Pull request overview

Adds an RPC reachability watchdog to the node runtime and exposes its status via a new Prometheus gauge, making RPC outages observable during steady-state operation (not just at startup).

Changes:

  • Introduces a periodic JSON-RPC net_version probe loop that updates a new decdn_rpc_healthy gauge and logs on up/down transitions.
  • Factors the existing startup RPC check into a shared probe_rpc helper to keep success/failure semantics aligned.
  • Wires a new blockchain.rpc_watchdog_interval_sec config field through config resolution and validates/reporting; adds a wiremock-based runtime test.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/node/src/runtime/mod.rs Spawns/shuts down the watchdog task, factors out probe_rpc, and adds a transition test.
crates/node/src/metrics.rs Adds rpc_healthy gauge plus helpers for setting/reading it (test-only read).
crates/node/src/config/types.rs Adds TOML config field rpc_watchdog_interval_sec.
crates/node/src/config/resolved.rs Adds resolved config field for the watchdog interval.
crates/node/src/config/mod.rs Adds default interval constant and resolves the new field into ResolvedBlockchain.
crates/node/src/commands/mod.rs Prints the resolved watchdog interval in config validate output and documents it in the sample config.
crates/node/tests/config_validate.rs Updates resolved-config test fixture to include the new required field.
crates/node/Cargo.toml Adds wiremock dev-dependency for the new runtime test.
Cargo.lock Locks the new wiremock dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/node/src/runtime/mod.rs Resolved
Comment thread crates/node/src/runtime/mod.rs Resolved
Comment thread crates/node/src/runtime/mod.rs Resolved
Address review feedback on PR #366:

- Seed `rpc_healthy(true)` from `run()` right after the successful
  startup `check_rpc_reachability` probe, before the watchdog-spawn
  branch. Covers the `rpc_watchdog_interval_sec == 0` (disabled) case
  too, so a registered Prometheus gauge no longer defaults to 0 and
  trips outage alerts on a healthy node.
- Drop the redundant in-watchdog seed and update its doc comment to
  match (caller seeds, watchdog only writes on tick boundaries).
- Drop `%url` from the RPC-healthy / RPC-unhealthy transition logs.
  The URL may carry basic-auth credentials in its userinfo
  component, and the node configures one RPC endpoint so the log
  doesn't need to identify which one. `%err` is kept on the warn.
- Fix the `mount_healthy` test helper doc comment so it no longer
  claims to return a guard the function doesn't return.
- Update the runtime test to mirror the new seeding contract.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thiras
thiras merged commit 2310ae0 into main Apr 30, 2026
11 checks passed
@thiras
thiras deleted the feat/rpc-watchdog branch April 30, 2026 20:44
thiras added a commit that referenced this pull request Apr 30, 2026
Resolves conflicts with PRs #363/#364/#365/#366 that landed on main while
this branch was in review. Conflict resolution:

- crates/node/Cargo.toml: keep both new dev-deps (nix from this branch
  for SIGHUP integration tests, wiremock from #366 for the rpc-watchdog
  test).
- crates/node/src/runtime/mod.rs: union the test-module clippy allows
  ([unwrap_used, expect_used, panic, indexing_slicing]); keep both new
  test bodies (rpc_watchdog_tracks_endpoint_transitions from #366 plus
  shutdown_streams_recv_resolves_on_sigterm from this branch).
- Test fixtures across config/mod.rs, runtime/reload.rs, and
  tests/sighup_signal.rs gained the rpc_watchdog_interval_sec field
  (Option::None for FileConfig literals; literal 30u64 for ResolvedBlockchain).

Verified post-merge: cargo fmt --check, cargo clippy --workspace
--all-targets -- -D warnings, cargo nextest run -p decdn-node (179/179),
RUSTDOCFLAGS=-D warnings cargo doc --workspace --no-deps --document-private-items,
all clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <[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

2 participants