diff --git a/docs/checks/alerts/count.md b/docs/checks/alerts/count.md index 4ca9ea0e..7b8febad 100644 --- a/docs/checks/alerts/count.md +++ b/docs/checks/alerts/count.md @@ -9,7 +9,7 @@ grand_parent: Documentation This check is used to estimate how many times given alert would fire. It will run `expr` query from every alert rule against selected Prometheus servers and report how many unique alerts it would generate. -If `for` is set on alerts it will be used to adjust results. +If `for` and/or `keep_firing_for` are set on alerts they will be used to adjust results. ## Configuration diff --git a/internal/checks/alerts_count.go b/internal/checks/alerts_count.go index e96f3727..5d119516 100644 --- a/internal/checks/alerts_count.go +++ b/internal/checks/alerts_count.go @@ -89,10 +89,15 @@ func (c AlertsCheck) Check(ctx context.Context, _ string, rule parser.Rule, _ [] if rule.AlertingRule.For != nil { forDur, _ = model.ParseDuration(rule.AlertingRule.For.Value.Value) } + var keepFiringForDur model.Duration + if rule.AlertingRule.For != nil { + keepFiringForDur, _ = model.ParseDuration(rule.AlertingRule.KeepFiringFor.Value.Value) + } var alerts int for _, r := range qr.Series.Ranges { - if r.End.Sub(r.Start) > time.Duration(forDur) { + // If `keepFiringFor` is not defined its Duration will be 0 + if r.End.Sub(r.Start) > (time.Duration(forDur) + time.Duration(keepFiringForDur)) { alerts++ } }