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
+28 -4
View File
@@ -218,6 +218,9 @@
"format": "int64",
"type": "integer"
},
"record": {
"$ref": "#/definitions/AlertRuleRecordExport"
},
"title": {
"type": "string"
},
@@ -367,6 +370,18 @@
"title": "AlertRuleNotificationSettingsExport is the provisioned export of models.NotificationSettings.",
"type": "object"
},
"AlertRuleRecordExport": {
"properties": {
"from": {
"type": "string"
},
"metric": {
"type": "string"
}
},
"title": "Record is the provisioned export of models.Record.",
"type": "object"
},
"AlertingFileExport": {
"properties": {
"apiVersion": {
@@ -2922,6 +2937,9 @@
"provenance": {
"$ref": "#/definitions/Provenance"
},
"record": {
"$ref": "#/definitions/Record"
},
"ruleGroup": {
"example": "eval_group_1",
"maxLength": 190,
@@ -3256,13 +3274,20 @@
"Record": {
"properties": {
"from": {
"description": "Which expression node should be used as the input for the recorded metric.",
"example": "A",
"type": "string"
},
"metric": {
"description": "Name of the recorded metric.",
"example": "grafana_alerts_ratio",
"type": "string"
}
},
"title": "Record defines how data produced by a recording rule is written.",
"required": [
"metric",
"from"
],
"type": "object"
},
"RelativeTimeRange": {
@@ -4435,7 +4460,6 @@
"type": "object"
},
"alertGroup": {
"description": "AlertGroup alert group",
"properties": {
"alerts": {
"description": "alerts",
@@ -4459,7 +4483,6 @@
"type": "object"
},
"alertGroups": {
"description": "AlertGroups alert groups",
"items": {
"$ref": "#/definitions/alertGroup"
},
@@ -4626,6 +4649,7 @@
"type": "array"
},
"gettableSilence": {
"description": "GettableSilence gettable silence",
"properties": {
"comment": {
"description": "comment",
@@ -4681,6 +4705,7 @@
"type": "array"
},
"integration": {
"description": "Integration integration",
"properties": {
"lastNotifyAttempt": {
"description": "A timestamp indicating the last attempt to deliver a notification regardless of the outcome.\nFormat: date-time",
@@ -4861,7 +4886,6 @@
"type": "object"
},
"receiver": {
"description": "Receiver receiver",
"properties": {
"active": {
"description": "active",
@@ -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"`
}
+38 -85
View File
@@ -218,6 +218,9 @@
"format": "int64",
"type": "integer"
},
"record": {
"$ref": "#/definitions/AlertRuleRecordExport"
},
"title": {
"type": "string"
},
@@ -367,6 +370,18 @@
"title": "AlertRuleNotificationSettingsExport is the provisioned export of models.NotificationSettings.",
"type": "object"
},
"AlertRuleRecordExport": {
"properties": {
"from": {
"type": "string"
},
"metric": {
"type": "string"
}
},
"title": "Record is the provisioned export of models.Record.",
"type": "object"
},
"AlertingFileExport": {
"properties": {
"apiVersion": {
@@ -967,7 +982,9 @@
},
"type": "object"
},
"EvalQueriesResponse": {},
"EvalQueriesResponse": {
"type": "object"
},
"ExplorePanelsState": {
"description": "This is an object constructed with the keys as the values of the enum VisType and the value being a bag of properties"
},
@@ -2922,6 +2939,9 @@
"provenance": {
"$ref": "#/definitions/Provenance"
},
"record": {
"$ref": "#/definitions/Record"
},
"ruleGroup": {
"example": "eval_group_1",
"maxLength": 190,
@@ -3256,13 +3276,20 @@
"Record": {
"properties": {
"from": {
"description": "Which expression node should be used as the input for the recorded metric.",
"example": "A",
"type": "string"
},
"metric": {
"description": "Name of the recorded metric.",
"example": "grafana_alerts_ratio",
"type": "string"
}
},
"title": "Record defines how data produced by a recording rule is written.",
"required": [
"metric",
"from"
],
"type": "object"
},
"RelativeTimeRange": {
@@ -4461,7 +4488,8 @@
},
"alertGroups": {
"items": {
"$ref": "#/definitions/alertGroup"
"$ref": "#/definitions/alertGroup",
"type": "object"
},
"type": "array"
},
@@ -4564,49 +4592,6 @@
"type": "object"
},
"gettableAlert": {
"description": "GettableAlert gettable alert",
"properties": {
"annotations": {
"$ref": "#/definitions/labelSet"
},
"endsAt": {
"description": "ends at",
"format": "date-time",
"type": "string"
},
"fingerprint": {
"description": "fingerprint",
"type": "string"
},
"generatorURL": {
"description": "generator URL\nFormat: uri",
"format": "uri",
"type": "string"
},
"labels": {
"$ref": "#/definitions/labelSet"
},
"receivers": {
"description": "receivers",
"items": {
"$ref": "#/definitions/receiver"
},
"type": "array"
},
"startsAt": {
"description": "starts at",
"format": "date-time",
"type": "string"
},
"status": {
"$ref": "#/definitions/alertStatus"
},
"updatedAt": {
"description": "updated at",
"format": "date-time",
"type": "string"
}
},
"required": [
"labels",
"annotations",
@@ -4620,49 +4605,13 @@
"type": "object"
},
"gettableAlerts": {
"description": "GettableAlerts gettable alerts",
"items": {
"$ref": "#/definitions/gettableAlert"
"$ref": "#/definitions/gettableAlert",
"type": "object"
},
"type": "array"
},
"gettableSilence": {
"description": "GettableSilence gettable silence",
"properties": {
"comment": {
"description": "comment",
"type": "string"
},
"createdBy": {
"description": "created by",
"type": "string"
},
"endsAt": {
"description": "ends at",
"format": "date-time",
"type": "string"
},
"id": {
"description": "id",
"type": "string"
},
"matchers": {
"$ref": "#/definitions/matchers"
},
"startsAt": {
"description": "starts at",
"format": "date-time",
"type": "string"
},
"status": {
"$ref": "#/definitions/silenceStatus"
},
"updatedAt": {
"description": "updated at",
"format": "date-time",
"type": "string"
}
},
"required": [
"comment",
"createdBy",
@@ -4677,11 +4626,13 @@
},
"gettableSilences": {
"items": {
"$ref": "#/definitions/gettableSilence"
"$ref": "#/definitions/gettableSilence",
"type": "object"
},
"type": "array"
},
"integration": {
"description": "Integration integration",
"properties": {
"lastNotifyAttempt": {
"description": "A timestamp indicating the last attempt to deliver a notification regardless of the outcome.\nFormat: date-time",
@@ -4825,6 +4776,7 @@
"type": "array"
},
"postableSilence": {
"description": "PostableSilence postable silence",
"properties": {
"comment": {
"description": "comment",
@@ -4862,6 +4814,7 @@
"type": "object"
},
"receiver": {
"description": "Receiver receiver",
"properties": {
"active": {
"description": "active",
+44 -83
View File
@@ -3731,6 +3731,9 @@
"type": "integer",
"format": "int64"
},
"record": {
"$ref": "#/definitions/AlertRuleRecordExport"
},
"title": {
"type": "string"
},
@@ -3878,6 +3881,18 @@
}
}
},
"AlertRuleRecordExport": {
"type": "object",
"title": "Record is the provisioned export of models.Record.",
"properties": {
"from": {
"type": "string"
},
"metric": {
"type": "string"
}
}
},
"AlertingFileExport": {
"type": "object",
"title": "AlertingFileExport is the full provisioned file export.",
@@ -4480,7 +4495,7 @@
}
},
"EvalQueriesResponse": {
"$ref": "#/definitions/EvalQueriesResponse"
"type": "object"
},
"ExplorePanelsState": {
"description": "This is an object constructed with the keys as the values of the enum VisType and the value being a bag of properties"
@@ -6449,6 +6464,9 @@
"provenance": {
"$ref": "#/definitions/Provenance"
},
"record": {
"$ref": "#/definitions/Record"
},
"ruleGroup": {
"type": "string",
"maxLength": 190,
@@ -6770,13 +6788,20 @@
},
"Record": {
"type": "object",
"title": "Record defines how data produced by a recording rule is written.",
"required": [
"metric",
"from"
],
"properties": {
"from": {
"type": "string"
"description": "Which expression node should be used as the input for the recorded metric.",
"type": "string",
"example": "A"
},
"metric": {
"type": "string"
"description": "Name of the recorded metric.",
"type": "string",
"example": "grafana_alerts_ratio"
}
}
},
@@ -7972,15 +7997,15 @@
"receiver": {
"$ref": "#/definitions/receiver"
}
},
"$ref": "#/definitions/alertGroup"
}
},
"alertGroups": {
"description": "AlertGroups alert groups",
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/alertGroup"
},
"$ref": "#/definitions/alertGroups"
}
},
"alertStatus": {
"description": "AlertStatus alert status",
@@ -8081,7 +8106,6 @@
}
},
"gettableAlert": {
"description": "GettableAlert gettable alert",
"type": "object",
"required": [
"labels",
@@ -8092,58 +8116,14 @@
"startsAt",
"status",
"updatedAt"
],
"properties": {
"annotations": {
"$ref": "#/definitions/labelSet"
},
"endsAt": {
"description": "ends at",
"type": "string",
"format": "date-time"
},
"fingerprint": {
"description": "fingerprint",
"type": "string"
},
"generatorURL": {
"description": "generator URL\nFormat: uri",
"type": "string",
"format": "uri"
},
"labels": {
"$ref": "#/definitions/labelSet"
},
"receivers": {
"description": "receivers",
"type": "array",
"items": {
"$ref": "#/definitions/receiver"
}
},
"startsAt": {
"description": "starts at",
"type": "string",
"format": "date-time"
},
"status": {
"$ref": "#/definitions/alertStatus"
},
"updatedAt": {
"description": "updated at",
"type": "string",
"format": "date-time"
}
},
"$ref": "#/definitions/gettableAlert"
]
},
"gettableAlerts": {
"description": "GettableAlerts gettable alerts",
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/gettableAlert"
},
"$ref": "#/definitions/gettableAlerts"
}
},
"gettableSilence": {
"description": "GettableSilence gettable silence",
@@ -8192,17 +8172,17 @@
"type": "string",
"format": "date-time"
}
},
"$ref": "#/definitions/gettableSilence"
}
},
"gettableSilences": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/gettableSilence"
},
"$ref": "#/definitions/gettableSilences"
}
},
"integration": {
"description": "Integration integration",
"type": "object",
"required": [
"name",
@@ -8230,8 +8210,7 @@
"description": "send resolved",
"type": "boolean"
}
},
"$ref": "#/definitions/integration"
}
},
"labelSet": {
"description": "LabelSet label set",
@@ -8347,6 +8326,7 @@
}
},
"postableSilence": {
"description": "PostableSilence postable silence",
"type": "object",
"required": [
"comment",
@@ -8381,8 +8361,7 @@
"type": "string",
"format": "date-time"
}
},
"$ref": "#/definitions/postableSilence"
}
},
"receiver": {
"type": "object",
@@ -8390,25 +8369,7 @@
"active",
"integrations",
"name"
],
"properties": {
"active": {
"description": "active",
"type": "boolean"
},
"integrations": {
"description": "integrations",
"type": "array",
"items": {
"$ref": "#/definitions/integration"
}
},
"name": {
"description": "name",
"type": "string"
}
},
"$ref": "#/definitions/receiver"
]
},
"silence": {
"description": "Silence silence",