From a7d64cad21448e21116b4f1b671d4f17fe121c50 Mon Sep 17 00:00:00 2001 From: Raphael Bauduin Date: Wed, 17 Feb 2021 10:02:09 +0100 Subject: [PATCH] promtool: alert_rule_test items require alertname Accepting alert_rule_test without alertname is confusing as it will always pass with empty exp_alerts, and never with non-empty exp_alerts. Signed-off-by: Raphael Bauduin --- cmd/promtool/unittest.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/promtool/unittest.go b/cmd/promtool/unittest.go index 64107f171..682ebc66b 100644 --- a/cmd/promtool/unittest.go +++ b/cmd/promtool/unittest.go @@ -188,6 +188,13 @@ func (tg *testGroup) test(evalInterval time.Duration, groupOrderMap map[string]i // Map of all the unit tests for given eval_time. alertTests := make(map[model.Duration][]alertTestCase) for _, alert := range tg.AlertRuleTests { + if alert.Alertname == "" { + var testGroupLog string + if tg.TestGroupName != "" { + testGroupLog = fmt.Sprintf(" (in TestGroup %s)", tg.TestGroupName) + } + return []error{errors.Errorf("an item under alert_rule_test misses required attribute alertname at eval_time %v%s", alert.EvalTime, testGroupLog)} + } alertEvalTimesMap[alert.EvalTime] = struct{}{} if _, ok := alertsInTest[alert.EvalTime]; !ok {