diff --git a/internal/app/statestore/alerts.go b/internal/app/statestore/alerts.go index bf51291c9..247274967 100644 --- a/internal/app/statestore/alerts.go +++ b/internal/app/statestore/alerts.go @@ -28,13 +28,15 @@ const ( // serviceWatch remembers since when each service has been unhealthy. type serviceWatch struct { - since map[string]time.Time + booted time.Time + since map[string]time.Time } // unhealthy returns the services that have been down or degraded for longer // 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. +// counts from its last report, but never from before this store booted: the +// whole stack usually restarts together, and every peer's last report predates +// the restart until it reports again. func (w *serviceWatch) unhealthy(mesh []presence.Service, now time.Time) []string { if w.since == nil { w.since = map[string]time.Time{} @@ -51,7 +53,7 @@ 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() { + if service.State == presence.StateDown && service.ReportedAt.After(w.booted) { since = service.ReportedAt } w.since[service.Service] = since @@ -95,7 +97,7 @@ func (b *server) sweepAlerts(ctx context.Context, store alert.Store) { ListPresence(context.Context) ([]storecontract.Presence, error) }) reporter := alert.Reporter{Raiser: store, Log: b.log, By: "state-store"} - var watch serviceWatch + watch := serviceWatch{booted: time.Now()} ticker := time.NewTicker(alertSweepInterval) defer ticker.Stop() for {