Alerting: Distinguish conflict violation errors (#86634)

* update generator to set ID = 0 and do not set 0 if unique is needed
* return proper message when the constraint violation
This commit is contained in:
Yuri Tseretyan
2024-04-22 12:28:46 -04:00
committed by GitHub
parent de92317fc7
commit 9735a8a080
4 changed files with 42 additions and 14 deletions
+2 -2
View File
@@ -71,7 +71,7 @@ func AlertRuleGen(mutators ...AlertRuleMutator) func() *AlertRule {
}
rule := &AlertRule{
ID: rand.Int63n(1500),
ID: 0,
OrgID: rand.Int63n(1500) + 1, // Prevent OrgID=0 as this does not pass alert rule validation.
Title: "TEST-ALERT-" + util.GenerateShortUID(),
Condition: "A",
@@ -110,7 +110,7 @@ func WithUniqueID() AlertRuleMutator {
usedID := make(map[int64]struct{})
return func(rule *AlertRule) {
for {
id := rand.Int63n(1500)
id := rand.Int63n(1500) + 1
if _, ok := usedID[id]; !ok {
usedID[id] = struct{}{}
rule.ID = id