cmd/promtool: add $externalLabels for alert unit tests

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2019-05-29 16:39:58 +02:00
parent 22824c2e08
commit 74ff35ccdd
2 changed files with 6 additions and 2 deletions

View File

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

View File

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