From 95c78eec40bd40fe708040a721ff6ff5d828332b Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 29 Nov 2021 07:50:07 +0100 Subject: [PATCH] Notify only after third failed self-check --- compat/module.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/compat/module.go b/compat/module.go index a6e9da05..379050b0 100644 --- a/compat/module.go +++ b/compat/module.go @@ -15,7 +15,15 @@ var ( selfcheckTask *modules.Task selfcheckTaskRetryAfter = 10 * time.Second - selfCheckIsFailing = abool.New() + + // selfCheckIsFailing holds whether or not the self-check is currently + // failing. This helps other failure systems to not make noise when there is + // an underlying failure. + selfCheckIsFailing = abool.New() + + // selfcheckFails counts how often the self check failed successively. + // selfcheckFails is not locked as it is only accessed by the self-check task. + selfcheckFails int ) func init() { @@ -55,6 +63,7 @@ func selfcheckTaskFunc(ctx context.Context, task *modules.Task) error { issue, err := selfcheck(ctx) if err == nil { selfCheckIsFailing.UnSet() + selfcheckFails = 0 resetSystemIssue() return nil } @@ -62,14 +71,18 @@ func selfcheckTaskFunc(ctx context.Context, task *modules.Task) error { // Log result. if issue != nil { selfCheckIsFailing.Set() + selfcheckFails++ log.Errorf("compat: %s", err) - issue.notify(err) + if selfcheckFails >= 3 { + issue.notify(err) + } // Retry quicker when failed. task.Schedule(time.Now().Add(selfcheckTaskRetryAfter)) } else { selfCheckIsFailing.UnSet() + selfcheckFails = 0 // Only log internal errors, but don't notify. log.Warningf("compat: %s", err)