mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: update rules POST API to validate query and condition only for rules that changed. (#68667)
* replace condition validation with just structural validation * validate conditions of only new and updated rules * add integration tests for rule update\delete API Co-authored-by: George Robinson <george.robinson@grafana.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
"github.com/grafana/grafana/pkg/services/auth"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/eval"
|
||||
models2 "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
@@ -159,3 +160,18 @@ func Test_containsProvisionedAlerts(t *testing.T) {
|
||||
require.Falsef(t, containsProvisionedAlerts(provenance, rules), "the group of rules is not expected to be provisioned but it is. Provenances: %v", provenance)
|
||||
})
|
||||
}
|
||||
|
||||
type recordingConditionValidator struct {
|
||||
recorded []models2.Condition
|
||||
hook func(c models2.Condition) error
|
||||
}
|
||||
|
||||
func (r *recordingConditionValidator) Validate(_ eval.EvaluationContext, condition models2.Condition) error {
|
||||
r.recorded = append(r.recorded, condition)
|
||||
if r.hook != nil {
|
||||
return r.hook(condition)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ ConditionValidator = &recordingConditionValidator{}
|
||||
|
||||
Reference in New Issue
Block a user