feat(observability): CountDIDs + DID/pending/peer counts in status + /stats (#103)#104
Merged
Merged
Conversation
…/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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
statusCLI 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 (sqliteCOUNT(DISTINCT suffix); bbolt counts distinct prefixes in the sorteddid_fwdbucket). Reorg-coupled.p2p.Client.PeerCount() int.ion-node statusnow printsdidsandpendingRetryable.startstatus log addspeers,dids,pendingRetryable.GET /stats(agent-native parity with the CLI) →{dids, pendingRetryable, committedHeight, processedHeight, fullyResolved}. Registered only when aStatsProvideris configured (servewires the store viaHandler.WithStats).How to use
Caveat
didsreflects only locally-resolved content, so it can undercount whilependingRetryable > 0(anchored content not yet fetched from IPFS).fullyResolved/pendingRetryablesignal completeness.Tests
TestCountDIDs— distinct suffixes (not rows: a DID with several ops counts once), reorg-coupled, both engines.TestStatsEndpoint—/statsreports counts; returns 404 without a provider.go test -race ./...green (26 packages).Post-Deploy Monitoring & Validation
peers(should track--outbound),pendingRetryable(should trend to 0 when IPFS is healthy), anddids(monotonic up as sync progresses). ScrapeGET /statsfrom monitoring.peersnear 0 (sync stall), orpendingRetryablegrowing without bound (IPFS unreachable).Closes #103
🤖 Generated with Claude Code