From 5ddcac8678e4a5f51f32a1db0a7035a312f75e10 Mon Sep 17 00:00:00 2001 From: Moustafa Baiou Date: Tue, 22 Apr 2025 14:57:04 -0400 Subject: [PATCH] Alerting: Add back time interval items to the API spec (#104306) --- pkg/services/ngalert/api/tooling/api.json | 61 ++++++++++- .../api/tooling/definitions/time_intervals.go | 19 ++++ pkg/services/ngalert/api/tooling/post.json | 63 +++++++++-- pkg/services/ngalert/api/tooling/spec.json | 63 +++++++++-- public/api-enterprise-spec.json | 100 ++++++++++++++++++ public/api-merged.json | 61 ++++++++++- public/openapi3.json | 61 ++++++++++- 7 files changed, 402 insertions(+), 26 deletions(-) create mode 100644 pkg/services/ngalert/api/tooling/definitions/time_intervals.go diff --git a/pkg/services/ngalert/api/tooling/api.json b/pkg/services/ngalert/api/tooling/api.json index 696e5686d06..e6305fc2c91 100644 --- a/pkg/services/ngalert/api/tooling/api.json +++ b/pkg/services/ngalert/api/tooling/api.json @@ -492,6 +492,12 @@ "name": { "type": "string" }, + "queriedDatasourceUIDs": { + "items": { + "type": "string" + }, + "type": "array" + }, "query": { "type": "string" }, @@ -521,9 +527,7 @@ } }, "required": [ - "uid", "name", - "folderUid", "query", "health", "type", @@ -3789,9 +3793,7 @@ } }, "required": [ - "uid", "name", - "folderUid", "query", "health", "type" @@ -4530,6 +4532,55 @@ "title": "TimeInterval represents a named set of time intervals for which a route should be muted.", "type": "object" }, + "TimeIntervalItem": { + "properties": { + "days_of_month": { + "items": { + "type": "string" + }, + "type": "array" + }, + "location": { + "type": "string" + }, + "months": { + "items": { + "type": "string" + }, + "type": "array" + }, + "times": { + "items": { + "$ref": "#/definitions/TimeIntervalTimeRange" + }, + "type": "array" + }, + "weekdays": { + "items": { + "type": "string" + }, + "type": "array" + }, + "years": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "type": "object" + }, + "TimeIntervalTimeRange": { + "properties": { + "end_time": { + "type": "string" + }, + "start_time": { + "type": "string" + } + }, + "type": "object" + }, "TimeRange": { "description": "Redefining this to avoid an import cycle", "properties": { @@ -4988,6 +5039,7 @@ "type": "object" }, "gettableAlerts": { + "description": "GettableAlerts gettable alerts", "items": { "$ref": "#/definitions/gettableAlert", "type": "object" @@ -5112,6 +5164,7 @@ "type": "object" }, "gettableSilences": { + "description": "GettableSilences gettable silences", "items": { "$ref": "#/definitions/gettableSilence", "type": "object" diff --git a/pkg/services/ngalert/api/tooling/definitions/time_intervals.go b/pkg/services/ngalert/api/tooling/definitions/time_intervals.go new file mode 100644 index 00000000000..f2709e3fbc2 --- /dev/null +++ b/pkg/services/ngalert/api/tooling/definitions/time_intervals.go @@ -0,0 +1,19 @@ +package definitions + +// NOTE: These structs are needed to support the MuteTimings provisioning api in the open api client + +// swagger:model +type TimeIntervalItem struct { + Times []TimeIntervalTimeRange `json:"times,omitempty" hcl:"times,block"` + Weekdays *[]string `json:"weekdays,omitempty" hcl:"weekdays"` + DaysOfMonth *[]string `json:"days_of_month,omitempty" hcl:"days_of_month"` + Months *[]string `json:"months,omitempty" hcl:"months"` + Years *[]string `json:"years,omitempty" hcl:"years"` + Location *string `json:"location,omitempty" hcl:"location"` +} + +// swagger:model +type TimeIntervalTimeRange struct { + StartMinute string `json:"start_time" hcl:"start"` + EndMinute string `json:"end_time" hcl:"end"` +} diff --git a/pkg/services/ngalert/api/tooling/post.json b/pkg/services/ngalert/api/tooling/post.json index a8c9b24f49e..6f005554994 100644 --- a/pkg/services/ngalert/api/tooling/post.json +++ b/pkg/services/ngalert/api/tooling/post.json @@ -492,6 +492,12 @@ "name": { "type": "string" }, + "queriedDatasourceUIDs": { + "items": { + "type": "string" + }, + "type": "array" + }, "query": { "type": "string" }, @@ -521,9 +527,7 @@ } }, "required": [ - "uid", "name", - "folderUid", "query", "health", "type", @@ -3789,9 +3793,7 @@ } }, "required": [ - "uid", "name", - "folderUid", "query", "health", "type" @@ -4530,6 +4532,55 @@ "title": "TimeInterval represents a named set of time intervals for which a route should be muted.", "type": "object" }, + "TimeIntervalItem": { + "properties": { + "days_of_month": { + "items": { + "type": "string" + }, + "type": "array" + }, + "location": { + "type": "string" + }, + "months": { + "items": { + "type": "string" + }, + "type": "array" + }, + "times": { + "items": { + "$ref": "#/definitions/TimeIntervalTimeRange" + }, + "type": "array" + }, + "weekdays": { + "items": { + "type": "string" + }, + "type": "array" + }, + "years": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "type": "object" + }, + "TimeIntervalTimeRange": { + "properties": { + "end_time": { + "type": "string" + }, + "start_time": { + "type": "string" + } + }, + "type": "object" + }, "TimeRange": { "description": "Redefining this to avoid an import cycle", "properties": { @@ -4545,7 +4596,6 @@ "type": "object" }, "URL": { - "description": "The general form represented is:\n\n[scheme:][//[userinfo@]host][/]path[?query][#fragment]\n\nURLs that do not start with a slash after the scheme are interpreted as:\n\nscheme:opaque[?query][#fragment]\n\nThe Host field contains the host and port subcomponents of the URL.\nWhen the port is present, it is separated from the host with a colon.\nWhen the host is an IPv6 address, it must be enclosed in square brackets:\n\"[fe80::1]:80\". The [net.JoinHostPort] function combines a host and port\ninto a string suitable for the Host field, adding square brackets to\nthe host when necessary.\n\nNote that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/.\nA consequence is that it is impossible to tell which slashes in the Path were\nslashes in the raw URL and which were %2f. This distinction is rarely important,\nbut when it is, the code should use the [URL.EscapedPath] method, which preserves\nthe original encoding of Path.\n\nThe RawPath field is an optional field which is only set when the default\nencoding of Path is different from the escaped path. See the EscapedPath method\nfor more details.\n\nURL's String method uses the EscapedPath method to obtain the path.", "properties": { "ForceQuery": { "type": "boolean" @@ -4581,7 +4631,7 @@ "$ref": "#/definitions/Userinfo" } }, - "title": "A URL represents a parsed URL (technically, a URI reference).", + "title": "URL is a custom URL type that allows validation at configuration load time.", "type": "object" }, "UpdateRuleGroupResponse": { @@ -5112,7 +5162,6 @@ "type": "object" }, "gettableSilences": { - "description": "GettableSilences gettable silences", "items": { "$ref": "#/definitions/gettableSilence", "type": "object" diff --git a/pkg/services/ngalert/api/tooling/spec.json b/pkg/services/ngalert/api/tooling/spec.json index 1875f799b8b..bc9e62927f7 100644 --- a/pkg/services/ngalert/api/tooling/spec.json +++ b/pkg/services/ngalert/api/tooling/spec.json @@ -4547,9 +4547,7 @@ "description": "adapted from cortex", "type": "object", "required": [ - "uid", "name", - "folderUid", "query", "health", "type", @@ -4602,6 +4600,12 @@ "name": { "type": "string" }, + "queriedDatasourceUIDs": { + "type": "array", + "items": { + "type": "string" + } + }, "query": { "type": "string" }, @@ -7856,9 +7860,7 @@ "description": "adapted from cortex", "type": "object", "required": [ - "uid", "name", - "folderUid", "query", "health", "type" @@ -8630,6 +8632,55 @@ } } }, + "TimeIntervalItem": { + "type": "object", + "properties": { + "days_of_month": { + "type": "array", + "items": { + "type": "string" + } + }, + "location": { + "type": "string" + }, + "months": { + "type": "array", + "items": { + "type": "string" + } + }, + "times": { + "type": "array", + "items": { + "$ref": "#/definitions/TimeIntervalTimeRange" + } + }, + "weekdays": { + "type": "array", + "items": { + "type": "string" + } + }, + "years": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "TimeIntervalTimeRange": { + "type": "object", + "properties": { + "end_time": { + "type": "string" + }, + "start_time": { + "type": "string" + } + } + }, "TimeRange": { "description": "Redefining this to avoid an import cycle", "type": "object", @@ -8645,9 +8696,8 @@ } }, "URL": { - "description": "The general form represented is:\n\n[scheme:][//[userinfo@]host][/]path[?query][#fragment]\n\nURLs that do not start with a slash after the scheme are interpreted as:\n\nscheme:opaque[?query][#fragment]\n\nThe Host field contains the host and port subcomponents of the URL.\nWhen the port is present, it is separated from the host with a colon.\nWhen the host is an IPv6 address, it must be enclosed in square brackets:\n\"[fe80::1]:80\". The [net.JoinHostPort] function combines a host and port\ninto a string suitable for the Host field, adding square brackets to\nthe host when necessary.\n\nNote that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/.\nA consequence is that it is impossible to tell which slashes in the Path were\nslashes in the raw URL and which were %2f. This distinction is rarely important,\nbut when it is, the code should use the [URL.EscapedPath] method, which preserves\nthe original encoding of Path.\n\nThe RawPath field is an optional field which is only set when the default\nencoding of Path is different from the escaped path. See the EscapedPath method\nfor more details.\n\nURL's String method uses the EscapedPath method to obtain the path.", "type": "object", - "title": "A URL represents a parsed URL (technically, a URI reference).", + "title": "URL is a custom URL type that allows validation at configuration load time.", "properties": { "ForceQuery": { "type": "boolean" @@ -9212,7 +9262,6 @@ } }, "gettableSilences": { - "description": "GettableSilences gettable silences", "type": "array", "items": { "type": "object", diff --git a/public/api-enterprise-spec.json b/public/api-enterprise-spec.json index cc8046467ec..fdc686ac78f 100644 --- a/public/api-enterprise-spec.json +++ b/public/api-enterprise-spec.json @@ -3897,6 +3897,30 @@ } } }, + "CreateSnapshotRequestDTO": { + "type": "object", + "properties": { + "resourceTypes": { + "type": "array", + "items": { + "type": "string", + "enum": [ + "DASHBOARD", + "DATASOURCE", + "FOLDER", + "LIBRARY_ELEMENT", + "ALERT_RULE", + "ALERT_RULE_GROUP", + "CONTACT_POINT", + "NOTIFICATION_POLICY", + "NOTIFICATION_TEMPLATE", + "MUTE_TIMING", + "PLUGIN" + ] + } + } + } + }, "CreateSnapshotResponseDTO": { "type": "object", "properties": { @@ -6038,6 +6062,9 @@ "language": { "type": "string" }, + "locale": { + "type": "string" + }, "navbar": { "$ref": "#/definitions/NavbarPreference" }, @@ -6304,6 +6331,10 @@ "description": "Selected language (beta)", "type": "string" }, + "locale": { + "description": "Selected locale (beta)", + "type": "string" + }, "navbar": { "$ref": "#/definitions/NavbarPreference" }, @@ -6942,6 +6973,57 @@ } } }, + "ResourceDependenciesResponseDTO": { + "type": "object", + "properties": { + "resourceDependencies": { + "type": "array", + "items": { + "$ref": "#/definitions/ResourceDependencyDTO" + } + } + } + }, + "ResourceDependencyDTO": { + "type": "object", + "properties": { + "dependencies": { + "type": "array", + "items": { + "type": "string", + "enum": [ + "DASHBOARD", + "DATASOURCE", + "FOLDER", + "LIBRARY_ELEMENT", + "ALERT_RULE", + "ALERT_RULE_GROUP", + "CONTACT_POINT", + "NOTIFICATION_POLICY", + "NOTIFICATION_TEMPLATE", + "MUTE_TIMING", + "PLUGIN" + ] + } + }, + "resourceType": { + "type": "string", + "enum": [ + "DASHBOARD", + "DATASOURCE", + "FOLDER", + "LIBRARY_ELEMENT", + "ALERT_RULE", + "ALERT_RULE_GROUP", + "CONTACT_POINT", + "NOTIFICATION_POLICY", + "NOTIFICATION_TEMPLATE", + "MUTE_TIMING", + "PLUGIN" + ] + } + } + }, "Responses": { "description": "The QueryData method the QueryDataHandler method will set the RefId\nproperty on the DataResponses' frames based on these RefIDs.", "type": "object", @@ -7682,10 +7764,16 @@ "email": { "type": "string" }, + "externalUID": { + "type": "string" + }, "id": { "type": "integer", "format": "int64" }, + "isProvisioned": { + "type": "boolean" + }, "memberCount": { "type": "integer", "format": "int64" @@ -7798,6 +7886,9 @@ "userId": { "type": "integer", "format": "int64" + }, + "userUID": { + "type": "string" } } }, @@ -8379,6 +8470,9 @@ "language": { "type": "string" }, + "locale": { + "type": "string" + }, "navbar": { "$ref": "#/definitions/NavbarPreference" }, @@ -10154,6 +10248,12 @@ "$ref": "#/definitions/ActiveUserStats" } }, + "resourceDependenciesResponse": { + "description": "", + "schema": { + "$ref": "#/definitions/ResourceDependenciesResponseDTO" + } + }, "resourcePermissionsDescription": { "description": "", "schema": { diff --git a/public/api-merged.json b/public/api-merged.json index 0d448848112..aa6563b5c1c 100644 --- a/public/api-merged.json +++ b/public/api-merged.json @@ -12858,9 +12858,7 @@ "description": "adapted from cortex", "type": "object", "required": [ - "uid", "name", - "folderUid", "query", "health", "type", @@ -12913,6 +12911,12 @@ "name": { "type": "string" }, + "queriedDatasourceUIDs": { + "type": "array", + "items": { + "type": "string" + } + }, "query": { "type": "string" }, @@ -20132,9 +20136,7 @@ "description": "adapted from cortex", "type": "object", "required": [ - "uid", "name", - "folderUid", "query", "health", "type" @@ -21684,6 +21686,55 @@ } } }, + "TimeIntervalItem": { + "type": "object", + "properties": { + "days_of_month": { + "type": "array", + "items": { + "type": "string" + } + }, + "location": { + "type": "string" + }, + "months": { + "type": "array", + "items": { + "type": "string" + } + }, + "times": { + "type": "array", + "items": { + "$ref": "#/definitions/TimeIntervalTimeRange" + } + }, + "weekdays": { + "type": "array", + "items": { + "type": "string" + } + }, + "years": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "TimeIntervalTimeRange": { + "type": "object", + "properties": { + "end_time": { + "type": "string" + }, + "start_time": { + "type": "string" + } + } + }, "TimeRange": { "description": "Redefining this to avoid an import cycle", "type": "object", @@ -22973,6 +23024,7 @@ } }, "gettableAlerts": { + "description": "GettableAlerts gettable alerts", "type": "array", "items": { "type": "object", @@ -23097,6 +23149,7 @@ } }, "gettableSilences": { + "description": "GettableSilences gettable silences", "type": "array", "items": { "type": "object", diff --git a/public/openapi3.json b/public/openapi3.json index 562042acc6d..fe5310802bb 100644 --- a/public/openapi3.json +++ b/public/openapi3.json @@ -2963,6 +2963,12 @@ "name": { "type": "string" }, + "queriedDatasourceUIDs": { + "items": { + "type": "string" + }, + "type": "array" + }, "query": { "type": "string" }, @@ -2992,9 +2998,7 @@ } }, "required": [ - "uid", "name", - "folderUid", "query", "health", "type", @@ -10227,9 +10231,7 @@ } }, "required": [ - "uid", "name", - "folderUid", "query", "health", "type" @@ -11745,6 +11747,55 @@ "title": "TimeInterval represents a named set of time intervals for which a route should be muted.", "type": "object" }, + "TimeIntervalItem": { + "properties": { + "days_of_month": { + "items": { + "type": "string" + }, + "type": "array" + }, + "location": { + "type": "string" + }, + "months": { + "items": { + "type": "string" + }, + "type": "array" + }, + "times": { + "items": { + "$ref": "#/components/schemas/TimeIntervalTimeRange" + }, + "type": "array" + }, + "weekdays": { + "items": { + "type": "string" + }, + "type": "array" + }, + "years": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "type": "object" + }, + "TimeIntervalTimeRange": { + "properties": { + "end_time": { + "type": "string" + }, + "start_time": { + "type": "string" + } + }, + "type": "object" + }, "TimeRange": { "description": "Redefining this to avoid an import cycle", "properties": { @@ -13033,6 +13084,7 @@ "type": "object" }, "gettableAlerts": { + "description": "GettableAlerts gettable alerts", "items": { "$ref": "#/components/schemas/gettableAlert" }, @@ -13156,6 +13208,7 @@ "type": "object" }, "gettableSilences": { + "description": "GettableSilences gettable silences", "items": { "$ref": "#/components/schemas/gettableSilence" },