Repository navigation
feat(node): count every JSON-RPC request by method and outcome - #2246
Conversation
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]>
There was a problem hiding this comment.
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_metricstransport 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 astimeout; the rate-limit predicate is centralized here and reused by the poller. - New
RpcMethod/RpcOutcomelabel types and anRpcMetricsgroup inmetrics.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
DecdnRpcErrorRatioHighalert, 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.
Code Coverage OverviewLanguages: Rust Rust / code-coverage/cargo-llvm-covThe overall line coverage in commit 1e8fe54 in the Show a line coverage summary of the most impacted files.
|
Summary
Operators had no denominator for chain-RPC health:
decdn_rpc_healthyis a 0/1 probe, and the other RPC counters only see failures on specific paths. This adds per-request metrics at one choke point.crates/node/src/rpc_metrics.rs).ProviderFactorybecomes 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 throughmetered_http_client. No call site changes. The layer usesClientBuilder::default().layer(..).http(url), which is whatconnect_httpdoes, so alloy's localhost poll default is unchanged (the existingprovider_factory_preserves_role_polling_policytest still pins that).decdn_rpc_requests_total{method,outcome}:methodis a closed set of 15 JSON-RPC names plusother.outcomeis one ofok,reverted,rpc_error,rate_limited,transport_error,timeout.timeoutcovers a reqwest timeout and a request whose caller dropped it, which in this node means the per-calltimeddeadline fired. A drop guard records it.decdn_rpc_request_duration_seconds{method}: buckets 10 ms to 10 s, with the top bucket atDEFAULT_RPC_CALL_TIMEOUT. A dropped request records no sample.RpcMetricsgroup.DecdnMetricsderivesDeserialize, and a labelled histogram family cannot deserialize, so they can't go there.multiplexed_pollerintorpc_metrics::is_rate_limit, so the poller and the metric share one definition.dashboard-chain.jsongets 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.ymlgetsDecdnRpcErrorRatioHigh: ratio over 10m > 10% for 15m, excludingokandreverted, with a volume guard of > 0.05 req/s.adr/appendix-observability.mdgets a new § Chain RPC Metrics (registry rows are gate-enforced) and a note thatoutcomemeets 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_exportedandadr_registry_names_are_exportedcargo clippy --workspace --all-targets --all-features,cargo fmt --check,RUSTDOCFLAGS=-D warnings cargo docpromtool check rules monitoring/prometheus-alerts.yml(promtool isn't installed locally)🤖 Generated with Claude Code