Alerting: Fix alert rule copy to include metadata (#100212)
* copy metadata * add tests for copy and generator * extract copy rule to a production method and update usages * fix tests
This commit is contained in:
@@ -984,7 +984,7 @@ func (st DBstore) RenameReceiverInNotificationSettings(ctx context.Context, orgI
|
||||
continue
|
||||
}
|
||||
|
||||
r := ngmodels.CopyRule(rule)
|
||||
r := rule.Copy()
|
||||
for idx := range r.NotificationSettings {
|
||||
if r.NotificationSettings[idx].Receiver == oldReceiver {
|
||||
r.NotificationSettings[idx].Receiver = newReceiver
|
||||
@@ -1059,7 +1059,7 @@ func (st DBstore) RenameTimeIntervalInNotificationSettings(
|
||||
continue
|
||||
}
|
||||
|
||||
r := ngmodels.CopyRule(rule)
|
||||
r := rule.Copy()
|
||||
for idx := range r.NotificationSettings {
|
||||
for mtIdx := range r.NotificationSettings[idx].MuteTimeIntervals {
|
||||
if r.NotificationSettings[idx].MuteTimeIntervals[mtIdx] == oldTimeInterval {
|
||||
|
||||
@@ -175,7 +175,7 @@ func UpdateCalculatedRuleFields(ch *GroupDelta) *GroupDelta {
|
||||
}
|
||||
if groupKey != ch.GroupKey {
|
||||
if rule.RuleGroupIndex != idx {
|
||||
upd.New = models.CopyRule(rule)
|
||||
upd.New = rule.Copy()
|
||||
upd.New.RuleGroupIndex = idx
|
||||
upd.Diff = rule.Diff(upd.New, AlertRuleFieldsToIgnoreInDiff[:]...)
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ func TestCalculateChanges(t *testing.T) {
|
||||
submittedMap := groupByUID(t, rules)
|
||||
submitted := make([]*models.AlertRuleWithOptionals, 0, len(rules))
|
||||
for _, rule := range rules {
|
||||
submitted = append(submitted, &models.AlertRuleWithOptionals{AlertRule: *rule})
|
||||
submitted = append(submitted, &models.AlertRuleWithOptionals{AlertRule: *rule, HasMetadata: true})
|
||||
}
|
||||
|
||||
fakeStore := fakes.NewRuleStore(t)
|
||||
@@ -216,7 +216,7 @@ func TestCalculateChanges(t *testing.T) {
|
||||
submittedMap := groupByUID(t, rules)
|
||||
submitted := make([]*models.AlertRuleWithOptionals, 0, len(rules))
|
||||
for _, rule := range rules {
|
||||
submitted = append(submitted, &models.AlertRuleWithOptionals{AlertRule: *rule})
|
||||
submitted = append(submitted, &models.AlertRuleWithOptionals{AlertRule: *rule, HasMetadata: true})
|
||||
}
|
||||
|
||||
changes, err := CalculateChanges(context.Background(), fakeStore, groupKey, submitted)
|
||||
|
||||
Reference in New Issue
Block a user