Skip to content

Commit a7d64ca

Browse files
author
Raphael Bauduin
committed
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 <[email protected]>
1 parent 6a3d55d commit a7d64ca

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cmd/promtool/unittest.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ func (tg *testGroup) test(evalInterval time.Duration, groupOrderMap map[string]i
188188
// Map of all the unit tests for given eval_time.
189189
alertTests := make(map[model.Duration][]alertTestCase)
190190
for _, alert := range tg.AlertRuleTests {
191+
if alert.Alertname == "" {
192+
var testGroupLog string
193+
if tg.TestGroupName != "" {
194+
testGroupLog = fmt.Sprintf(" (in TestGroup %s)", tg.TestGroupName)
195+
}
196+
return []error{errors.Errorf("an item under alert_rule_test misses required attribute alertname at eval_time %v%s", alert.EvalTime, testGroupLog)}
197+
}
191198
alertEvalTimesMap[alert.EvalTime] = struct{}{}
192199

193200
if _, ok := alertsInTest[alert.EvalTime]; !ok {

0 commit comments

Comments
 (0)