Alerting: Copy alert rule metadata when the rule is updated via provisioning API (#93723)

Alerting: Copy alert rule metadata when the rule is updated
This commit is contained in:
Alexander Akhmetov
2024-09-25 22:31:02 +02:00
committed by GitHub
parent 277d82db9a
commit b9964865cb
4 changed files with 91 additions and 1 deletions
@@ -795,6 +795,13 @@ func PatchPartialAlertRule(existingRule *AlertRule, ruleToPatch *AlertRuleWithOp
if !ruleToPatch.HasPause {
ruleToPatch.IsPaused = existingRule.IsPaused
}
// Currently metadata contains only editor settings, so we can just copy it.
// If we add more fields to metadata, we might need to handle them separately,
// and/or merge or update their values.
if ruleToPatch.Metadata == (AlertRuleMetadata{}) {
ruleToPatch.Metadata = existingRule.Metadata
}
}
func ValidateRuleGroupInterval(intervalSeconds, baseIntervalSeconds int64) error {
@@ -253,10 +253,17 @@ func TestPatchPartialAlertRule(t *testing.T) {
r.IsPaused = true
},
},
{
name: "No metadata",
mutator: func(r *AlertRuleWithOptionals) {
r.Metadata = AlertRuleMetadata{}
},
},
}
gen := RuleGen.With(
RuleMuts.WithFor(time.Duration(rand.Int63n(1000) + 1)),
RuleMuts.WithFor(time.Duration(rand.Int63n(1000)+1)),
RuleMuts.WithEditorSettingsSimplifiedQueryAndExpressionsSection(true),
)
for _, testCase := range testCases {