Skip to content

feat(metrics): export stream, volume, tx and DHT health; alert on the gaps - #2059

Merged
thiras merged 3 commits into
mainfrom
feat/metrics-alerts
Sep 19, 2026
Merged

thiras merged 3 commits into
mainfrom
feat/metrics-alerts

Conversation

@thiras

@thiras thiras commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Third of three observability PRs; #2057 and #2058 are merged.

Why

Eleven appendix-observability registry rows — including the Mandatory delivery counters (streams completed/failed, bytes served/received) and redemptions — were planned with nothing emitting them. Several failure paths were only logged (fee-shares getShares() re-reads, DHT refresh/bootstrap, config reload, receipt writes, the mid-stream PoolExhausted stop). And live counters whose every increase is a bug or lost revenue had no alert (slashes_detected, rpc_healthy, redemption_failures, node-fault / corruption / persist / flush counters, fee-shares watcher liveness).

Metrics

Family Where it counts
decdn_streams_{completed,failed}_total{direction} inbound from the ServeEnd #2058 records on the span; outbound per upstream candidate. Every stream counts once. Reason split stays in the sibling counters (per the ADR's siblings-not-labels rule), so the row drops its reason label
decdn_bytes_served_total / decdn_bytes_received_total per written frame / per verified range on paid node-to-node pulls only
decdn_onchain_tx_{landed,reverted,send_failed,receipt_failed,timeout}_total send_and_await_receipt choke point
decdn_pool_redemptions_total, decdn_vouchers_received_total, decdn_pool_grace_closes_total landed redeemMany voucher count; voucher accept; PoolCloseInitiated while this node has an unpaid lane on the pool
DHT: findvalue_queries, lookup_round_timeouts, store_published, routing_table_size, bucket_refresh_failures, bootstrap_find_node_failures lookup / publish / refresh / bootstrap
decdn_fee_shares_watcher_{poll_failures_total,restarts_total,down_seconds} poll failure + the downtime family the other watchers already had (hooks were None)
decdn_config_reload_failures_total, decdn_receipt_write_failures_total, decdn_serve_stream_midstream_pool_exhausted_total reload state, receipt writer, mid-stream stop

vouchers_signed stays planned (the payer-side count lives in client-pull); its ADR description had payer/payee swapped and is fixed. reputation_score, probe_* stay planned.

Alerts (promtool: 31 rules OK)

DecdnSlashDetected (critical), DecdnRpcUnhealthy (critical), DecdnFeeSharesWatcherStalled, DecdnFeeSharesPollFailing, DecdnRedemptionFailing, DecdnOnchainTxTimeouts, DecdnServeNodeFault, DecdnFrameAccountingFault, DecdnWatcherPersistFailures, DecdnLaneFlushFailures, DecdnNodePullCorruption, DecdnConfigReloadFailed, DecdnReceiptLogWriteFailing. Latent-bug counters use increase(...[1h]) > 0 so they resolve.

Dashboards

Delivery: stream outcomes by direction (+ mid-stream funding stops), wire bytes served/received. Chain: on-chain tx outcomes; vouchers/redemptions/grace closes; receipt write failures. Node: DHT discovery/publishing, routing table size, operator-path failures. Not yet pushed to Grafana Cloud.

Test plan

  • cargo nextest run -p decdn-node -p decdn-client-pull -p decdn-cache -p decdn-cli — 2581 passed, incl. the monitoring/ + ADR metric-name gates
  • New tests: every new series exports at zero; stream outcomes split by direction; fee-shares downtime transitions; tx outcome counted at the choke point
  • promtool check rules monitoring/prometheus-alerts.yml
  • anvil-e2e targets compile; clippy/doc/fmt via pre-commit

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings September 19, 2026 02:34
@thiras thiras self-assigned this Sep 19, 2026

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

🟡 Changes recommended

The node dashboard currently caps routing-table size at max: 100, which will clip real values and make the new DHT visibility misleading in production.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

This PR completes the observability rollout by wiring previously “planned” node metrics into the Rust runtime, then surfacing them in Prometheus alert rules and the bundled Grafana dashboards (delivery/chain/node), alongside registry and changelog updates.

Changes:

  • Add/emit new decdn_* metrics for stream outcomes + byte volume, on-chain tx outcomes, DHT health, fee-shares watcher health, and operator-path failures.
  • Add Prometheus alert rules for “latent bug / lost revenue” counters and watcher/RPC health gaps.
  • Extend the Grafana dashboards + observability appendix/CHANGELOG to document and visualize the new series.
File Description
monitoring/​prometheus-alerts.yml Adds new alert rules for slashing, RPC health, config/receipt failures, tx timeouts, and latent-bug counters.
monitoring/​dashboard-node.json Adds node drilldown panels for operator-path failures and DHT activity/routing table size.
monitoring/​dashboard-delivery.json Adds delivery panels for stream outcomes by direction and bytes served/received.
monitoring/​dashboard-chain.json Adds chain panels for on-chain tx outcomes, voucher/redemption/grace-close activity, and receipt write failures.
crates/​node/​tests/​bucket_refresh_clock.rs Updates bucket-refresh test harness to provide a Metrics handle.
crates/​node/​src/​runtime/​reload.rs Counts failed reload attempts into decdn_config_reload_failures_total (after metrics attachment).
crates/​node/​src/​runtime/​mod.rs Attaches metrics to reload state; records bootstrap + bucket-refresh DHT metrics.
crates/​node/​src/​receipt_log.rs Plumbs metrics into the receipt writer loop and counts write failures.
crates/​node/​src/​payment_settlement.rs Counts grace-close events when unredeemed vouchers exist; counts redeemed vouchers on landed redeemMany.
crates/​node/​src/​onchain_tx.rs Centralizes tx outcome counting at the send_and_await_receipt choke point; adds a unit test.
crates/​node/​src/​node_origin/​pull_leg.rs Counts bytes received on paid node-to-node pulls via the admit store.
crates/​node/​src/​node_origin/​mod.rs Counts outbound stream completion/failure for upstream candidate pulls.
crates/​node/​src/​node_origin/​admit_store.rs Adds optional “count bytes received” instrumentation on admitted verified ranges.
crates/​node/​src/​metrics.rs Defines and wires the new metrics families/recorders plus export-at-zero and direction split tests.
crates/​node/​src/​handlers/​client/​voucher.rs Increments vouchers-received counter on voucher acceptance.
crates/​node/​src/​handlers/​client/​serve_leg.rs Counts bytes served per written frame; counts mid-stream pool exhaustion stops.
crates/​node/​src/​handlers/​client/​dispatch.rs Counts inbound stream completion/failure based on ServeEnd.
crates/​node/​src/​handlers/​client/​delivery.rs Counts bytes served per written frame; counts mid-stream pool exhaustion stops.
crates/​node/​src/​fee_shares_watcher.rs Adds poll-failure counting and watcher downtime hooks for fee-shares.
crates/​node/​src/​dht/​publish.rs Counts accepted STORE records via publish return values for single/batched republish.
crates/​node/​src/​dht/​lookup.rs Counts findvalue queries and lookup round timeouts when metrics are provided.
crates/​node/​src/​dht/​bucket_refresh.rs Counts bucket-refresh failures and publishes routing table size each tick.
CHANGELOG.md Documents new metric families, alerts, and dashboard panels.
adr/​appendix-observability.md Updates the metric registry rows from planned → live and corrects descriptions/labeling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread monitoring/dashboard-node.json Resolved
Comment thread crates/node/src/dht/bucket_refresh.rs Resolved
@thiras
thiras force-pushed the feat/metrics-alerts branch 2 times, most recently from 632f266 to cdf0da4 Compare September 19, 2026 03:02
@thiras
thiras force-pushed the feat/metrics-alerts branch from cdf0da4 to 44e822c Compare September 19, 2026 03:13
@thiras
thiras force-pushed the feat/metrics-alerts branch 2 times, most recently from a2b3f62 to d113b87 Compare September 19, 2026 03:44
Base automatically changed from feat/trace-spans to main September 19, 2026 03:50
… gaps

Eleven registry rows — including the Mandatory delivery counters — were
`planned` with nothing emitting them, several failure paths were only
logged, and a set of live counters whose every increase is a bug or
lost revenue had no alert.

Metrics:
- `decdn_streams_{completed,failed}_total{direction}`: every inbound
  serve (from the `ServeEnd` the span already records) and every
  outbound per-candidate pull counts exactly once. The reason split
  stays in the sibling `serve_stream_rejected_*` / `node_pull_*`
  counters, so the ADR row drops its `reason` label.
- `decdn_bytes_served_total` per written frame, `decdn_bytes_received_total`
  per verified range on the paid node-to-node pulls only.
- `decdn_onchain_tx_*_total` (landed / reverted / send_failed /
  receipt_failed / timeout) at the `send_and_await_receipt` choke point;
  `decdn_pool_redemptions_total`, `decdn_vouchers_received_total`,
  `decdn_pool_grace_closes_total` (a closing pool with an unpaid lane).
- DHT: find_value lookups, round timeouts, accepted STOREs, routing
  table size, bucket-refresh and bootstrap FIND_NODE failures.
- Fee-shares watcher: `getShares()` poll failures (its tick still
  succeeds, so nothing else saw them) and the downtime family the other
  watchers already had.
- Config reload failures, receipt write failures, and the mid-stream
  `PoolExhausted` stop (the signer-cap sibling was already counted).

Alerts (promtool-clean): slash detected, RPC unhealthy, fee-shares
stall and poll failure, sustained redemption failure, tx receipt
timeouts, serve node fault, frame accounting fault, watcher persist
failure, lane flush failure, node-pull corruption, config reload failure,
receipt log write failure. Delivery, chain and node dashboards gain
panels for each family. `vouchers_signed` stays `planned` (its payer-side
count lives in client-pull) with its description corrected.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@thiras
thiras force-pushed the feat/metrics-alerts branch from d113b87 to 2d69d28 Compare September 19, 2026 03:51
Review on #2059:

- The three new node-dashboard panels inherited `max: 100` from the CPU
  panel they were built from, clipping the routing-table size and any
  rate above 100. The cap is gone.
- `decdn_dht_bucket_refresh_failures_total` counts invalid peer keys and
  panicked refresh tasks as well as FIND_NODE errors; the function,
  metric and ADR docs now say so.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 83.02% (was 83.03%, ▼ 0.01%) — 80943/97502 lines

File Coverage Lines Δ
crates/node/src/dht/bucket_refresh.rs 73.44% 141/192 ▼ 2.41%
crates/node/src/dht/lookup.rs 96.14% 423/440 ▼ 0.19%
crates/node/src/dht/publish.rs 89.86% 1117/1243 ▼ 0.76%
crates/node/src/fee_shares_watcher.rs 83.63% 143/171 ▲ +0.29%
crates/node/src/handlers/client/delivery.rs 92.18% 330/358 ▲ +0.04%
crates/node/src/handlers/client/dispatch.rs 80.97% 515/636 ▼ 0.01%
crates/node/src/handlers/client/serve_leg.rs 72.08% 142/197 ▼ 0.23%
crates/node/src/handlers/client/voucher.rs 93.73% 538/574 ▲ +0.01%
crates/node/src/metrics.rs 95.59% 1063/1112 ▲ +0.38%
crates/node/src/node_origin/admit_store.rs 93.51% 216/231 ▲ +0.23%
crates/node/src/node_origin/mod.rs 92.33% 1131/1225 ▲ +0.04%
crates/node/src/node_origin/pull_leg.rs 84.64% 722/853 ▲ +0.13%
crates/node/src/onchain_tx.rs 71.19% 42/59 ▲ +17.62%
crates/node/src/payment_settlement.rs 64.29% 1017/1582 ▲ +0.02%
crates/node/src/receipt_log.rs 90.60% 540/596 ▲ +0.04%
crates/node/src/runtime/mod.rs 47.95% 1168/2436 ▼ 0.22%
crates/node/src/runtime/reload.rs 96.95% 1655/1707 ▲ +0.04%
History
Commit Total Δ vs base
249cfc8 83.00% ▼ 0.03%
abe954b (HEAD) 83.02% ▼ 0.01%

…re alerts

Multi-agent review of #2059:

- The streaming miss path (`run_pull_leg`) recorded no outbound stream
  outcome, so `decdn_streams_*{direction="outbound"}` covered only the
  buffered path. It now records one outcome per assembled range (a
  cancelled assembly counts as neither).
- The buffered path counted every candidate it skipped before opening
  a stream — no address, above the ADR 041 buy ceiling, a pool-open
  failure — as a failed stream. It now counts only candidates it
  opened a stream to.
- Docs, ADR rows and panels say what each counter actually counts:
  failed inbound streams include routine outcomes (a cache-miss
  refusal, an early close, the free header handshake a downstream miss
  pull closes by design), so no raw success ratio; cancelled streams
  count in neither family; redemptions count lane claims; vouchers
  exclude PayWord reveals; `onchain_tx_*` is the settlement path only;
  a failed reload can leave earlier sections applied.
- Alerts: `DecdnSlashDetected` fires on the value, not `increase()`,
  since the watcher's backfill counts every still-appealable slash
  before the first scrape; new `DecdnPoolGraceCloseWithUnredeemed` and
  `DecdnDhtRoutingTableEmpty`; the stale "no outcome-labelled stream
  family" comment is corrected. promtool: 33 rules OK.
- Tests at the real call sites: a served stream counts one completed
  inbound stream, its vouchers and bytes; a relayed miss counts one
  completed outbound stream and bytes both ways; an own-origin fill
  counts no bytes received; a failed reload and a failed receipt write
  each count once; the grace-close predicate's four cases.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@thiras
thiras merged commit fd5bc3e into main Sep 19, 2026
25 checks passed
@thiras
thiras deleted the feat/metrics-alerts branch September 19, 2026 04:21
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