Skip to content

Commit

Permalink
fix: don't report groups/endpoints w/o progress
Browse files Browse the repository at this point in the history
  • Loading branch information
0x416e746f6e committed Mar 18, 2024
1 parent 7ff4c0f commit d8e279b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
10 changes: 10 additions & 0 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func (s *Server) handleHealthcheck(w http.ResponseWriter, r *http.Request) {

func (s *Server) handleEventPrometheusObserve(_ context.Context, o metric.Observer) error {
s.state.IterateELGroupsRO(func(gname string, g *state.ELGroup) {
// don't report groups that did't progress yet
if g.HighestBlock().Sign() == 0 {
return
}

attrs := []attribute.KeyValue{
{Key: keyTargetName, Value: attribute.StringValue(groupVirtualEndpoint)},
{Key: keyTargetGroup, Value: attribute.StringValue(normalisedGroup(gname))},
Expand All @@ -78,6 +83,11 @@ func (s *Server) handleEventPrometheusObserve(_ context.Context, o metric.Observ
o.ObserveFloat64(s.metrics.timeSinceLastBlock, tsBlockGroup.Seconds(), metric.WithAttributes(attrs...))

g.IterateEndpointsRO(func(ename string, e *state.ELEndpoint) {
// don't report endpoints that did't progress yet
if e.HighestBlock().Sign() == 0 {
return
}

attrs := []attribute.KeyValue{
{Key: keyTargetName, Value: attribute.StringValue(ename)},
{Key: keyTargetGroup, Value: attribute.StringValue(normalisedGroup(gname))},
Expand Down
7 changes: 7 additions & 0 deletions state/el_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func newELEndpoint(name string) *ELEndpoint {
}
}

func (e *ELEndpoint) HighestBlock() *big.Int {
e.mx.RLock()
defer e.mx.RUnlock()

return big.NewInt(0).Set(e.highestBlock)
}

func (e *ELEndpoint) RegisterBlock(
block *big.Int,
ts time.Time,
Expand Down
8 changes: 5 additions & 3 deletions state/el_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ func (g *ELGroup) registerEndpoint(name string) error {
return nil
}

func (g *ELGroup) Name() string {
// constant, no need for mutex
return g.name
func (g *ELGroup) HighestBlock() *big.Int {
g.mx.RLock()
defer g.mx.RUnlock()

return big.NewInt(0).Set(g.highestBlock)
}

func (g *ELGroup) Endpoint(name string) *ELEndpoint {
Expand Down

0 comments on commit d8e279b

Please sign in to comment.