diff --git a/CHANGELOG.md b/CHANGELOG.md index 99026c6e04..502b9bb1e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changes +- Add `sequencer_blocks_synchronized_total` Prometheus counter metric tracking blocks synced by source (DA/P2P) [#3259](https://github.com/evstack/ev-node/pull/3259) - Make it easier to override `DefaultMaxBlobSize` by ldflags [#3235](https://github.com/evstack/ev-node/pull/3235) - Add solo sequencer (simple in memory single sequencer without force inclusion) [#3235](https://github.com/evstack/ev-node/pull/3235) - Improve reaper to sustain txs burst better [#3236](https://github.com/evstack/ev-node/pull/3236) diff --git a/block/internal/common/event.go b/block/internal/common/event.go index 3cc18f4641..af7e267603 100644 --- a/block/internal/common/event.go +++ b/block/internal/common/event.go @@ -11,11 +11,18 @@ type EventSource string const ( // SourceDA indicates the event came from the DA layer - SourceDA EventSource = "DA" + SourceDA EventSource = "da" // SourceP2P indicates the event came from P2P network - SourceP2P EventSource = "P2P" + SourceP2P EventSource = "p2p" + // SourceRaft indicates the event came from Raft consensus recovery + SourceRaft EventSource = "raft" ) +// AllEventSources returns all possible event sources. +func AllEventSources() []EventSource { + return []EventSource{SourceDA, SourceP2P, SourceRaft} +} + // DAHeightEvent represents a DA event for caching type DAHeightEvent struct { Header *types.SignedHeader diff --git a/block/internal/common/metrics.go b/block/internal/common/metrics.go index cb5a1aa972..179157eb7e 100644 --- a/block/internal/common/metrics.go +++ b/block/internal/common/metrics.go @@ -67,6 +67,9 @@ type Metrics struct { // Forced inclusion metrics ForcedInclusionTxsInGracePeriod metrics.Gauge // Number of forced inclusion txs currently in grace period ForcedInclusionTxsMalicious metrics.Counter // Total number of forced inclusion txs marked as malicious + + // Syncer metrics + BlocksSynchronized map[EventSource]metrics.Counter // Blocks synchronized by source (P2P or DA) } // PrometheusMetrics returns Metrics built using Prometheus client library @@ -80,6 +83,7 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { OperationDuration: make(map[string]metrics.Histogram), DASubmitterFailures: make(map[DASubmitterFailureReason]metrics.Counter), DASubmitterLastFailure: make(map[DASubmitterFailureReason]metrics.Gauge), + BlocksSynchronized: make(map[EventSource]metrics.Counter), } // Original metrics @@ -223,6 +227,19 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { }, labels).With(labelsAndValues...) } + // Syncer metrics + for _, source := range AllEventSources() { + m.BlocksSynchronized[source] = prometheus.NewCounterFrom(stdprometheus.CounterOpts{ + Namespace: namespace, + Subsystem: MetricsSubsystem, + Name: "blocks_synchronized_total", + Help: "Total number of blocks synchronized by source", + ConstLabels: map[string]string{ + "source": string(source), + }, + }, labels).With(labelsAndValues...) + } + return m } @@ -251,6 +268,9 @@ func NopMetrics() *Metrics { // Forced inclusion metrics ForcedInclusionTxsInGracePeriod: discard.NewGauge(), ForcedInclusionTxsMalicious: discard.NewCounter(), + + // Syncer metrics + BlocksSynchronized: make(map[EventSource]metrics.Counter), } // Initialize maps with no-op metrics @@ -265,5 +285,10 @@ func NopMetrics() *Metrics { m.DASubmitterLastFailure[reason] = discard.NewGauge() } + // Initialize syncer no-op metrics + for _, source := range AllEventSources() { + m.BlocksSynchronized[source] = discard.NewCounter() + } + return m } diff --git a/block/internal/syncing/syncer.go b/block/internal/syncing/syncer.go index 4d2cbb4afe..9b0a965c5f 100644 --- a/block/internal/syncing/syncer.go +++ b/block/internal/syncing/syncer.go @@ -784,6 +784,9 @@ func (s *Syncer) trySyncNextBlockWithState(ctx context.Context, event *common.DA // Update in-memory state after successful commit s.SetLastState(newState) s.metrics.Height.Set(float64(newState.LastBlockHeight)) + if counter, ok := s.metrics.BlocksSynchronized[event.Source]; ok { + counter.Add(1) + } // Mark as seen s.cache.SetHeaderSeen(headerHash, header.Height()) @@ -1226,7 +1229,7 @@ func (s *Syncer) RecoverFromRaft(ctx context.Context, raftState *raft.RaftBlockS event := &common.DAHeightEvent{ Header: &header, Data: &data, - Source: "", + Source: common.SourceRaft, } err := s.trySyncNextBlockWithState(ctx, event, currentState) if err != nil {