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

Added metrics for observed waypoints #12785

Merged
merged 1 commit into from
Nov 20, 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
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
Loading