Skip to content

Commit f84de88

Browse files
authored
Merge pull request #944 from onflow/mpeter/add-block-processing-time-metric
Add a metric to count the EVM block processing time during event ingestion
2 parents 8d3654a + e134ee5 commit f84de88

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

metrics/collector.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,20 @@ var gasEstimationIterations = prometheus.NewGauge(prometheus.GaugeOpts{
6666
Help: "Number of iterations taken to estimate the gas of a EVM call/tx",
6767
})
6868

69+
// Time difference between block proposal time and block indexing time
6970
var blockIngestionTime = prometheus.NewHistogram(prometheus.HistogramOpts{
7071
Name: prefixedName("block_ingestion_time_seconds"),
71-
Help: "Time taken to fully ingest an EVM block in the local state index",
72+
Help: "Latency from EVM block proposal time to indexing completion (wall-clock duration)",
7273
Buckets: []float64{.5, 1, 2.5, 5, 10, 15, 20, 30, 45},
7374
})
7475

76+
// EVM block processing time during event ingestion, including transaction replay
77+
// and state validation
78+
var blockProcessTime = prometheus.NewSummary(prometheus.SummaryOpts{
79+
Name: prefixedName("block_process_time_seconds"),
80+
Help: "Processing time to fully index an EVM block in the local state index",
81+
})
82+
7583
var requestRateLimitedCounters = prometheus.NewCounterVec(prometheus.CounterOpts{
7684
Name: prefixedName("request_rate_limited"),
7785
Help: "Total number of rate limits by JSON-RPC method",
@@ -105,6 +113,7 @@ var metrics = []prometheus.Collector{
105113
availableSigningKeys,
106114
gasEstimationIterations,
107115
blockIngestionTime,
116+
blockProcessTime,
108117
requestRateLimitedCounters,
109118
transactionsDroppedCounter,
110119
rateLimitedTransactionsCounter,
@@ -123,6 +132,7 @@ type Collector interface {
123132
AvailableSigningKeys(count int)
124133
GasEstimationIterations(count int)
125134
BlockIngestionTime(blockCreation time.Time)
135+
BlockProcessTime(start time.Time)
126136
RequestRateLimited(method string)
127137
TransactionsDropped(count int)
128138
TransactionRateLimited()
@@ -147,6 +157,7 @@ type DefaultCollector struct {
147157
availableSigningkeys prometheus.Gauge
148158
gasEstimationIterations prometheus.Gauge
149159
blockIngestionTime prometheus.Histogram
160+
blockProcessTime prometheus.Summary
150161
requestRateLimitedCounters *prometheus.CounterVec
151162
transactionsDroppedCounter prometheus.Counter
152163
rateLimitedTransactionsCounter prometheus.Counter
@@ -173,6 +184,7 @@ func NewCollector(logger zerolog.Logger) Collector {
173184
availableSigningkeys: availableSigningKeys,
174185
gasEstimationIterations: gasEstimationIterations,
175186
blockIngestionTime: blockIngestionTime,
187+
blockProcessTime: blockProcessTime,
176188
requestRateLimitedCounters: requestRateLimitedCounters,
177189
transactionsDroppedCounter: transactionsDroppedCounter,
178190
rateLimitedTransactionsCounter: rateLimitedTransactionsCounter,
@@ -243,6 +255,10 @@ func (c *DefaultCollector) BlockIngestionTime(blockCreation time.Time) {
243255
Observe(time.Since(blockCreation).Seconds())
244256
}
245257

258+
func (c *DefaultCollector) BlockProcessTime(start time.Time) {
259+
c.blockProcessTime.Observe(time.Since(start).Seconds())
260+
}
261+
246262
func (c *DefaultCollector) RequestRateLimited(method string) {
247263
c.requestRateLimitedCounters.With(
248264
prometheus.Labels{

metrics/nop.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func (c *nopCollector) OperatorBalance(balance uint64) {}
2222
func (c *nopCollector) AvailableSigningKeys(count int) {}
2323
func (c *nopCollector) GasEstimationIterations(count int) {}
2424
func (c *nopCollector) BlockIngestionTime(blockCreation time.Time) {}
25+
func (c *nopCollector) BlockProcessTime(start time.Time) {}
2526
func (c *nopCollector) RequestRateLimited(method string) {}
2627
func (c *nopCollector) TransactionsDropped(count int) {}
2728
func (c *nopCollector) TransactionRateLimited() {}

services/ingestion/engine.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,14 @@ func (e *Engine) processEvents(events *models.CadenceEvents) error {
184184
Int("cadence-event-length", events.Length()).
185185
Msg("received new cadence evm events")
186186

187+
start := time.Now()
187188
err := e.withBatch(
188189
func(batch *pebbleDB.Batch) error {
189190
return e.indexEvents(events, batch)
190191
},
191192
)
193+
e.collector.BlockProcessTime(start)
194+
192195
if err != nil {
193196
return fmt.Errorf("failed to index events for cadence block %d: %w", events.CadenceHeight(), err)
194197
}

0 commit comments

Comments
 (0)