Alerting: Support recording rule struct in provisioning API (#87849)

* Support record struct in provisioning API

* Update api spec

* Use record field

* Restrict API endpoints following toggle

* Fix swagger spec

* Add recording rule validation to store validator
This commit is contained in:
William Wernert
2024-06-06 21:05:02 +03:00
committed by GitHub
parent 808cf75ff8
commit d359591dac
15 changed files with 426 additions and 202 deletions
@@ -477,6 +477,18 @@ type AlertRuleNotificationSettings struct {
MuteTimeIntervals []string `json:"mute_time_intervals,omitempty"`
}
// swagger:model
type Record struct {
// Name of the recorded metric.
// required: true
// example: grafana_alerts_ratio
Metric string `json:"metric" yaml:"metric"`
// Which expression node should be used as the input for the recorded metric.
// required: true
// example: A
From string `json:"from" yaml:"from"`
}
// swagger:model
type PostableGrafanaRule struct {
Title string `json:"title" yaml:"title"`
@@ -578,12 +590,6 @@ func (d *Duration) UnmarshalYAML(unmarshal func(any) error) error {
}
}
// Record defines how data produced by a recording rule is written.
type Record struct {
Metric string `json:"metric" yaml:"metric"`
From string `json:"from" yaml:"from"`
}
// swagger:model
type UpdateRuleGroupResponse struct {
Message string `json:"message"`
@@ -167,6 +167,8 @@ type ProvisionedAlertRule struct {
IsPaused bool `json:"isPaused"`
// example: {"receiver":"email","group_by":["alertname","grafana_folder","cluster"],"group_wait":"30s","group_interval":"1m","repeat_interval":"4d","mute_time_intervals":["Weekends","Holidays"]}
NotificationSettings *AlertRuleNotificationSettings `json:"notification_settings"`
//example: {"metric":"grafana_alerts_ratio", "from":"A"}
Record *Record `json:"record"`
}
// swagger:route GET /v1/provisioning/folder/{FolderUID}/rule-groups/{Group} provisioning stable RouteGetAlertRuleGroup
@@ -273,6 +275,7 @@ type AlertRuleExport struct {
Labels *map[string]string `json:"labels,omitempty" yaml:"labels,omitempty" hcl:"labels"`
IsPaused bool `json:"isPaused" yaml:"isPaused" hcl:"is_paused"`
NotificationSettings *AlertRuleNotificationSettingsExport `json:"notification_settings,omitempty" yaml:"notification_settings,omitempty" hcl:"notification_settings,block"`
Record *AlertRuleRecordExport `json:"record,omitempty" yaml:"record,omitempty" hcl:"record"`
}
// AlertQueryExport is the provisioned export of models.AlertQuery.
@@ -301,3 +304,9 @@ type AlertRuleNotificationSettingsExport struct {
RepeatInterval *string `yaml:"repeat_interval,omitempty" json:"repeat_interval,omitempty" hcl:"repeat_interval,optional"`
MuteTimeIntervals []string `yaml:"mute_time_intervals,omitempty" json:"mute_time_intervals,omitempty" hcl:"mute_timings"` // TF -> `mute_timings`
}
// Record is the provisioned export of models.Record.
type AlertRuleRecordExport struct {
Metric string `json:"metric" yaml:"metric" hcl:"metric"`
From string `json:"from" yaml:"from" hcl:"from"`
}