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:
co-authored by
Yuri Tseretyan
parent
16f5220adc
commit
b7bbc5058f
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user