Browse Source

Merge pull request #5608 from simonpasquier/external-labels-for-alert-tests

cmd/promtool: add $externalLabels for alert unit tests
pull/5698/head
Björn Rabenstein 6 years ago committed by GitHub
parent
commit
dc22f74153
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      cmd/promtool/unittest.go
  2. 4
      docs/configuration/unit_testing_rules.md

4
cmd/promtool/unittest.go

@ -157,6 +157,7 @@ type testGroup struct {
InputSeries []series `yaml:"input_series"`
AlertRuleTests []alertTestCase `yaml:"alert_rule_test,omitempty"`
PromqlExprTests []promqlTestCase `yaml:"promql_expr_test,omitempty"`
ExternalLabels labels.Labels `yaml:"external_labels,omitempty"`
}
// test performs the unit tests.
@ -177,8 +178,7 @@ func (tg *testGroup) test(mint, maxt time.Time, evalInterval time.Duration, grou
Logger: log.NewNopLogger(),
}
m := rules.NewManager(opts)
// TODO(beorn7): Provide a way to pass in external labels.
groupsMap, ers := m.LoadGroups(tg.Interval, nil, ruleFiles...)
groupsMap, ers := m.LoadGroups(tg.Interval, tg.ExternalLabels, ruleFiles...)
if ers != nil {
return ers
}

4
docs/configuration/unit_testing_rules.md

@ -53,6 +53,10 @@ alert_rule_test:
# Unit tests PromQL expressions.
promql_expr_test:
[ - <promql_test_case> ]
# External labels accessible to the alert template.
external_labels:
[ <labelname>: <string> ... ]
```
### `<series>`

Loading…
Cancel
Save