grafana/pkg/services/ngalert/store/models.go
Yuri Tseretyan f8fa5286a1
Alerting: Introduce alert rule models in storage (#93187)
* introduce storage model for alert rule tables
* remove AlertRuleVersion from models because it's not used anywhere other than in storage
* update historian xorm store to use alerting store to fetch rules

* fix folder tests

---------

Co-authored-by: Matthew Jacobson <matthew.jacobson@grafana.com>
2024-09-12 13:20:33 -04:00

67 lines
2.1 KiB
Go

package store
import "time"
// alertRule represents a record in alert_rule table
type alertRule struct {
ID int64 `xorm:"pk autoincr 'id'"`
OrgID int64 `xorm:"org_id"`
Title string
Condition string
Data string
Updated time.Time
IntervalSeconds int64
Version int64 `xorm:"version"` // this tag makes xorm add optimistic lock (see https://xorm.io/docs/chapter-06/1.lock/)
UID string `xorm:"uid"`
NamespaceUID string `xorm:"namespace_uid"`
DashboardUID *string `xorm:"dashboard_uid"`
PanelID *int64 `xorm:"panel_id"`
RuleGroup string
RuleGroupIndex int `xorm:"rule_group_idx"`
Record string
NoDataState string
ExecErrState string
For time.Duration
Annotations string
Labels string
IsPaused bool
NotificationSettings string `xorm:"notification_settings"`
}
func (a alertRule) TableName() string {
return "alert_rule"
}
// alertRuleVersion represents a record in alert_rule_version table
type alertRuleVersion struct {
ID int64 `xorm:"pk autoincr 'id'"`
RuleOrgID int64 `xorm:"rule_org_id"`
RuleUID string `xorm:"rule_uid"`
RuleNamespaceUID string `xorm:"rule_namespace_uid"`
RuleGroup string
RuleGroupIndex int `xorm:"rule_group_idx"`
ParentVersion int64
RestoredFrom int64
Version int64
Created time.Time
Title string
Condition string
Data string
IntervalSeconds int64
Record string
NoDataState string
ExecErrState string
// ideally this field should have been apimodels.ApiDuration
// but this is currently not possible because of circular dependencies
For time.Duration
Annotations string
Labels string
IsPaused bool
NotificationSettings string `xorm:"notification_settings"`
}
func (a alertRuleVersion) TableName() string {
return "alert_rule_version"
}