fix(statestore): service-unhealthy grace counts from the last stored report and covers silent services
Issue: archie-core-07lyl
This commit is contained in:
1 parent
8ecda341e0
commit
bb67bd77f1
1 file changed
+7
-3
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user