Alerting: Add SaveAlertInstancesForRule instance store method (#94505)
Alerting: Add SaveAlertInstancesForRule method to the InstanceStore interface
This commit is contained in:
@@ -464,6 +464,11 @@ type AlertRuleKeyWithVersion struct {
|
||||
AlertRuleKey `xorm:"extends"`
|
||||
}
|
||||
|
||||
type AlertRuleKeyWithGroup struct {
|
||||
RuleGroup string
|
||||
AlertRuleKey `xorm:"extends"`
|
||||
}
|
||||
|
||||
type AlertRuleKeyWithId struct {
|
||||
AlertRuleKey
|
||||
ID int64
|
||||
@@ -517,6 +522,11 @@ func (alertRule *AlertRule) GetKey() AlertRuleKey {
|
||||
return AlertRuleKey{OrgID: alertRule.OrgID, UID: alertRule.UID}
|
||||
}
|
||||
|
||||
// GetKeyWithGroup returns the alert definitions identifier
|
||||
func (alertRule *AlertRule) GetKeyWithGroup() AlertRuleKeyWithGroup {
|
||||
return AlertRuleKeyWithGroup{AlertRuleKey: alertRule.GetKey(), RuleGroup: alertRule.RuleGroup}
|
||||
}
|
||||
|
||||
// GetGroupKey returns the identifier of a group the rule belongs to
|
||||
func (alertRule *AlertRule) GetGroupKey() AlertRuleGroupKey {
|
||||
return AlertRuleGroupKey{OrgID: alertRule.OrgID, NamespaceUID: alertRule.NamespaceUID, RuleGroup: alertRule.RuleGroup}
|
||||
|
||||
@@ -884,3 +884,27 @@ func TestTimeRangeYAML(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, yamlRaw, string(serialized))
|
||||
}
|
||||
|
||||
func TestAlertRuleGetKey(t *testing.T) {
|
||||
t.Run("should return correct key", func(t *testing.T) {
|
||||
rule := RuleGen.GenerateRef()
|
||||
expected := AlertRuleKey{
|
||||
OrgID: rule.OrgID,
|
||||
UID: rule.UID,
|
||||
}
|
||||
require.Equal(t, expected, rule.GetKey())
|
||||
})
|
||||
}
|
||||
|
||||
func TestAlertRuleGetKeyWithGroup(t *testing.T) {
|
||||
t.Run("should return correct key", func(t *testing.T) {
|
||||
rule := RuleGen.With(
|
||||
RuleMuts.WithUniqueGroupIndex(),
|
||||
).GenerateRef()
|
||||
expected := AlertRuleKeyWithGroup{
|
||||
AlertRuleKey: rule.GetKey(),
|
||||
RuleGroup: rule.RuleGroup,
|
||||
}
|
||||
require.Equal(t, expected, rule.GetKeyWithGroup())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -587,6 +587,14 @@ func GenerateRuleKey(orgID int64) AlertRuleKey {
|
||||
}
|
||||
}
|
||||
|
||||
// GenerateRuleKeyWithGroup generates a random alert rule key with group
|
||||
func GenerateRuleKeyWithGroup(orgID int64) AlertRuleKeyWithGroup {
|
||||
return AlertRuleKeyWithGroup{
|
||||
AlertRuleKey: GenerateRuleKey(orgID),
|
||||
RuleGroup: util.GenerateShortUID(),
|
||||
}
|
||||
}
|
||||
|
||||
// GenerateGroupKey generates a random group key
|
||||
func GenerateGroupKey(orgID int64) AlertRuleGroupKey {
|
||||
return AlertRuleGroupKey{
|
||||
|
||||
Reference in New Issue
Block a user