From 74ff35ccdda21239485bf1fad8767de97f48393c Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Wed, 29 May 2019 16:39:58 +0200 Subject: [PATCH] cmd/promtool: add $externalLabels for alert unit tests Signed-off-by: Simon Pasquier --- cmd/promtool/unittest.go | 4 ++-- docs/configuration/unit_testing_rules.md | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/promtool/unittest.go b/cmd/promtool/unittest.go index 9d72bd39a..384388f84 100644 --- a/cmd/promtool/unittest.go +++ b/cmd/promtool/unittest.go @@ -144,6 +144,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. @@ -164,8 +165,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 3bacc7cff..5f3f3837e 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: + [ : ... ] ``` ### ``