From bb67bd77f1b3f2e6c8fd4effc0b3d097c84aa43e Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 13 Oct 2026 15:29:29 +1100 Subject: [PATCH] fix(statestore): service-unhealthy grace counts from the last stored report and covers silent services Issue: archie-core-07lyl --- internal/app/statestore/alerts.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/app/statestore/alerts.go b/internal/app/statestore/alerts.go index 42fadf249..6b4797092 100644 --- a/internal/app/statestore/alerts.go +++ b/internal/app/statestore/alerts.go @@ -30,15 +30,16 @@ type serviceWatch struct { } // unhealthy returns the services that have been down or degraded for longer -// than serviceGrace, and forgets those that recovered. A service that never -// reported is absent rather than unhealthy and is left out. +// than serviceGrace, and forgets those that recovered. A service gone silent +// counts from its last report, which is stored, so a restart of this store does +// not restart the grace; one that never reported counts from first sight. func (w *serviceWatch) unhealthy(mesh []presence.Service, now time.Time) []string { if w.since == nil { w.since = map[string]time.Time{} } var out []string for _, service := range mesh { - if !slices.Contains(presence.Services(), service.Service) || service.ReportedAt.IsZero() { + if !slices.Contains(presence.Services(), service.Service) { continue } if service.State == presence.StateUp { @@ -48,6 +49,9 @@ func (w *serviceWatch) unhealthy(mesh []presence.Service, now time.Time) []strin since, ok := w.since[service.Service] if !ok { since = now + if service.State == presence.StateDown && !service.ReportedAt.IsZero() { + since = service.ReportedAt + } w.since[service.Service] = since } if now.Sub(since) >= serviceGrace {