Skip to content

Return diagnostics snapshot on first Stats and refactor diagnostics collection#253

Closed
mateeullahmalik wants to merge 1 commit intomasterfrom
codex/investigate-p2p_stats-and-supernode-issues
Closed

Return diagnostics snapshot on first Stats and refactor diagnostics collection#253
mateeullahmalik wants to merge 1 commit intomasterfrom
codex/investigate-p2p_stats-and-supernode-issues

Conversation

@mateeullahmalik
Copy link
Collaborator

Motivation

  • Initial Stats calls could return an empty/zeroed diagnostics snapshot because the expensive diagnostics refresh was only scheduled async, causing metrics to be missing on first call.
  • Ensure the first Stats invocation can synchronously obtain and return a populated diagnostics snapshot so status consumers get meaningful data immediately.
  • Reuse the same diagnostics collection logic for both sync and async refresh paths to avoid duplication and racey cache propagation.
  • Improve observability by logging failures and slow refreshes for initial and background refreshes.

Description

  • Stats now calls refreshDiagnosticsSync and uses the returned *StatsSnapshot when the cache is empty instead of relying on cache propagation.
  • Introduced collectDiagnostics(ctx,p,prev) (replaces refreshDiagnostics) which returns (*StatsSnapshot, error) and performs the heavy snapshot collection without mutating global state directly.
  • refreshDiagnosticsSync and maybeRefreshDiagnostics now both call collectDiagnostics and, when a snapshot is returned, call m.setSnapshot(next) and m.markFresh(); both paths remain deduped by refreshInFlight.
  • Added warning logs for initial refresh failures and for refreshes slower than p2pStatsSlowRefreshThreshold to aid debugging.

Testing

  • No automated tests were run.
  • Changes were applied to p2p/p2p_stats.go and committed.

Codex Task

@roomote-v0
Copy link

roomote-v0 bot commented Dec 31, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The changes correctly address the motivation of ensuring the first Stats call returns a populated diagnostics snapshot. The refactoring cleanly separates collection logic from caching, and the concurrency handling with refreshInFlight is sound.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant