Alerting: Store instance annotations in alert rule state (#114975)

Alerting: Store annotations in alert instance state
This commit is contained in:
Alexander Akhmetov
2025-12-09 13:52:42 +01:00
committed by GitHub
parent 6746c978b4
commit c59d5d1c8e
17 changed files with 258 additions and 109 deletions
+48 -3
View File
@@ -32,9 +32,10 @@ import (
)
var (
RuleMuts = AlertRuleMutators{}
NSMuts = NotificationSettingsMutators{}
RuleGen = &AlertRuleGenerator{
RuleMuts = AlertRuleMutators{}
NSMuts = NotificationSettingsMutators{}
InstanceMuts = AlertInstanceMutators{}
RuleGen = &AlertRuleGenerator{
mutators: []AlertRuleMutator{
RuleMuts.WithUniqueUID(), RuleMuts.WithUniqueTitle(),
},
@@ -928,6 +929,50 @@ func AlertInstanceGen(mutators ...AlertInstanceMutator) *AlertInstance {
return instance
}
type AlertInstanceMutators struct{}
func (a AlertInstanceMutators) WithOrgID(orgID int64) AlertInstanceMutator {
return func(i *AlertInstance) {
i.RuleOrgID = orgID
}
}
func (a AlertInstanceMutators) WithRuleUID(ruleUID string) AlertInstanceMutator {
return func(i *AlertInstance) {
i.RuleUID = ruleUID
}
}
func (a AlertInstanceMutators) WithLabelsHash(hash string) AlertInstanceMutator {
return func(i *AlertInstance) {
i.LabelsHash = hash
}
}
func (a AlertInstanceMutators) WithReason(reason string) AlertInstanceMutator {
return func(i *AlertInstance) {
i.CurrentReason = reason
}
}
func (a AlertInstanceMutators) WithState(state InstanceStateType) AlertInstanceMutator {
return func(i *AlertInstance) {
i.CurrentState = state
}
}
func (a AlertInstanceMutators) WithLabels(labels InstanceLabels) AlertInstanceMutator {
return func(i *AlertInstance) {
i.Labels = labels
}
}
func (a AlertInstanceMutators) WithAnnotations(annotations InstanceAnnotations) AlertInstanceMutator {
return func(i *AlertInstance) {
i.Annotations = annotations
}
}
type Mutator[T any] func(*T)
// CopyNotificationSettings creates a deep copy of NotificationSettings.