Skip to content

feat(node): count every JSON-RPC request by method and outcome - #2246

Merged
alpergundogdu merged 1 commit into
mainfrom
claude/interesting-davinci-308b22
Sep 30, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
claude/interesting-davinci-308b22

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Summary

Operators had no denominator for chain-RPC health: decdn_rpc_healthy is a 0/1 probe, and the other RPC counters only see failures on specific paths. This adds per-request metrics at one choke point.

  • Tower layer on the alloy RPC client (crates/node/src/rpc_metrics.rs). ProviderFactory becomes a value holding the URL and the metrics handle, and every role (read-only, shared head, seller wallet, buyer wallet, deployment preflight) builds its client through metered_http_client. No call site changes. The layer uses ClientBuilder::default().layer(..).http(url), which is what connect_http does, so alloy's localhost poll default is unchanged (the existing provider_factory_preserves_role_polling_policy test still pins that).
  • decdn_rpc_requests_total{method,outcome}:
    • method is a closed set of 15 JSON-RPC names plus other.
    • outcome is one of ok, reverted, rpc_error, rate_limited, transport_error, timeout. timeout covers a reqwest timeout and a request whose caller dropped it, which in this node means the per-call timed deadline fired. A drop guard records it.
    • Batch replies are matched per request by id.
    • All 96 pairs are exported at zero from startup.
    • The URL is never a label.
  • decdn_rpc_request_duration_seconds{method}: buckets 10 ms to 10 s, with the top bucket at DEFAULT_RPC_CALL_TIMEOUT. A dropped request records no sample.
  • These metrics live in a separate RpcMetrics group. DecdnMetrics derives Deserialize, and a labelled histogram family cannot deserialize, so they can't go there.
  • The rate-limit predicate moves from multiplexed_poller into rpc_metrics::is_rate_limit, so the poller and the metric share one definition.
  • Monitoring: dashboard-chain.json gets a "Chain RPC provider" row with request rate by method, error ratio by method (plus all methods), failures by outcome, and p95 latency by method. prometheus-alerts.yml gets DecdnRpcErrorRatioHigh: ratio over 10m > 10% for 15m, excluding ok and reverted, with a volume guard of > 0.05 req/s.
  • Docs: adr/appendix-observability.md gets a new § Chain RPC Metrics (registry rows are gate-enforced) and a note that outcome meets the labelled-reason-split bar. docs/runbook.md § RPC unreachable covers the new alert.

Test plan

  • cargo nextest run -p decdn-node: 1502 passed. Includes the new classification unit tests, wiremock end-to-end tests (ok / reverted / 429 / dropped-at-deadline), the exposure test, monitoring_selectors_are_exported and adr_registry_names_are_exported
  • cargo clippy --workspace --all-targets --all-features, cargo fmt --check, RUSTDOCFLAGS=-D warnings cargo doc
  • pre-commit (crate edges, ADR hygiene, markdownlint, yaml)
  • promtool check rules monitoring/prometheus-alerts.yml (promtool isn't installed locally)

🤖 Generated with Claude Code

A tower layer on the alloy RPC client, installed once in ProviderFactory,
records every request the node's providers send on
decdn_rpc_requests_total{method,outcome} and
decdn_rpc_request_duration_seconds{method}. Outcomes: ok, reverted,
rpc_error, rate_limited, transport_error, timeout (a caller-dropped
request). Methods are a closed set plus `other`; the URL is never a label.

The chain dashboard gains a "Chain RPC provider" row (rate, error ratio,
failures by outcome, p95 latency by method), and DecdnRpcErrorRatioHigh
fires on a sustained >10% error ratio. The rate-limit predicate moves from
the multiplexed poller into rpc_metrics so both share one definition.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings September 30, 2026 09:48

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

🔵 Needs a closer look

It reworks the core chain-provider construction path and inserts transport middleware intercepting every on-chain RPC, which—despite strong test coverage and no bugs found—warrants human review before merge.

Review effort: Balanced
Findings: None

What changed in this PR

This PR adds per-request JSON-RPC observability for the node's chain provider. It introduces a Tower layer on the alloy RPC client (rpc_metrics.rs) that classifies every request by method and outcome, records decdn_rpc_requests_total{method,outcome} and decdn_rpc_request_duration_seconds{method}, and refactors ProviderFactory from static constructors into a value carrying the URL and metrics handle so every provider role is metered without call-site changes. It gives operators the denominator that decdn_rpc_healthy (a 0/1 probe) lacks, wiring the new series into the chain dashboard, an error-ratio alert, the observability ADR, and the runbook.

Changes:

  • New rpc_metrics transport layer with outcome classification (ok/reverted/rpc_error/rate_limited/transport_error/timeout), batch-by-id matching, and a drop-guard that records dropped requests as timeout; the rate-limit predicate is centralized here and reused by the poller.
  • New RpcMethod/RpcOutcome label types and an RpcMetrics group in metrics.rs, with all 96 (method, outcome) pairs and per-method histograms materialized at zero from startup.
  • Monitoring + docs: a "Chain RPC provider" dashboard row, the DecdnRpcErrorRatioHigh alert, an ADR registry section, and a runbook note.
File Description
crates/​node/​src/​rpc_metrics.rs New Tower layer/service, request classification, drop-guard timeout, and tests
crates/​node/​src/​metrics.rs RpcMethod/RpcOutcome labels, RpcMetrics group, rpc_request recorder, zero-export tests
crates/​node/​src/​runtime/​mod.rs ProviderFactory becomes a metered value; all provider call sites updated
crates/​node/​src/​chain_events/​multiplexed_poller.rs Moves is_rate_limit/RATE_LIMIT_WORDS into rpc_metrics; imports the shared predicate
crates/​node/​src/​lib.rs Registers the new rpc_metrics module
crates/​node/​Cargo.toml Promotes tower/alloy-json-rpc from dev- to normal dependencies
Cargo.toml Updates the rationale comments for tower/alloy-json-rpc
monitoring/​dashboard-chain.json Adds request-rate, error-ratio, failures-by-outcome, and p95 panels
monitoring/​prometheus-alerts.yml Adds DecdnRpcErrorRatioHigh with a volume guard
adr/​appendix-observability.md Adds the Chain RPC Metrics registry rows and reason-split note
docs/​runbook.md Documents the new alert under RPC unreachable

💡 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 1e8fe54 in the claude/interesting-d... branch remains at 87%, unchanged from commit 5aa68b3 in the main branch.

Show a line coverage summary of the most impacted files.
File main 5aa68b3 claude/interesting-d... 1e8fe54 +/-
crates/node/src...nt/serve_leg.rs 92% 91% -1%
crates/incentiv...eth_identity.rs 99% 98% -1%
crates/node/src/metrics.rs 96% 96% 0%
crates/protocol/src/framing.rs 97% 97% 0%
crates/node/src...lexed_poller.rs 93% 93% 0%
crates/node/src/runtime/mod.rs 53% 54% +1%
crates/node/src/rpc_metrics.rs 0% 99% +99%

@alpergundogdu
alpergundogdu merged commit 769de4b into main Sep 30, 2026
58 of 60 checks passed
@alpergundogdu
alpergundogdu deleted the claude/interesting-davinci-308b22 branch September 30, 2026 10:17
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