diff --git a/pkg/services/ngalert/api/tooling/api.json b/pkg/services/ngalert/api/tooling/api.json index 6539d39c71e..965cee8114f 100644 --- a/pkg/services/ngalert/api/tooling/api.json +++ b/pkg/services/ngalert/api/tooling/api.json @@ -163,6 +163,14 @@ ], "type": "object" }, + "AlertRuleEditorSettings": { + "properties": { + "simplified_query_and_expressions_section": { + "type": "boolean" + } + }, + "type": "object" + }, "AlertRuleExport": { "properties": { "annotations": { @@ -286,6 +294,14 @@ }, "type": "object" }, + "AlertRuleMetadata": { + "properties": { + "editor_settings": { + "$ref": "#/definitions/AlertRuleEditorSettings" + } + }, + "type": "object" + }, "AlertRuleNotificationSettings": { "properties": { "group_by": { @@ -1573,6 +1589,9 @@ "is_paused": { "type": "boolean" }, + "metadata": { + "$ref": "#/definitions/AlertRuleMetadata" + }, "namespace_uid": { "type": "string" }, @@ -1660,12 +1679,25 @@ }, "GettableRuleGroupConfig": { "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/definitions/Duration" }, + "limit": { + "format": "int64", + "type": "integer" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "items": { "$ref": "#/definitions/GettableExtendedRuleNode" @@ -2786,6 +2818,9 @@ "is_paused": { "type": "boolean" }, + "metadata": { + "$ref": "#/definitions/AlertRuleMetadata" + }, "no_data_state": { "enum": [ "Alerting", @@ -2824,17 +2859,36 @@ }, "PostableRuleGroupConfig": { "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/definitions/Duration" }, + "limit": { + "format": "int64", + "type": "integer" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "items": { "$ref": "#/definitions/PostableExtendedRuleNode" }, "type": "array" + }, + "source_tenants": { + "items": { + "type": "string" + }, + "type": "array" } }, "type": "object" @@ -3616,12 +3670,25 @@ }, "RuleGroupConfigResponse": { "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/definitions/Duration" }, + "limit": { + "format": "int64", + "type": "integer" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "items": { "$ref": "#/definitions/GettableExtendedRuleNode" diff --git a/pkg/services/ngalert/api/tooling/definitions/cortex-ruler.go b/pkg/services/ngalert/api/tooling/definitions/cortex-ruler.go index cf4c693ad69..bca1323a41b 100644 --- a/pkg/services/ngalert/api/tooling/definitions/cortex-ruler.go +++ b/pkg/services/ngalert/api/tooling/definitions/cortex-ruler.go @@ -237,6 +237,14 @@ type PostableRuleGroupConfig struct { Name string `yaml:"name" json:"name"` Interval model.Duration `yaml:"interval,omitempty" json:"interval,omitempty"` Rules []PostableExtendedRuleNode `yaml:"rules" json:"rules"` + + // fields below are used by Mimir/Loki rulers + + SourceTenants []string `yaml:"source_tenants,omitempty" json:"source_tenants,omitempty"` + EvaluationDelay *model.Duration `yaml:"evaluation_delay,omitempty" json:"evaluation_delay,omitempty"` + QueryOffset *model.Duration `yaml:"query_offset,omitempty" json:"query_offset,omitempty"` + AlignEvaluationTimeOnInterval bool `yaml:"align_evaluation_time_on_interval,omitempty" json:"align_evaluation_time_on_interval,omitempty"` + Limit int `yaml:"limit,omitempty" json:"limit,omitempty"` } func (c *PostableRuleGroupConfig) UnmarshalJSON(b []byte) error { @@ -275,15 +283,26 @@ func (c *PostableRuleGroupConfig) validate() error { if hasGrafRules && hasLotexRules { return fmt.Errorf("cannot mix Grafana & Prometheus style rules") } + + if hasGrafRules && (len(c.SourceTenants) > 0 || c.EvaluationDelay != nil || c.QueryOffset != nil || c.AlignEvaluationTimeOnInterval || c.Limit > 0) { + return fmt.Errorf("fields source_tenants, evaluation_delay, query_offset, align_evaluation_time_on_interval and limit are not supported for Grafana rules") + } return nil } // swagger:model type GettableRuleGroupConfig struct { - Name string `yaml:"name" json:"name"` - Interval model.Duration `yaml:"interval,omitempty" json:"interval,omitempty"` - SourceTenants []string `yaml:"source_tenants,omitempty" json:"source_tenants,omitempty"` - Rules []GettableExtendedRuleNode `yaml:"rules" json:"rules"` + Name string `yaml:"name" json:"name"` + Interval model.Duration `yaml:"interval,omitempty" json:"interval,omitempty"` + Rules []GettableExtendedRuleNode `yaml:"rules" json:"rules"` + + // fields below are used by Mimir/Loki rulers + + SourceTenants []string `yaml:"source_tenants,omitempty" json:"source_tenants,omitempty"` + EvaluationDelay *model.Duration `yaml:"evaluation_delay,omitempty" json:"evaluation_delay,omitempty"` + QueryOffset *model.Duration `yaml:"query_offset,omitempty" json:"query_offset,omitempty"` + AlignEvaluationTimeOnInterval bool `yaml:"align_evaluation_time_on_interval,omitempty" json:"align_evaluation_time_on_interval,omitempty"` + Limit int `yaml:"limit,omitempty" json:"limit,omitempty"` } func (c *GettableRuleGroupConfig) UnmarshalJSON(b []byte) error { diff --git a/pkg/services/ngalert/api/tooling/post.json b/pkg/services/ngalert/api/tooling/post.json index 4371f639744..eae46145ba8 100644 --- a/pkg/services/ngalert/api/tooling/post.json +++ b/pkg/services/ngalert/api/tooling/post.json @@ -163,6 +163,14 @@ ], "type": "object" }, + "AlertRuleEditorSettings": { + "properties": { + "simplified_query_and_expressions_section": { + "type": "boolean" + } + }, + "type": "object" + }, "AlertRuleExport": { "properties": { "annotations": { @@ -286,6 +294,14 @@ }, "type": "object" }, + "AlertRuleMetadata": { + "properties": { + "editor_settings": { + "$ref": "#/definitions/AlertRuleEditorSettings" + } + }, + "type": "object" + }, "AlertRuleNotificationSettings": { "properties": { "group_by": { @@ -1573,6 +1589,9 @@ "is_paused": { "type": "boolean" }, + "metadata": { + "$ref": "#/definitions/AlertRuleMetadata" + }, "namespace_uid": { "type": "string" }, @@ -1660,12 +1679,25 @@ }, "GettableRuleGroupConfig": { "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/definitions/Duration" }, + "limit": { + "format": "int64", + "type": "integer" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "items": { "$ref": "#/definitions/GettableExtendedRuleNode" @@ -2786,6 +2818,9 @@ "is_paused": { "type": "boolean" }, + "metadata": { + "$ref": "#/definitions/AlertRuleMetadata" + }, "no_data_state": { "enum": [ "Alerting", @@ -2824,17 +2859,36 @@ }, "PostableRuleGroupConfig": { "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/definitions/Duration" }, + "limit": { + "format": "int64", + "type": "integer" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "items": { "$ref": "#/definitions/PostableExtendedRuleNode" }, "type": "array" + }, + "source_tenants": { + "items": { + "type": "string" + }, + "type": "array" } }, "type": "object" @@ -3616,12 +3670,25 @@ }, "RuleGroupConfigResponse": { "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/definitions/Duration" }, + "limit": { + "format": "int64", + "type": "integer" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "items": { "$ref": "#/definitions/GettableExtendedRuleNode" diff --git a/pkg/services/ngalert/api/tooling/spec.json b/pkg/services/ngalert/api/tooling/spec.json index 61e5ec742aa..95716ea1899 100644 --- a/pkg/services/ngalert/api/tooling/spec.json +++ b/pkg/services/ngalert/api/tooling/spec.json @@ -3794,6 +3794,14 @@ } } }, + "AlertRuleEditorSettings": { + "type": "object", + "properties": { + "simplified_query_and_expressions_section": { + "type": "boolean" + } + } + }, "AlertRuleExport": { "type": "object", "title": "AlertRuleExport is the provisioned file export of models.AlertRule.", @@ -3917,6 +3925,14 @@ } } }, + "AlertRuleMetadata": { + "type": "object", + "properties": { + "editor_settings": { + "$ref": "#/definitions/AlertRuleEditorSettings" + } + } + }, "AlertRuleNotificationSettings": { "type": "object", "required": [ @@ -5206,6 +5222,9 @@ "is_paused": { "type": "boolean" }, + "metadata": { + "$ref": "#/definitions/AlertRuleMetadata" + }, "namespace_uid": { "type": "string" }, @@ -5293,12 +5312,25 @@ "GettableRuleGroupConfig": { "type": "object", "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/definitions/Duration" }, + "limit": { + "type": "integer", + "format": "int64" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "type": "array", "items": { @@ -6420,6 +6452,9 @@ "is_paused": { "type": "boolean" }, + "metadata": { + "$ref": "#/definitions/AlertRuleMetadata" + }, "no_data_state": { "type": "string", "enum": [ @@ -6458,17 +6493,36 @@ "PostableRuleGroupConfig": { "type": "object", "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/definitions/Duration" }, + "limit": { + "type": "integer", + "format": "int64" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "type": "array", "items": { "$ref": "#/definitions/PostableExtendedRuleNode" } + }, + "source_tenants": { + "type": "array", + "items": { + "type": "string" + } } } }, @@ -7250,12 +7304,25 @@ "RuleGroupConfigResponse": { "type": "object", "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/definitions/Duration" }, + "limit": { + "type": "integer", + "format": "int64" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "type": "array", "items": { diff --git a/public/api-merged.json b/public/api-merged.json index 65ede3f4d53..a149ee3ead8 100644 --- a/public/api-merged.json +++ b/public/api-merged.json @@ -12394,6 +12394,14 @@ } } }, + "AlertRuleEditorSettings": { + "type": "object", + "properties": { + "simplified_query_and_expressions_section": { + "type": "boolean" + } + } + }, "AlertRuleExport": { "type": "object", "title": "AlertRuleExport is the provisioned file export of models.AlertRule.", @@ -12517,6 +12525,14 @@ } } }, + "AlertRuleMetadata": { + "type": "object", + "properties": { + "editor_settings": { + "$ref": "#/definitions/AlertRuleEditorSettings" + } + } + }, "AlertRuleNotificationSettings": { "type": "object", "required": [ @@ -15799,6 +15815,9 @@ "is_paused": { "type": "boolean" }, + "metadata": { + "$ref": "#/definitions/AlertRuleMetadata" + }, "namespace_uid": { "type": "string" }, @@ -15886,12 +15905,25 @@ "GettableRuleGroupConfig": { "type": "object", "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/definitions/Duration" }, + "limit": { + "type": "integer", + "format": "int64" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "type": "array", "items": { @@ -18087,6 +18119,9 @@ "is_paused": { "type": "boolean" }, + "metadata": { + "$ref": "#/definitions/AlertRuleMetadata" + }, "no_data_state": { "type": "string", "enum": [ @@ -18125,17 +18160,36 @@ "PostableRuleGroupConfig": { "type": "object", "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/definitions/Duration" }, + "limit": { + "type": "integer", + "format": "int64" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "type": "array", "items": { "$ref": "#/definitions/PostableExtendedRuleNode" } + }, + "source_tenants": { + "type": "array", + "items": { + "type": "string" + } } } }, @@ -19600,12 +19654,25 @@ "RuleGroupConfigResponse": { "type": "object", "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/definitions/Duration" }, + "limit": { + "type": "integer", + "format": "int64" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "type": "array", "items": { diff --git a/public/openapi3.json b/public/openapi3.json index 1b7bb227b26..65eec59a72c 100644 --- a/public/openapi3.json +++ b/public/openapi3.json @@ -2621,6 +2621,14 @@ ], "type": "object" }, + "AlertRuleEditorSettings": { + "properties": { + "simplified_query_and_expressions_section": { + "type": "boolean" + } + }, + "type": "object" + }, "AlertRuleExport": { "properties": { "annotations": { @@ -2744,6 +2752,14 @@ }, "type": "object" }, + "AlertRuleMetadata": { + "properties": { + "editor_settings": { + "$ref": "#/components/schemas/AlertRuleEditorSettings" + } + }, + "type": "object" + }, "AlertRuleNotificationSettings": { "properties": { "group_by": { @@ -6025,6 +6041,9 @@ "is_paused": { "type": "boolean" }, + "metadata": { + "$ref": "#/components/schemas/AlertRuleMetadata" + }, "namespace_uid": { "type": "string" }, @@ -6112,12 +6131,25 @@ }, "GettableRuleGroupConfig": { "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/components/schemas/Duration" }, + "limit": { + "format": "int64", + "type": "integer" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "items": { "$ref": "#/components/schemas/GettableExtendedRuleNode" @@ -8313,6 +8345,9 @@ "is_paused": { "type": "boolean" }, + "metadata": { + "$ref": "#/components/schemas/AlertRuleMetadata" + }, "no_data_state": { "enum": [ "Alerting", @@ -8351,17 +8386,36 @@ }, "PostableRuleGroupConfig": { "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/components/schemas/Duration" }, + "limit": { + "format": "int64", + "type": "integer" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "items": { "$ref": "#/components/schemas/PostableExtendedRuleNode" }, "type": "array" + }, + "source_tenants": { + "items": { + "type": "string" + }, + "type": "array" } }, "type": "object" @@ -9826,12 +9880,25 @@ }, "RuleGroupConfigResponse": { "properties": { + "align_evaluation_time_on_interval": { + "type": "boolean" + }, + "evaluation_delay": { + "type": "string" + }, "interval": { "$ref": "#/components/schemas/Duration" }, + "limit": { + "format": "int64", + "type": "integer" + }, "name": { "type": "string" }, + "query_offset": { + "type": "string" + }, "rules": { "items": { "$ref": "#/components/schemas/GettableExtendedRuleNode"