Skip to content

Commit

Permalink
Cleanup: rename lastBlockAge -> lastFetchedBlockAge
Browse files Browse the repository at this point in the history
  • Loading branch information
dwasse committed Jul 8, 2024
1 parent 4afaee1 commit 60b0cf1
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ethergo/listener/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type otelRecorder struct {
meter metric.Meter
// lastBlockGauge is the gauge for the last block.
lastBlockGauge metric.Int64ObservableGauge
// lastBlockAgeGauge is the gauge for the last block age.
lastBlockAgeGauge metric.Float64ObservableGauge
// lastFetchedBlockAgeGauge is the gauge for the last block age.
lastFetchedBlockAgeGauge metric.Float64ObservableGauge
// lastBlock is the last block processed by the listener.
lastBlock *uint64
// lastBlockFetchTime is the time the last block was fetched (used to calculate last block age).
Expand All @@ -53,7 +53,7 @@ func newOtelRecorder(meterHandler metrics.Handler, chainID int) (_ iOtelRecorder
return nil, fmt.Errorf("could not create last block gauge")
}

Check warning on line 54 in ethergo/listener/otel.go

View check run for this annotation

Codecov / codecov/patch

ethergo/listener/otel.go#L53-L54

Added lines #L53 - L54 were not covered by tests

or.lastBlockAgeGauge, err = or.meter.Float64ObservableGauge("last_block_age")
or.lastFetchedBlockAgeGauge, err = or.meter.Float64ObservableGauge("last_block_age")
if err != nil {
return nil, fmt.Errorf("could not create last block age gauge")
}

Check warning on line 59 in ethergo/listener/otel.go

View check run for this annotation

Codecov / codecov/patch

ethergo/listener/otel.go#L58-L59

Added lines #L58 - L59 were not covered by tests
Expand All @@ -63,7 +63,7 @@ func newOtelRecorder(meterHandler metrics.Handler, chainID int) (_ iOtelRecorder
return nil, fmt.Errorf("could not register callback for last block gauge")
}

Check warning on line 64 in ethergo/listener/otel.go

View check run for this annotation

Codecov / codecov/patch

ethergo/listener/otel.go#L63-L64

Added lines #L63 - L64 were not covered by tests

_, err = or.meter.RegisterCallback(or.recordLastBlockAge, or.lastBlockAgeGauge)
_, err = or.meter.RegisterCallback(or.recordLastFetchedBlockAge, or.lastFetchedBlockAgeGauge)
if err != nil {
return nil, fmt.Errorf("could not register callback for last block age gauge")
}

Check warning on line 69 in ethergo/listener/otel.go

View check run for this annotation

Codecov / codecov/patch

ethergo/listener/otel.go#L68-L69

Added lines #L68 - L69 were not covered by tests
Expand All @@ -84,16 +84,16 @@ func (o *otelRecorder) recordLastBlock(_ context.Context, observer metric.Observ
return nil

Check warning on line 84 in ethergo/listener/otel.go

View check run for this annotation

Codecov / codecov/patch

ethergo/listener/otel.go#L79-L84

Added lines #L79 - L84 were not covered by tests
}

func (o *otelRecorder) recordLastBlockAge(_ context.Context, observer metric.Observer) (err error) {
if o.metrics == nil || o.lastBlockAgeGauge == nil || o.lastBlockFetchTime == nil {
func (o *otelRecorder) recordLastFetchedBlockAge(_ context.Context, observer metric.Observer) (err error) {
if o.metrics == nil || o.lastFetchedBlockAgeGauge == nil || o.lastBlockFetchTime == nil {
return nil
}

Check warning on line 90 in ethergo/listener/otel.go

View check run for this annotation

Codecov / codecov/patch

ethergo/listener/otel.go#L87-L90

Added lines #L87 - L90 were not covered by tests

age := time.Since(*o.lastBlockFetchTime).Seconds()
opts := metric.WithAttributes(
attribute.Int(metrics.ChainID, o.chainID),
)
observer.ObserveFloat64(o.lastBlockAgeGauge, age, opts)
observer.ObserveFloat64(o.lastFetchedBlockAgeGauge, age, opts)

return nil

Check warning on line 98 in ethergo/listener/otel.go

View check run for this annotation

Codecov / codecov/patch

ethergo/listener/otel.go#L92-L98

Added lines #L92 - L98 were not covered by tests
}
Expand Down

0 comments on commit 60b0cf1

Please sign in to comment.