Skip to content

feat(monitoring): map active nodes by declared region on the chain dashboard - #2056

Merged
thiras merged 2 commits into
mainfrom
feat/network-region-map
Sep 19, 2026
Merged

thiras merged 2 commits into
mainfrom
feat/network-region-map

Conversation

@thiras

@thiras thiras commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a world map of active nodes to the chain dashboard (decdn-chain). Every node's CapacityBond registry already holds the whole network's NodeId → regionHint map (ADR 030), so exporting it as a gauge lets a single scrape map the network.

  • decdn_staker_set_active_by_region{node_region}:
    • Counts active stakers per region.
    • Recomputed at bootstrap, at the end of every clean watcher tick, and after each resync.
    • Values pass Region::parse, so the ISO allowlist bounds cardinality.
    • A region with no active node loses its series.
  • decdn_staker_set_active_unknown_region: active stakers with an empty or invalid regionHint. After each tick, the two gauges together equal decdn_staker_set_active_count.
  • The registry follows RegionUpdated. A region change now reaches the region map on the next tick instead of waiting for the 15-minute re-enumeration. This also speeds up the ADR 030 latency penalty, which reads the same map.
  • Dashboard: in the "Registry and staking" row:
    • a Geomap panel (country lookup, max by (node_region));
    • a per-region table, which also lists codes Grafana's country gazetteer cannot place (user-assigned codes, XK, SS);
    • an unknown-region stat panel.
  • Docs: adr/appendix-observability.md gets both registry rows, and names this family as the one exception to the zero-export rule. There is also a CHANGELOG entry under ### Added.

Design notes

  • Label is node_region, not region. Every dashboard selector already filters on a scrape-side region target label. With honor_labels: false, a clashing metric label would be renamed to exported_region.
  • max across nodes, not sum. Every node reports the same network view, so summing would multiply the counts by fleet size.
  • Stale series are removed explicitly. Family cannot list its children, so Metrics tracks the published regions. It sets live children before it removes stale ones, all under one lock.

Test plan

  • cargo nextest run -p decdn-node: 1153 passed. New tests:
    • tick_publishes_active_nodes_by_region
    • region_updated_moves_the_node_on_the_next_tick
    • resync_republishes_the_region_split
    • staker_set_active_by_region_replaces_the_previous_map
    • the monitoring_selectors_are_exported gate
  • cargo clippy --workspace --all-targets -D warnings, rustdoc -D warnings, cargo fmt, and pre-commit.
  • g_node_04_blacklist_compliance anvil e2e test (exercises updateRegion): 5/5 passed.
  • Import monitoring/dashboard-chain.json into Grafana and check the geomap renders against nodes running this build.

🤖 Generated with Claude Code

…shboard

Every node's CapacityBond registry already holds the whole network's
NodeId -> regionHint map, but no metric carried a region, so nothing
could be put on a map.

- New gauge decdn_staker_set_active_by_region{node_region}: active
  stakers per region, recomputed at bootstrap, at the end of every clean
  watcher tick and after each resync. Values pass Region::parse, so the
  ISO allowlist bounds cardinality. A region with no active node loses
  its series. The label is node_region because every dashboard already
  filters on a scrape-side region label.
- New gauge decdn_staker_set_active_unknown_region: active stakers with
  an empty or invalid regionHint.
- The registry follows RegionUpdated, so a region change reaches the
  region map (and the ADR 030 latency penalty) on the next tick instead
  of the 15-minute re-enumeration.
- dashboard-chain.json gains a Geomap panel (country lookup,
  max by node_region), a per-region table that also lists codes the map
  cannot place (user-assigned, XK, SS), and an unknown-region stat.
- appendix-observability documents both gauges and names the family as
  the one exception to the zero-export rule.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI lite review requested due to automatic review settings September 19, 2026 00:14
@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

RegionUpdated currently stores raw regionHint strings without normalization, which can break downstream region equality semantics and should be normalized via Region::parse before insertion.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds chain-dashboard visibility for operator-declared regions by exporting a per-region active-staker metric from each node’s CapacityBond registry view, and visualizing it as a world map + table + “unknown region” stat on the decdn-chain Grafana dashboard.

Changes:

  • Export decdn_staker_set_active_by_region{node_region} and decdn_staker_set_active_unknown_region from the node metrics endpoint, updated on bootstrap, watcher ticks, and resync.
  • Track RegionUpdated in the CapacityBond registry projection and publish updated per-region counts on each clean tick and after resync.
  • Add new “Active nodes by country/region” panels to monitoring/dashboard-chain.json and document the metric family + exception semantics in observability docs and the changelog.
File Description
monitoring/​dashboard-chain.json Adds geomap/table/stat panels driven by the new per-region active-staker gauges.
crates/​node/​src/​metrics.rs Introduces the labelled gauge family + unknown-region gauge, plus publishing/removal logic and tests.
crates/​node/​src/​dht/​capacity_bond_registry.rs Subscribes to RegionUpdated and publishes per-region active-node counts at tick/resync/bootstrap.
CHANGELOG.md Documents the new metrics and dashboard panels.
adr/​appendix-observability.md Documents the new metrics and clarifies the “no series at zero” exception for the region map family.

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

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 82.97% (was 82.94%, ▲ +0.03%) — 80250/96716 lines

File Coverage Lines Δ
crates/node/src/dht/capacity_bond_registry.rs 84.22% 854/1014 ▲ +2.94%
crates/node/src/metrics.rs 95.21% 974/1023 ▼ 0.19%
History
Commit Total Δ vs base
790f0e8 82.97% ▲ +0.02%
3468595 (HEAD) 82.97% ▲ +0.03%

The contract only length-checks regionHint, and every write path into
the region map (NodeRegistered, the getRegisteredNodes enumeration, and
RegionUpdated) stored the raw string. The ADR 030 latency penalty
compares that string against the node's own normalized identity.region,
so a peer that registered " de " never matched "DE".

All three paths now store the Region::parse form and treat an empty or
invalid hint as absence.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@thiras
thiras merged commit 4a391d7 into main Sep 19, 2026
25 checks passed
@thiras
thiras deleted the feat/network-region-map branch September 19, 2026 00:39
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