Skip to content

Commit

Permalink
Added metrics for observed waypoints (#12785)
Browse files Browse the repository at this point in the history
  • Loading branch information
eastorski authored Nov 20, 2024
1 parent 65e829e commit ffcbbf1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions polygon/heimdall/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ var (
timer: metrics.GetOrCreateSummary("client_requests_checkpointcount_duration"),
},
}

waypointCheckpointLength = metrics.NewGauge(`waypoint_length{type="checkpoint"}`)
waypointMilestoneLength = metrics.NewGauge(`waypoint_length{type="milestone"}`)
)

func sendMetrics(ctx context.Context, start time.Time, isSuccessful bool) {
Expand All @@ -102,3 +105,11 @@ func sendMetrics(ctx context.Context, start time.Time, isSuccessful bool) {
meters.request[isSuccessful].Set(1)
meters.timer.ObserveDuration(start)
}

func UpdateObservedWaypointCheckpointLength(length uint64) {
waypointCheckpointLength.SetUint64(length)
}

func UpdateObservedWaypointMilestoneLength(length uint64) {
waypointMilestoneLength.SetUint64(length)
}
19 changes: 19 additions & 0 deletions polygon/heimdall/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ func (s *Service) RegisterMilestoneObserver(callback func(*Milestone), opts ...O
})
}

func (s *Service) RegisterCheckpointObserver(callback func(*Checkpoint), opts ...ObserverOption) polygoncommon.UnregisterFunc {
options := NewObserverOptions(opts...)
return s.checkpointScraper.RegisterObserver(func(entities []*Checkpoint) {
for _, entity := range libcommon.SliceTakeLast(entities, options.eventsLimit) {
callback(entity)
}
})
}

func (s *Service) RegisterSpanObserver(callback func(*Span), opts ...ObserverOption) polygoncommon.UnregisterFunc {
options := NewObserverOptions(opts...)
return s.spanScraper.RegisterObserver(func(entities []*Span) {
Expand Down Expand Up @@ -304,6 +313,16 @@ func (s *Service) Run(ctx context.Context) error {
s.spanBlockProducersTracker.ObserveSpanAsync(span)
})

milestoneObserver := s.RegisterMilestoneObserver(func(milestone *Milestone) {
UpdateObservedWaypointMilestoneLength(milestone.Length())
})
defer milestoneObserver()

checkpointObserver := s.RegisterCheckpointObserver(func(checkpoint *Checkpoint) {
UpdateObservedWaypointCheckpointLength(checkpoint.Length())
}, WithEventsLimit(5))
defer checkpointObserver()

eg, ctx := errgroup.WithContext(ctx)
eg.Go(func() error {
if err := s.checkpointScraper.Run(ctx); err != nil {
Expand Down

0 comments on commit ffcbbf1

Please sign in to comment.