Alerting: Fix path for cortex-style Prometheus namespaces conversion endpoint (#103655)
This commit is contained in:
committed by
GitHub
parent
39dcff23f9
commit
babe188e31
@@ -1284,6 +1284,46 @@ func createRequestCtx() *contextmodel.ReqContext {
|
||||
}
|
||||
}
|
||||
|
||||
// Test parseBooleanHeader function which handles boolean header values
|
||||
func TestParseBooleanHeader(t *testing.T) {
|
||||
headerName := "X-Test-Header"
|
||||
|
||||
t.Run("should return false when header is not present", func(t *testing.T) {
|
||||
result, err := parseBooleanHeader("", headerName)
|
||||
require.NoError(t, err)
|
||||
require.False(t, result)
|
||||
})
|
||||
|
||||
t.Run("should return true when header is 'true'", func(t *testing.T) {
|
||||
result, err := parseBooleanHeader("true", headerName)
|
||||
require.NoError(t, err)
|
||||
require.True(t, result)
|
||||
})
|
||||
|
||||
t.Run("should return false when header is 'false'", func(t *testing.T) {
|
||||
result, err := parseBooleanHeader("false", headerName)
|
||||
require.NoError(t, err)
|
||||
require.False(t, result)
|
||||
})
|
||||
|
||||
t.Run("should return true when header is 'TRUE' (case insensitive)", func(t *testing.T) {
|
||||
result, err := parseBooleanHeader("TRUE", headerName)
|
||||
require.NoError(t, err)
|
||||
require.True(t, result)
|
||||
})
|
||||
|
||||
t.Run("should return error when header has invalid value", func(t *testing.T) {
|
||||
_, err := parseBooleanHeader("invalid", headerName)
|
||||
require.Error(t, err)
|
||||
require.ErrorContains(t, err, "Invalid value for header")
|
||||
})
|
||||
|
||||
t.Run("should return error when header is numeric but not 0/1", func(t *testing.T) {
|
||||
_, err := parseBooleanHeader("2", headerName)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetWorkingFolderUID(t *testing.T) {
|
||||
t.Run("should return root folder UID when header is not present", func(t *testing.T) {
|
||||
rc := createRequestCtx()
|
||||
|
||||
@@ -130,7 +130,7 @@ func (api *API) authorize(method, path string) web.Handler {
|
||||
case http.MethodPost + "/api/convert/prometheus/config/v1/rules/{NamespaceTitle}",
|
||||
http.MethodPost + "/api/convert/api/prom/rules/{NamespaceTitle}",
|
||||
http.MethodPost + "/api/convert/prometheus/config/v1/rules",
|
||||
http.MethodPost + "/api/convert/api/prom/config/v1/rules":
|
||||
http.MethodPost + "/api/convert/api/prom/rules":
|
||||
eval = ac.EvalAll(
|
||||
ac.EvalPermission(ac.ActionAlertingRuleCreate),
|
||||
ac.EvalPermission(ac.ActionAlertingProvisioningSetStatus),
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestAuthorize(t *testing.T) {
|
||||
}
|
||||
paths[p] = methods
|
||||
}
|
||||
require.Len(t, paths, 64)
|
||||
require.Len(t, paths, 63)
|
||||
|
||||
ac := acmock.New()
|
||||
api := &API{AccessControl: ac, FeatureManager: featuremgmt.WithFeatures()}
|
||||
|
||||
@@ -177,13 +177,13 @@ func (api *API) RegisterConvertPrometheusApiEndpoints(srv ConvertPrometheusApi,
|
||||
),
|
||||
)
|
||||
group.Post(
|
||||
toMacaronPath("/api/convert/api/prom/config/v1/rules"),
|
||||
toMacaronPath("/api/convert/api/prom/rules"),
|
||||
requestmeta.SetOwner(requestmeta.TeamAlerting),
|
||||
requestmeta.SetSLOGroup(requestmeta.SLOGroupHighSlow),
|
||||
api.authorize(http.MethodPost, "/api/convert/api/prom/config/v1/rules"),
|
||||
api.authorize(http.MethodPost, "/api/convert/api/prom/rules"),
|
||||
metrics.Instrument(
|
||||
http.MethodPost,
|
||||
"/api/convert/api/prom/config/v1/rules",
|
||||
"/api/convert/api/prom/rules",
|
||||
api.Hooks.Wrap(srv.RouteConvertPrometheusCortexPostRuleGroups),
|
||||
m,
|
||||
),
|
||||
|
||||
@@ -1454,6 +1454,12 @@
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"jira_configs": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/JiraConfig"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"msteams_configs": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/MSTeamsConfig"
|
||||
@@ -1815,6 +1821,9 @@
|
||||
"http_config": {
|
||||
"$ref": "#/definitions/HTTPClientConfig"
|
||||
},
|
||||
"jira_api_url": {
|
||||
"$ref": "#/definitions/URL"
|
||||
},
|
||||
"opsgenie_api_key": {
|
||||
"$ref": "#/definitions/Secret"
|
||||
},
|
||||
@@ -1863,6 +1872,9 @@
|
||||
"smtp_smarthost": {
|
||||
"$ref": "#/definitions/HostPort"
|
||||
},
|
||||
"smtp_tls_config": {
|
||||
"$ref": "#/definitions/TLSConfig"
|
||||
},
|
||||
"telegram_api_url": {
|
||||
"$ref": "#/definitions/URL"
|
||||
},
|
||||
@@ -2053,6 +2065,57 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"JiraConfig": {
|
||||
"properties": {
|
||||
"api_url": {
|
||||
"$ref": "#/definitions/URL"
|
||||
},
|
||||
"custom_fields": {
|
||||
"additionalProperties": {},
|
||||
"type": "object"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"http_config": {
|
||||
"$ref": "#/definitions/HTTPClientConfig"
|
||||
},
|
||||
"issue_type": {
|
||||
"type": "string"
|
||||
},
|
||||
"labels": {
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"priority": {
|
||||
"type": "string"
|
||||
},
|
||||
"project": {
|
||||
"type": "string"
|
||||
},
|
||||
"reopen_duration": {
|
||||
"$ref": "#/definitions/Duration"
|
||||
},
|
||||
"reopen_transition": {
|
||||
"type": "string"
|
||||
},
|
||||
"resolve_transition": {
|
||||
"type": "string"
|
||||
},
|
||||
"send_resolved": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"summary": {
|
||||
"type": "string"
|
||||
},
|
||||
"wont_fix_resolution": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"Json": {
|
||||
"type": "object"
|
||||
},
|
||||
@@ -2659,6 +2722,12 @@
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"jira_configs": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/JiraConfig"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"msteams_configs": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/MSTeamsConfig"
|
||||
@@ -3401,6 +3470,12 @@
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"jira_configs": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/JiraConfig"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"msteams_configs": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/MSTeamsConfig"
|
||||
@@ -4470,6 +4545,7 @@
|
||||
"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"
|
||||
@@ -4505,7 +4581,7 @@
|
||||
"$ref": "#/definitions/Userinfo"
|
||||
}
|
||||
},
|
||||
"title": "URL is a custom URL type that allows validation at configuration load time.",
|
||||
"title": "A URL represents a parsed URL (technically, a URI reference).",
|
||||
"type": "object"
|
||||
},
|
||||
"UpdateRuleGroupResponse": {
|
||||
@@ -4656,6 +4732,9 @@
|
||||
"send_resolved": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"timeout": {
|
||||
"$ref": "#/definitions/Duration"
|
||||
},
|
||||
"url": {
|
||||
"$ref": "#/definitions/SecretURL"
|
||||
},
|
||||
@@ -4747,6 +4826,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"alertGroups": {
|
||||
"description": "AlertGroups alert groups",
|
||||
"items": {
|
||||
"$ref": "#/definitions/alertGroup",
|
||||
"type": "object"
|
||||
@@ -4908,7 +4988,6 @@
|
||||
"type": "object"
|
||||
},
|
||||
"gettableAlerts": {
|
||||
"description": "GettableAlerts gettable alerts",
|
||||
"items": {
|
||||
"$ref": "#/definitions/gettableAlert",
|
||||
"type": "object"
|
||||
|
||||
@@ -97,7 +97,7 @@ import (
|
||||
// 202: ConvertPrometheusResponse
|
||||
// 403: ForbiddenError
|
||||
|
||||
// swagger:route POST /convert/api/prom/config/v1/rules convert_prometheus RouteConvertPrometheusCortexPostRuleGroups
|
||||
// swagger:route POST /convert/api/prom/rules convert_prometheus RouteConvertPrometheusCortexPostRuleGroups
|
||||
//
|
||||
// Converts the submitted rule groups into Grafana-Managed Rules.
|
||||
//
|
||||
|
||||
@@ -1454,6 +1454,12 @@
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"jira_configs": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/JiraConfig"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"msteams_configs": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/MSTeamsConfig"
|
||||
@@ -1815,6 +1821,9 @@
|
||||
"http_config": {
|
||||
"$ref": "#/definitions/HTTPClientConfig"
|
||||
},
|
||||
"jira_api_url": {
|
||||
"$ref": "#/definitions/URL"
|
||||
},
|
||||
"opsgenie_api_key": {
|
||||
"$ref": "#/definitions/Secret"
|
||||
},
|
||||
@@ -1863,6 +1872,9 @@
|
||||
"smtp_smarthost": {
|
||||
"$ref": "#/definitions/HostPort"
|
||||
},
|
||||
"smtp_tls_config": {
|
||||
"$ref": "#/definitions/TLSConfig"
|
||||
},
|
||||
"telegram_api_url": {
|
||||
"$ref": "#/definitions/URL"
|
||||
},
|
||||
@@ -2053,6 +2065,57 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"JiraConfig": {
|
||||
"properties": {
|
||||
"api_url": {
|
||||
"$ref": "#/definitions/URL"
|
||||
},
|
||||
"custom_fields": {
|
||||
"additionalProperties": {},
|
||||
"type": "object"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"http_config": {
|
||||
"$ref": "#/definitions/HTTPClientConfig"
|
||||
},
|
||||
"issue_type": {
|
||||
"type": "string"
|
||||
},
|
||||
"labels": {
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"priority": {
|
||||
"type": "string"
|
||||
},
|
||||
"project": {
|
||||
"type": "string"
|
||||
},
|
||||
"reopen_duration": {
|
||||
"$ref": "#/definitions/Duration"
|
||||
},
|
||||
"reopen_transition": {
|
||||
"type": "string"
|
||||
},
|
||||
"resolve_transition": {
|
||||
"type": "string"
|
||||
},
|
||||
"send_resolved": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"summary": {
|
||||
"type": "string"
|
||||
},
|
||||
"wont_fix_resolution": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"Json": {
|
||||
"type": "object"
|
||||
},
|
||||
@@ -2659,6 +2722,12 @@
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"jira_configs": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/JiraConfig"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"msteams_configs": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/MSTeamsConfig"
|
||||
@@ -3401,6 +3470,12 @@
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"jira_configs": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/JiraConfig"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"msteams_configs": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/MSTeamsConfig"
|
||||
@@ -4657,6 +4732,9 @@
|
||||
"send_resolved": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"timeout": {
|
||||
"$ref": "#/definitions/Duration"
|
||||
},
|
||||
"url": {
|
||||
"$ref": "#/definitions/SecretURL"
|
||||
},
|
||||
@@ -4909,6 +4987,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"gettableAlerts": {
|
||||
"description": "GettableAlerts gettable alerts",
|
||||
"items": {
|
||||
"$ref": "#/definitions/gettableAlert",
|
||||
"type": "object"
|
||||
@@ -6376,36 +6455,6 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/convert/api/prom/config/v1/rules": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/yaml"
|
||||
],
|
||||
"operationId": "RouteConvertPrometheusCortexPostRuleGroups",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"responses": {
|
||||
"202": {
|
||||
"description": "ConvertPrometheusResponse",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ConvertPrometheusResponse"
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "ForbiddenError",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ForbiddenError"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Converts the submitted rule groups into Grafana-Managed Rules.",
|
||||
"tags": [
|
||||
"convert_prometheus"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/convert/api/prom/rules": {
|
||||
"get": {
|
||||
"operationId": "RouteConvertPrometheusCortexGetRules",
|
||||
@@ -6436,6 +6485,34 @@
|
||||
"tags": [
|
||||
"convert_prometheus"
|
||||
]
|
||||
},
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/yaml"
|
||||
],
|
||||
"operationId": "RouteConvertPrometheusCortexPostRuleGroups",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"responses": {
|
||||
"202": {
|
||||
"description": "ConvertPrometheusResponse",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ConvertPrometheusResponse"
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "ForbiddenError",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ForbiddenError"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Converts the submitted rule groups into Grafana-Managed Rules.",
|
||||
"tags": [
|
||||
"convert_prometheus"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/convert/api/prom/rules/{NamespaceTitle}": {
|
||||
|
||||
@@ -1102,36 +1102,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/convert/api/prom/config/v1/rules": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/yaml"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"convert_prometheus"
|
||||
],
|
||||
"summary": "Converts the submitted rule groups into Grafana-Managed Rules.",
|
||||
"operationId": "RouteConvertPrometheusCortexPostRuleGroups",
|
||||
"responses": {
|
||||
"202": {
|
||||
"description": "ConvertPrometheusResponse",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ConvertPrometheusResponse"
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "ForbiddenError",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ForbiddenError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/convert/api/prom/rules": {
|
||||
"get": {
|
||||
"produces": [
|
||||
@@ -1162,6 +1132,34 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/yaml"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"convert_prometheus"
|
||||
],
|
||||
"summary": "Converts the submitted rule groups into Grafana-Managed Rules.",
|
||||
"operationId": "RouteConvertPrometheusCortexPostRuleGroups",
|
||||
"responses": {
|
||||
"202": {
|
||||
"description": "ConvertPrometheusResponse",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ConvertPrometheusResponse"
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "ForbiddenError",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ForbiddenError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/convert/api/prom/rules/{NamespaceTitle}": {
|
||||
@@ -5588,6 +5586,12 @@
|
||||
"$ref": "#/definitions/GettableGrafanaReceiver"
|
||||
}
|
||||
},
|
||||
"jira_configs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/JiraConfig"
|
||||
}
|
||||
},
|
||||
"msteams_configs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -5949,6 +5953,9 @@
|
||||
"http_config": {
|
||||
"$ref": "#/definitions/HTTPClientConfig"
|
||||
},
|
||||
"jira_api_url": {
|
||||
"$ref": "#/definitions/URL"
|
||||
},
|
||||
"opsgenie_api_key": {
|
||||
"$ref": "#/definitions/Secret"
|
||||
},
|
||||
@@ -5997,6 +6004,9 @@
|
||||
"smtp_smarthost": {
|
||||
"$ref": "#/definitions/HostPort"
|
||||
},
|
||||
"smtp_tls_config": {
|
||||
"$ref": "#/definitions/TLSConfig"
|
||||
},
|
||||
"telegram_api_url": {
|
||||
"$ref": "#/definitions/URL"
|
||||
},
|
||||
@@ -6186,6 +6196,57 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"JiraConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"api_url": {
|
||||
"$ref": "#/definitions/URL"
|
||||
},
|
||||
"custom_fields": {
|
||||
"type": "object",
|
||||
"additionalProperties": {}
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"http_config": {
|
||||
"$ref": "#/definitions/HTTPClientConfig"
|
||||
},
|
||||
"issue_type": {
|
||||
"type": "string"
|
||||
},
|
||||
"labels": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"priority": {
|
||||
"type": "string"
|
||||
},
|
||||
"project": {
|
||||
"type": "string"
|
||||
},
|
||||
"reopen_duration": {
|
||||
"$ref": "#/definitions/Duration"
|
||||
},
|
||||
"reopen_transition": {
|
||||
"type": "string"
|
||||
},
|
||||
"resolve_transition": {
|
||||
"type": "string"
|
||||
},
|
||||
"send_resolved": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"summary": {
|
||||
"type": "string"
|
||||
},
|
||||
"wont_fix_resolution": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Json": {
|
||||
"type": "object"
|
||||
},
|
||||
@@ -6794,6 +6855,12 @@
|
||||
"$ref": "#/definitions/PostableGrafanaReceiver"
|
||||
}
|
||||
},
|
||||
"jira_configs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/JiraConfig"
|
||||
}
|
||||
},
|
||||
"msteams_configs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -7537,6 +7604,12 @@
|
||||
"$ref": "#/definitions/EmailConfig"
|
||||
}
|
||||
},
|
||||
"jira_configs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/JiraConfig"
|
||||
}
|
||||
},
|
||||
"msteams_configs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -8793,6 +8866,9 @@
|
||||
"send_resolved": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"timeout": {
|
||||
"$ref": "#/definitions/Duration"
|
||||
},
|
||||
"url": {
|
||||
"$ref": "#/definitions/SecretURL"
|
||||
},
|
||||
@@ -9043,6 +9119,7 @@
|
||||
}
|
||||
},
|
||||
"gettableAlerts": {
|
||||
"description": "GettableAlerts gettable alerts",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
|
||||
Reference in New Issue
Block a user