Skip to content

feat(observability): CountDIDs + DID/pending/peer counts in status + /stats (#103)#104

Merged
LiranCohen merged 1 commit into
mainfrom
feat/observability-did-count
Jun 8, 2026
Merged

feat(observability): CountDIDs + DID/pending/peer counts in status + /stats (#103)#104
LiranCohen merged 1 commit into
mainfrom
feat/observability-did-count

Conversation

@LiranCohen

Copy link
Copy Markdown
Contributor

Summary

Closes audit finding #14, and adds the directly-requested capability: how many DIDs has this node indexed? The node exposed no counts — no DID total, the status CLI omitted pending and peer counts, and there was no machine-readable stats endpoint. The two most common silent degradations (IPFS down → growing pending backlog; zero peers → sync stall) had no easy signal.

What's added

  • store.CountDIDs() (int, error) — distinct projected DID suffixes (sqlite COUNT(DISTINCT suffix); bbolt counts distinct prefixes in the sorted did_fwd bucket). Reorg-coupled.
  • p2p.Client.PeerCount() int.
  • ion-node status now prints dids and pendingRetryable.
  • The live start status log adds peers, dids, pendingRetryable.
  • GET /stats (agent-native parity with the CLI) → {dids, pendingRetryable, committedHeight, processedHeight, fullyResolved}. Registered only when a StatsProvider is configured (serve wires the store via Handler.WithStats).

How to use

ion-node status                          # network=… committedHeight=… indexedAnchors=… dids=… pendingRetryable=… datadir=…
curl -s http://127.0.0.1:8080/stats      # {"dids":…,"pendingRetryable":…,"fullyResolved":…,…}

Caveat

dids reflects only locally-resolved content, so it can undercount while pendingRetryable > 0 (anchored content not yet fetched from IPFS). fullyResolved/pendingRetryable signal completeness.

Tests

  • TestCountDIDs — distinct suffixes (not rows: a DID with several ops counts once), reorg-coupled, both engines.
  • TestStatsEndpoint/stats reports counts; returns 404 without a provider.

go test -race ./... green (26 packages).

Post-Deploy Monitoring & Validation

  • What to watch: peers (should track --outbound), pendingRetryable (should trend to 0 when IPFS is healthy), and dids (monotonic up as sync progresses). Scrape GET /stats from monitoring.
  • Failure signal / trigger: peers near 0 (sync stall), or pendingRetryable growing without bound (IPFS unreachable).
  • Window/owner: ongoing operational dashboards.

Closes #103

🤖 Generated with Claude Code

…/stats (#103)

Finding #14, and the directly-requested "how many DIDs?" capability. The node
exposed no counts; the two most common silent degradations (IPFS down → growing
pending; zero peers → sync stall) had no easy signal.

- internal/store: CountDIDs() (int, error) added to the Store interface and both
  engines — distinct projected DID suffixes (sqlite COUNT(DISTINCT suffix); bbolt
  counts distinct prefixes in the sorted did_fwd bucket). Reorg-coupled.
- internal/p2p: Client.PeerCount() int.
- cmd/ion-node: `status` prints dids + pendingRetryable; the live `start` status log
  adds peers, dids, pendingRetryable.
- internal/api: GET /stats (agent-native parity with status) returns dids,
  pendingRetryable, committedHeight, processedHeight, fullyResolved — registered only
  when a StatsProvider is configured; `serve` wires the store via Handler.WithStats.

dids reflects only locally-resolved content, so it can undercount while
pendingRetryable > 0 (anchored content not yet fetched) — surfaced via
fullyResolved/pendingRetryable.

Tests: TestCountDIDs (distinct suffixes, not rows; reorg-coupled; both engines),
TestStatsEndpoint (/stats reports counts; 404 without a provider). go test -race
./... green.

Co-authored-by: Liran Cohen <liranlasvegas@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@LiranCohen LiranCohen merged commit 3c8a8da into main Jun 8, 2026
1 check passed
@LiranCohen LiranCohen deleted the feat/observability-did-count branch June 8, 2026 03:10
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.

Observability: no DID count or pending/peer visibility; add CountDIDs, enrich status, add /stats

1 participant