Skip to content

feat(metrics): track blocks synchronized by source#3259

Merged
julienrbrt merged 5 commits intomainfrom
claude/metric
Apr 16, 2026
Merged

feat(metrics): track blocks synchronized by source#3259
julienrbrt merged 5 commits intomainfrom
claude/metric

Conversation

@auricom
Copy link
Copy Markdown
Contributor

@auricom auricom commented Apr 16, 2026

Summary

  • Add sequencer_blocks_synchronized_total Prometheus counter with source label (DA/P2P)
  • Counter increments each time a block is synced in the syncer
  • Resets on process restart

Test plan

  • Run node and verify sequencer_blocks_synchronized_total{source="DA"} and sequencer_blocks_synchronized_total{source="P2P"} appear in /metrics
  • Confirm counters increment as blocks are synced from each source

🤖 Generated with Claude Code

auricom and others added 2 commits April 16, 2026 11:50
Add sequencer_blocks_synchronized_total counter with source label (DA/P2P) to track how many blocks were synced from each source.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 16, 2026

Claude finished @auricom's task in 1m 31s —— View job


Code Review

  • Gather context and read changed files
  • Review code quality & architecture
  • Review error handling & resilience
  • Review testing & reliability
  • Post final review

Overall this is a clean, well-scoped addition that follows existing codebase patterns. A few issues worth addressing before merging:


Issues

1. EventSource value case change is a silent breaking change for log consumers

SourceDA and SourceP2P were changed from "DA" / "P2P" to lowercase "da" / "p2p". These values appear in structured log output across the syncer:

// block/internal/syncing/syncer.go:548, 561, 671, 717
Str("source", string(event.Source))

Any dashboards, alerts, or log parsers that filter on source="DA" or source="P2P" will silently break. This should be called out explicitly in the CHANGELOG under a Breaking Changes section. The motivation for lowercasing is valid (Prometheus label convention), but the impact is broader than Prometheus alone.

2. CHANGELOG and PR description reference wrong label values

The CHANGELOG entry and the PR test plan both reference source="DA" and source="P2P", but the actual registered values are lowercase "da", "p2p", "raft". Fix this →

3. Stale field comment on BlocksSynchronized

// block/internal/common/metrics.go:72
BlocksSynchronized map[EventSource]metrics.Counter // Blocks synchronized by source (P2P or DA)

SourceRaft is now a valid third source. The comment should read // Blocks synchronized by source (DA, P2P, or Raft). Fix this →

4. No test coverage for the new counter increment

Codecov reports 0% patch coverage on syncer.go. The two new lines (787–789) increment BlocksSynchronized after a successful commit, but no test verifies that the counter actually fires. The NopMetrics are already used in syncer tests — it would be straightforward to add an assertion that BlocksSynchronized[SourceDA] increments after a successful TrySyncNextBlock call.


Positives

  • Correct placement — the counter increment is after batch.Commit(), so only successfully committed blocks are counted. Blocks that fail validation, fail to apply, or fail to commit are not counted.
  • Defensive map lookup — the if counter, ok := s.metrics.BlocksSynchronized[event.Source]; ok guard prevents a nil map panic if an unexpected source appears.
  • SourceRaft fix — the empty string in RecoverFromRaft was a latent bug; tagging it as SourceRaft is the right fix and ensures Raft-recovered blocks are tracked.
  • Consistent with existing patternsConstLabels-per-source approach matches DASubmitterFailures and DASubmitterLastFailure.
  • NopMetrics properly populated — no-op counters are initialized for all sources, preventing nil-pointer panics in test contexts.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 16, 2026

The latest Buf updates on your PR. Results from workflow CI / buf-check (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped✅ passed✅ passedApr 16, 2026, 10:02 AM

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 16, 2026

Warning

Rate limit exceeded

@auricom has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 51 minutes and 20 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 51 minutes and 20 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e0fa38c4-45b7-48ed-8ba9-d1f962c40a79

📥 Commits

Reviewing files that changed from the base of the PR and between 2865d6d and 8c43e66.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • block/internal/common/event.go
  • block/internal/common/metrics.go
  • block/internal/syncing/syncer.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/metric

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- Use nil-safe map lookup to avoid panic when RecoverFromRaft calls
  trySyncNextBlockWithState with Source: "" (not in the map)
- Move counter increment to after batch.Commit() so only successfully
  committed blocks are counted

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.32%. Comparing base (2865d6d) to head (8c43e66).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3259      +/-   ##
==========================================
- Coverage   62.33%   62.32%   -0.01%     
==========================================
  Files         122      122              
  Lines       12873    12877       +4     
==========================================
+ Hits         8024     8026       +2     
- Misses       3968     3970       +2     
  Partials      881      881              
Flag Coverage Δ
combined 62.32% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Lowercase EventSource constant values (da/p2p/raft) for Prometheus label convention
- Add SourceRaft for RecoverFromRaft path so blocks are counted
- Add AllEventSources() helper to avoid duplicating source list in metrics.go
- Use AllEventSources() in both PrometheusMetrics and NopMetrics init loops

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@julienrbrt julienrbrt merged commit 3cfc1ad into main Apr 16, 2026
63 of 72 checks passed
@julienrbrt julienrbrt deleted the claude/metric branch April 16, 2026 12:04
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.

3 participants