diff --git a/cmd/promtool/unittest.go b/cmd/promtool/unittest.go index 8b19d8039..798cc40e1 100644 --- a/cmd/promtool/unittest.go +++ b/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 } diff --git a/docs/configuration/unit_testing_rules.md b/docs/configuration/unit_testing_rules.md index 260752c65..2d1e4ffdc 100644 --- a/docs/configuration/unit_testing_rules.md +++ b/docs/configuration/unit_testing_rules.md @@ -53,6 +53,10 @@ alert_rule_test: # Unit tests PromQL expressions. promql_expr_test: [ - ] + +# External labels accessible to the alert template. +external_labels: + [ : ... ] ``` ### ``