Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metric for indexed cadence block height #571

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions metrics/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -74,6 +81,7 @@ func NewCollector(logger zerolog.Logger) Collector {
apiErrors,
traceDownloadErrorCounter,
serverPanicsCounters,
cadenceBlockHeight,
evmBlockHeight,
operatorBalance,
evmAccountCallCounters,
Expand All @@ -88,6 +96,7 @@ func NewCollector(logger zerolog.Logger) Collector {
apiErrorsCounter: apiErrors,
traceDownloadErrorCounter: traceDownloadErrorCounter,
serverPanicsCounters: serverPanicsCounters,
cadenceBlockHeight: cadenceBlockHeight,
evmBlockHeight: evmBlockHeight,
evmAccountCallCounters: evmAccountCallCounters,
requestDurations: requestDurations,
Expand Down Expand Up @@ -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))
}
Expand Down
1 change: 1 addition & 0 deletions metrics/nop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
1 change: 1 addition & 0 deletions services/ingestion/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func (e *Engine) processEvents(events *models.CadenceEvents) error {
}

e.collector.EVMHeightIndexed(events.Block().Height)
e.collector.CadenceHeightIndexed(events.CadenceHeight())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This processEvents method has a case where it can return early, if a Flow block has no EVM-related events:

// if heartbeat interval with no data still update the cadence height
if events.Empty() {
if err := e.blocks.SetLatestCadenceHeight(events.CadenceHeight(), nil); err != nil {

Maybe we should move the tracking of CadenceHeightIndexed before that condition, if we want to keep track of the fact that we received a response from the event-streaming API.
Right now we use a heartbeatInterval of 1, so we should get a response for every block.

Copy link
Contributor

@sideninja sideninja Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point @m-Peter
I think we should change flow EVM GW to expect one evm block for one cadence block, now we kinda generalize the idea so there could be none blocks etc, I think this loose requirement can create more issues than it will solve, if we, one day change this mapping 1:1 we should update the gateway then. I don't think it's still worth generalizing at this point. So this PR can be accepted in the current shape but follow-up PR must be made to make ingesting more strict imho.

return nil
}

Expand Down
Loading