Alerting: Include rule uid, title, namespace in unique constraint errors (#82011)

* Alerting: Include rule_uid, title, namespace_uid in unique constraint errors
This commit is contained in:
Matthew Jacobson
2024-02-07 12:55:48 -05:00
committed by GitHub
parent 645684df15
commit dd0ca1263b
5 changed files with 53 additions and 7 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ var (
ErrCannotEditNamespace = errors.New("user does not have permissions to edit the namespace")
ErrRuleGroupNamespaceNotFound = errors.New("rule group not found under this namespace")
ErrAlertRuleFailedValidation = errors.New("invalid alert rule")
ErrAlertRuleUniqueConstraintViolation = errors.New("a conflicting alert rule is found: rule title under the same organisation and folder should be unique")
ErrAlertRuleUniqueConstraintViolation = errors.New("rule title under the same organisation and folder should be unique")
ErrQuotaReached = errors.New("quota has been exceeded")
// ErrNoDashboard is returned when the alert rule does not have a Dashboard UID
// in its annotations or the dashboard does not exist.
+15
View File
@@ -0,0 +1,15 @@
package models
import (
"github.com/grafana/grafana/pkg/util/errutil"
)
var (
errAlertRuleConflictMsg = "conflicting alert rule found [rule_uid: '{{ .Public.RuleUID }}', title: '{{ .Public.Title }}', namespace_uid: '{{ .Public.NamespaceUID }}']: {{ .Public.Error }}"
ErrAlertRuleConflictBase = errutil.Conflict("alerting.alert-rule.conflict").
MustTemplate(errAlertRuleConflictMsg, errutil.WithPublic(errAlertRuleConflictMsg))
)
func ErrAlertRuleConflict(rule AlertRule, underlying error) error {
return ErrAlertRuleConflictBase.Build(errutil.TemplateData{Public: map[string]any{"RuleUID": rule.UID, "Title": rule.Title, "NamespaceUID": rule.NamespaceUID, "Error": underlying.Error()}, Error: underlying})
}