Alerting: Store instance annotations in alert rule state (#114975)
Alerting: Store annotations in alert instance state
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user