Alerting: Don't validate rules on group update if they've only been reordered (#81841)

---------

Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
This commit is contained in:
William Wernert
2024-02-15 12:03:28 -05:00
committed by GitHub
co-authored by Yuri Tseretyan
parent 16f5220adc
commit b7bbc5058f
2 changed files with 42 additions and 3 deletions
+23 -3
View File
@@ -9,6 +9,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"slices"
"testing"
"time"
@@ -31,6 +32,7 @@ import (
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/util/cmputil"
"github.com/grafana/grafana/pkg/web"
)
@@ -538,7 +540,24 @@ func TestValidateQueries(t *testing.T) {
New: models.AlertRuleGen(func(rule *models.AlertRule) {
rule.Condition = "Update_New"
})(),
Diff: nil,
Diff: cmputil.DiffReport{
cmputil.Diff{
Path: "SomeField",
},
},
},
{
Existing: models.AlertRuleGen(func(rule *models.AlertRule) {
rule.Condition = "Update_Index_Existing"
})(),
New: models.AlertRuleGen(func(rule *models.AlertRule) {
rule.Condition = "Update_Index_New"
})(),
Diff: cmputil.DiffReport{
cmputil.Diff{
Path: "RuleGroupIndex",
},
},
},
},
Delete: []*models.AlertRule{
@@ -548,12 +567,13 @@ func TestValidateQueries(t *testing.T) {
},
}
t.Run("should validate New and Updated only", func(t *testing.T) {
t.Run("should not validate deleted rules or updated rules with ignored fields", func(t *testing.T) {
validator := &recordingConditionValidator{}
err := validateQueries(context.Background(), &delta, validator, nil)
require.NoError(t, err)
noValidate := []string{"Deleted", "Update_Index_New"}
for _, condition := range validator.recorded {
if condition.Condition == "New" || condition.Condition == "Update_New" {
if !slices.Contains(noValidate, condition.Condition) {
continue
}
assert.Failf(t, "validated unexpected condition", "condition '%s' was validated but should not", condition.Condition)