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 {