Alerting: Fix incorrect 500 code on missing alert rule dashboardUID / panelID (#96491)

This commit is contained in:
Matthew Jacobson
2024-11-14 21:24:48 +02:00
committed by GitHub
parent 97347a1f94
commit 64c93217ff
5 changed files with 90 additions and 21 deletions
@@ -301,6 +301,36 @@ func TestValidateRuleGroupFailures(t *testing.T) {
require.Contains(t, err.Error(), apiModel.Rules[0].GrafanaManagedAlert.UID)
},
},
{
name: "fail with 4xx if rule contains only panelID",
group: func() *apimodels.PostableRuleGroupConfig {
r1 := validRule()
panelId := int64(42)
r1.Annotations = map[string]string{
models.PanelIDAnnotation: strconv.FormatInt(panelId, 10),
}
g := validGroup(cfg, r1)
return &g
},
assert: func(t *testing.T, apiModel *apimodels.PostableRuleGroupConfig, err error) {
require.ErrorIs(t, err, models.ErrAlertRuleFailedValidation)
},
},
{
name: "fail with 4xx if rule contains only dashboardUID",
group: func() *apimodels.PostableRuleGroupConfig {
r1 := validRule()
dashboardUid := "oinwerfgiuac"
r1.Annotations = map[string]string{
models.DashboardUIDAnnotation: dashboardUid,
}
g := validGroup(cfg, r1)
return &g
},
assert: func(t *testing.T, apiModel *apimodels.PostableRuleGroupConfig, err error) {
require.ErrorIs(t, err, models.ErrAlertRuleFailedValidation)
},
},
}
for _, testCase := range testCases {