Skip to content

Commit d5b8984

Browse files
authored
Merge pull request #571 from onflow/petera/570-add-cadence-height-metric
Add metric for indexed cadence block height
2 parents 888c69d + 7f8a5d5 commit d5b8984

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

metrics/collector.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type Collector interface {
1313
ApiErrorOccurred()
1414
TraceDownloadFailed()
1515
ServerPanicked(reason string)
16+
CadenceHeightIndexed(height uint64)
1617
EVMHeightIndexed(height uint64)
1718
EVMAccountInteraction(address string)
1819
MeasureRequestDuration(start time.Time, method string)
@@ -26,6 +27,7 @@ type DefaultCollector struct {
2627
apiErrorsCounter prometheus.Counter
2728
traceDownloadErrorCounter prometheus.Counter
2829
serverPanicsCounters *prometheus.CounterVec
30+
cadenceBlockHeight prometheus.Gauge
2931
evmBlockHeight prometheus.Gauge
3032
operatorBalance prometheus.Gauge
3133
evmAccountCallCounters *prometheus.CounterVec
@@ -53,6 +55,11 @@ func NewCollector(logger zerolog.Logger) Collector {
5355
Help: "Flow balance of the EVM gateway operator wallet",
5456
})
5557

58+
cadenceBlockHeight := prometheus.NewGauge(prometheus.GaugeOpts{
59+
Name: prefixedName("cadence_block_height"),
60+
Help: "Current Cadence block height",
61+
})
62+
5663
evmBlockHeight := prometheus.NewGauge(prometheus.GaugeOpts{
5764
Name: prefixedName("evm_block_height"),
5865
Help: "Current EVM block height",
@@ -74,6 +81,7 @@ func NewCollector(logger zerolog.Logger) Collector {
7481
apiErrors,
7582
traceDownloadErrorCounter,
7683
serverPanicsCounters,
84+
cadenceBlockHeight,
7785
evmBlockHeight,
7886
operatorBalance,
7987
evmAccountCallCounters,
@@ -88,6 +96,7 @@ func NewCollector(logger zerolog.Logger) Collector {
8896
apiErrorsCounter: apiErrors,
8997
traceDownloadErrorCounter: traceDownloadErrorCounter,
9098
serverPanicsCounters: serverPanicsCounters,
99+
cadenceBlockHeight: cadenceBlockHeight,
91100
evmBlockHeight: evmBlockHeight,
92101
evmAccountCallCounters: evmAccountCallCounters,
93102
requestDurations: requestDurations,
@@ -118,6 +127,10 @@ func (c *DefaultCollector) ServerPanicked(reason string) {
118127
c.serverPanicsCounters.With(prometheus.Labels{"reason": reason}).Inc()
119128
}
120129

130+
func (c *DefaultCollector) CadenceHeightIndexed(height uint64) {
131+
c.cadenceBlockHeight.Set(float64(height))
132+
}
133+
121134
func (c *DefaultCollector) EVMHeightIndexed(height uint64) {
122135
c.evmBlockHeight.Set(float64(height))
123136
}

metrics/nop.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var NopCollector = &nopCollector{}
1515
func (c *nopCollector) ApiErrorOccurred() {}
1616
func (c *nopCollector) TraceDownloadFailed() {}
1717
func (c *nopCollector) ServerPanicked(string) {}
18+
func (c *nopCollector) CadenceHeightIndexed(uint64) {}
1819
func (c *nopCollector) EVMHeightIndexed(uint64) {}
1920
func (c *nopCollector) EVMAccountInteraction(string) {}
2021
func (c *nopCollector) MeasureRequestDuration(time.Time, string) {}

services/ingestion/engine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ func (e *Engine) processEvents(events *models.CadenceEvents) error {
206206
}
207207

208208
e.collector.EVMHeightIndexed(events.Block().Height)
209+
e.collector.CadenceHeightIndexed(events.CadenceHeight())
209210
return nil
210211
}
211212

0 commit comments

Comments
 (0)