Skip to content

Commit

Permalink
Account for keep_firing_for in Alerts check
Browse files Browse the repository at this point in the history
  • Loading branch information
felipesere committed Sep 8, 2023
1 parent 3c41b36 commit 7f1e22e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/checks/alerts/count.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion internal/checks/alerts_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}
}
Expand Down

0 comments on commit 7f1e22e

Please sign in to comment.