Alerting: scheduler to use short version of model for alert rule (#48916)

* scheduler to use a short version of alert rule model
This commit is contained in:
Yuriy Tseretyan
2022-05-12 09:55:05 -04:00
committed by GitHub
parent c8a0e52a59
commit 369fcc5e9a
4 changed files with 42 additions and 14 deletions
+18
View File
@@ -113,6 +113,13 @@ type AlertRule struct {
Labels map[string]string
}
type SchedulableAlertRule struct {
UID string `xorm:"uid"`
OrgID int64 `xorm:"org_id"`
IntervalSeconds int64
Version int64
}
type LabelOption func(map[string]string)
func WithoutInternalLabels() LabelOption {
@@ -169,6 +176,11 @@ func (alertRule *AlertRule) GetKey() AlertRuleKey {
return AlertRuleKey{OrgID: alertRule.OrgID, UID: alertRule.UID}
}
// GetKey returns the alert definitions identifier
func (alertRule *SchedulableAlertRule) GetKey() AlertRuleKey {
return AlertRuleKey{OrgID: alertRule.OrgID, UID: alertRule.UID}
}
// PreSave sets default values and loads the updated model for each alert query.
func (alertRule *AlertRule) PreSave(timeNow func() time.Time) error {
for i, q := range alertRule.Data {
@@ -242,6 +254,12 @@ type ListAlertRulesQuery struct {
Result []*AlertRule
}
type GetAlertRulesForSchedulingQuery struct {
ExcludeOrgIDs []int64
Result []*SchedulableAlertRule
}
// ListNamespaceAlertRulesQuery is the query for listing namespace alert rules
type ListNamespaceAlertRulesQuery struct {
OrgID int64