Skip to content

Commit 3cfc1ad

Browse files
auricomclaude
andauthored
feat(metrics): track blocks synchronized by source (#3259)
* feat(metrics): track blocks synchronized by source 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> * docs(changelog): add entry for blocks_synchronized_total metric Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * docs(changelog): fix PR number for blocks_synchronized_total metric Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(metrics): guard BlocksSynchronized lookup and move after commit - 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> * fix(metrics): address code review feedback - 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> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2865d6d commit 3cfc1ad

4 files changed

Lines changed: 39 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changes
1313

14+
- Add `sequencer_blocks_synchronized_total` Prometheus counter metric tracking blocks synced by source (DA/P2P) [#3259](https://github.com/evstack/ev-node/pull/3259)
1415
- Make it easier to override `DefaultMaxBlobSize` by ldflags [#3235](https://github.com/evstack/ev-node/pull/3235)
1516
- Add solo sequencer (simple in memory single sequencer without force inclusion) [#3235](https://github.com/evstack/ev-node/pull/3235)
1617
- Improve reaper to sustain txs burst better [#3236](https://github.com/evstack/ev-node/pull/3236)

block/internal/common/event.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ type EventSource string
1111

1212
const (
1313
// SourceDA indicates the event came from the DA layer
14-
SourceDA EventSource = "DA"
14+
SourceDA EventSource = "da"
1515
// SourceP2P indicates the event came from P2P network
16-
SourceP2P EventSource = "P2P"
16+
SourceP2P EventSource = "p2p"
17+
// SourceRaft indicates the event came from Raft consensus recovery
18+
SourceRaft EventSource = "raft"
1719
)
1820

21+
// AllEventSources returns all possible event sources.
22+
func AllEventSources() []EventSource {
23+
return []EventSource{SourceDA, SourceP2P, SourceRaft}
24+
}
25+
1926
// DAHeightEvent represents a DA event for caching
2027
type DAHeightEvent struct {
2128
Header *types.SignedHeader

block/internal/common/metrics.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ type Metrics struct {
6767
// Forced inclusion metrics
6868
ForcedInclusionTxsInGracePeriod metrics.Gauge // Number of forced inclusion txs currently in grace period
6969
ForcedInclusionTxsMalicious metrics.Counter // Total number of forced inclusion txs marked as malicious
70+
71+
// Syncer metrics
72+
BlocksSynchronized map[EventSource]metrics.Counter // Blocks synchronized by source (P2P or DA)
7073
}
7174

7275
// PrometheusMetrics returns Metrics built using Prometheus client library
@@ -80,6 +83,7 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
8083
OperationDuration: make(map[string]metrics.Histogram),
8184
DASubmitterFailures: make(map[DASubmitterFailureReason]metrics.Counter),
8285
DASubmitterLastFailure: make(map[DASubmitterFailureReason]metrics.Gauge),
86+
BlocksSynchronized: make(map[EventSource]metrics.Counter),
8387
}
8488

8589
// Original metrics
@@ -223,6 +227,19 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
223227
}, labels).With(labelsAndValues...)
224228
}
225229

230+
// Syncer metrics
231+
for _, source := range AllEventSources() {
232+
m.BlocksSynchronized[source] = prometheus.NewCounterFrom(stdprometheus.CounterOpts{
233+
Namespace: namespace,
234+
Subsystem: MetricsSubsystem,
235+
Name: "blocks_synchronized_total",
236+
Help: "Total number of blocks synchronized by source",
237+
ConstLabels: map[string]string{
238+
"source": string(source),
239+
},
240+
}, labels).With(labelsAndValues...)
241+
}
242+
226243
return m
227244
}
228245

@@ -251,6 +268,9 @@ func NopMetrics() *Metrics {
251268
// Forced inclusion metrics
252269
ForcedInclusionTxsInGracePeriod: discard.NewGauge(),
253270
ForcedInclusionTxsMalicious: discard.NewCounter(),
271+
272+
// Syncer metrics
273+
BlocksSynchronized: make(map[EventSource]metrics.Counter),
254274
}
255275

256276
// Initialize maps with no-op metrics
@@ -265,5 +285,10 @@ func NopMetrics() *Metrics {
265285
m.DASubmitterLastFailure[reason] = discard.NewGauge()
266286
}
267287

288+
// Initialize syncer no-op metrics
289+
for _, source := range AllEventSources() {
290+
m.BlocksSynchronized[source] = discard.NewCounter()
291+
}
292+
268293
return m
269294
}

block/internal/syncing/syncer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,9 @@ func (s *Syncer) trySyncNextBlockWithState(ctx context.Context, event *common.DA
784784
// Update in-memory state after successful commit
785785
s.SetLastState(newState)
786786
s.metrics.Height.Set(float64(newState.LastBlockHeight))
787+
if counter, ok := s.metrics.BlocksSynchronized[event.Source]; ok {
788+
counter.Add(1)
789+
}
787790

788791
// Mark as seen
789792
s.cache.SetHeaderSeen(headerHash, header.Height())
@@ -1226,7 +1229,7 @@ func (s *Syncer) RecoverFromRaft(ctx context.Context, raftState *raft.RaftBlockS
12261229
event := &common.DAHeightEvent{
12271230
Header: &header,
12281231
Data: &data,
1229-
Source: "",
1232+
Source: common.SourceRaft,
12301233
}
12311234
err := s.trySyncNextBlockWithState(ctx, event, currentState)
12321235
if err != nil {

0 commit comments

Comments
 (0)