From 7f8a5d520f3c68033c857827b6b5bee67ff79f44 Mon Sep 17 00:00:00 2001 From: Peter Argue <89119817+peterargue@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:19:04 -0700 Subject: [PATCH] Add metric for indexed cadence block height --- metrics/collector.go | 13 +++++++++++++ metrics/nop.go | 1 + services/ingestion/engine.go | 1 + 3 files changed, 15 insertions(+) diff --git a/metrics/collector.go b/metrics/collector.go index 1b25b7c04..41e087c31 100644 --- a/metrics/collector.go +++ b/metrics/collector.go @@ -13,6 +13,7 @@ type Collector interface { ApiErrorOccurred() TraceDownloadFailed() ServerPanicked(reason string) + CadenceHeightIndexed(height uint64) EVMHeightIndexed(height uint64) EVMAccountInteraction(address string) MeasureRequestDuration(start time.Time, method string) @@ -26,6 +27,7 @@ type DefaultCollector struct { apiErrorsCounter prometheus.Counter traceDownloadErrorCounter prometheus.Counter serverPanicsCounters *prometheus.CounterVec + cadenceBlockHeight prometheus.Gauge evmBlockHeight prometheus.Gauge operatorBalance prometheus.Gauge evmAccountCallCounters *prometheus.CounterVec @@ -53,6 +55,11 @@ func NewCollector(logger zerolog.Logger) Collector { Help: "Flow balance of the EVM gateway operator wallet", }) + cadenceBlockHeight := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: prefixedName("cadence_block_height"), + Help: "Current Cadence block height", + }) + evmBlockHeight := prometheus.NewGauge(prometheus.GaugeOpts{ Name: prefixedName("evm_block_height"), Help: "Current EVM block height", @@ -74,6 +81,7 @@ func NewCollector(logger zerolog.Logger) Collector { apiErrors, traceDownloadErrorCounter, serverPanicsCounters, + cadenceBlockHeight, evmBlockHeight, operatorBalance, evmAccountCallCounters, @@ -88,6 +96,7 @@ func NewCollector(logger zerolog.Logger) Collector { apiErrorsCounter: apiErrors, traceDownloadErrorCounter: traceDownloadErrorCounter, serverPanicsCounters: serverPanicsCounters, + cadenceBlockHeight: cadenceBlockHeight, evmBlockHeight: evmBlockHeight, evmAccountCallCounters: evmAccountCallCounters, requestDurations: requestDurations, @@ -118,6 +127,10 @@ func (c *DefaultCollector) ServerPanicked(reason string) { c.serverPanicsCounters.With(prometheus.Labels{"reason": reason}).Inc() } +func (c *DefaultCollector) CadenceHeightIndexed(height uint64) { + c.cadenceBlockHeight.Set(float64(height)) +} + func (c *DefaultCollector) EVMHeightIndexed(height uint64) { c.evmBlockHeight.Set(float64(height)) } diff --git a/metrics/nop.go b/metrics/nop.go index f44d5cc97..7ed77e4f4 100644 --- a/metrics/nop.go +++ b/metrics/nop.go @@ -15,6 +15,7 @@ var NopCollector = &nopCollector{} func (c *nopCollector) ApiErrorOccurred() {} func (c *nopCollector) TraceDownloadFailed() {} func (c *nopCollector) ServerPanicked(string) {} +func (c *nopCollector) CadenceHeightIndexed(uint64) {} func (c *nopCollector) EVMHeightIndexed(uint64) {} func (c *nopCollector) EVMAccountInteraction(string) {} func (c *nopCollector) MeasureRequestDuration(time.Time, string) {} diff --git a/services/ingestion/engine.go b/services/ingestion/engine.go index d795687f3..97728418a 100644 --- a/services/ingestion/engine.go +++ b/services/ingestion/engine.go @@ -206,6 +206,7 @@ func (e *Engine) processEvents(events *models.CadenceEvents) error { } e.collector.EVMHeightIndexed(events.Block().Height) + e.collector.CadenceHeightIndexed(events.CadenceHeight()) return nil }