From d8e279b7a5231b05369e29e1d124d41e46229290 Mon Sep 17 00:00:00 2001 From: Anton Bronnikov Date: Mon, 18 Mar 2024 14:35:59 +0200 Subject: [PATCH] fix: don't report groups/endpoints w/o progress --- server/handlers.go | 10 ++++++++++ state/el_endpoint.go | 7 +++++++ state/el_group.go | 8 +++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/server/handlers.go b/server/handlers.go index be4b608..ec0b7ed 100644 --- a/server/handlers.go +++ b/server/handlers.go @@ -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))}, @@ -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))}, diff --git a/state/el_endpoint.go b/state/el_endpoint.go index fad1401..4eff91a 100644 --- a/state/el_endpoint.go +++ b/state/el_endpoint.go @@ -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, diff --git a/state/el_group.go b/state/el_group.go index f49504e..b82df0a 100644 --- a/state/el_group.go +++ b/state/el_group.go @@ -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 {