mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-12 16:44:05 -08:00
Ensure alert rules are marked as restored in unit tests (#7661)
This makes sure the ALERTS timeseries is created when unit testing alerting rules. Signed-off-by: David Leadbeater <dgl@dgl.cx>
This commit is contained in:
parent
4a52faf2ae
commit
77c784ac93
8
cmd/promtool/testdata/unittest.yml
vendored
8
cmd/promtool/testdata/unittest.yml
vendored
|
@ -8,6 +8,14 @@ tests:
|
||||||
input_series:
|
input_series:
|
||||||
- series: 'up{job="prometheus", instance="localhost:9090"}'
|
- series: 'up{job="prometheus", instance="localhost:9090"}'
|
||||||
values: "0+0x1440"
|
values: "0+0x1440"
|
||||||
|
|
||||||
|
promql_expr_test:
|
||||||
|
- expr: count(ALERTS) by (alertname, alertstate)
|
||||||
|
eval_time: 4m
|
||||||
|
exp_samples:
|
||||||
|
- labels: '{alertname="InstanceDown",alertstate="pending"}'
|
||||||
|
value: 1
|
||||||
|
|
||||||
alert_rule_test:
|
alert_rule_test:
|
||||||
- eval_time: 1d
|
- eval_time: 1d
|
||||||
alertname: InstanceDown
|
alertname: InstanceDown
|
||||||
|
|
|
@ -221,6 +221,16 @@ func (tg *testGroup) test(mint, maxt time.Time, evalInterval time.Duration, grou
|
||||||
// Current index in alertEvalTimes what we are looking at.
|
// Current index in alertEvalTimes what we are looking at.
|
||||||
curr := 0
|
curr := 0
|
||||||
|
|
||||||
|
for _, g := range groups {
|
||||||
|
for _, r := range g.Rules() {
|
||||||
|
if alertRule, ok := r.(*rules.AlertingRule); ok {
|
||||||
|
// Mark alerting rules as restored, to ensure the ALERTS timeseries is
|
||||||
|
// created when they run.
|
||||||
|
alertRule.SetRestored(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var errs []error
|
var errs []error
|
||||||
for ts := mint; ts.Before(maxt); ts = ts.Add(evalInterval) {
|
for ts := mint; ts.Before(maxt); ts = ts.Add(evalInterval) {
|
||||||
// Collects the alerts asked for unit testing.
|
// Collects the alerts asked for unit testing.
|
||||||
|
|
Loading…
Reference in a new issue