Alerting: Fix copying of recording rule fields
Recording rule fields were not being copied correctly when duplicating an alert rule. This manifests as missing `TargetDataSourceUID` fields from the `Record` part of the rule when rules in a group are re-ordered.
Added some additional tests to ensure we cover the generation of recording rules in tests and fixed the copying logic to ensure all fields are copied correctly.
(cherry picked from commit c73b3ccf6e)
This commit is contained in:
committed by
Moustafa Baiou
parent
39ca690c5a
commit
0d2ee90ff1
@@ -561,6 +561,14 @@ func (a *AlertRuleMutators) WithAllRecordingRules() AlertRuleMutator {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *AlertRuleMutators) WithoutTargetDataSource() AlertRuleMutator {
|
||||
return func(rule *AlertRule) {
|
||||
if rule.Record != nil {
|
||||
rule.Record.TargetDatasourceUID = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a *AlertRuleMutators) WithMetric(metric string) AlertRuleMutator {
|
||||
return func(rule *AlertRule) {
|
||||
if rule.Record == nil {
|
||||
@@ -1363,10 +1371,14 @@ func ConvertToRecordingRule(rule *AlertRule) {
|
||||
if rule.Record.Metric == "" {
|
||||
rule.Record.Metric = fmt.Sprintf("some_metric_%s", util.GenerateShortUID())
|
||||
}
|
||||
if rule.Record.TargetDatasourceUID == "" {
|
||||
rule.Record.TargetDatasourceUID = util.GenerateShortUID()
|
||||
}
|
||||
rule.Condition = ""
|
||||
rule.NoDataState = ""
|
||||
rule.ExecErrState = ""
|
||||
rule.For = 0
|
||||
rule.KeepFiringFor = 0
|
||||
rule.NotificationSettings = nil
|
||||
rule.MissingSeriesEvalsToResolve = nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user