diff --git a/pkg/services/ngalert/api/Makefile b/pkg/services/ngalert/api/Makefile index c84ba1c7ebe..68828e51b6c 100644 --- a/pkg/services/ngalert/api/Makefile +++ b/pkg/services/ngalert/api/Makefile @@ -19,6 +19,7 @@ copy-files: fix: sed -i -e 's/apimodels\.\[\]PostableAlert/apimodels.PostableAlerts/' $(GENERATED_GO_MATCHERS) sed -i -e 's/apimodels\.\[\]UpdateDashboardAclCommand/apimodels.Permissions/' $(GENERATED_GO_MATCHERS) + sed -i -e 's/apimodels\.\[\]PostableApiReceiver/apimodels.TestReceiversConfigParams/' $(GENERATED_GO_MATCHERS) goimports -w -v $(GENERATED_GO_MATCHERS) clean: diff --git a/pkg/services/ngalert/api/api_testing.go b/pkg/services/ngalert/api/api_testing.go index a55bebd0853..f56d296b500 100644 --- a/pkg/services/ngalert/api/api_testing.go +++ b/pkg/services/ngalert/api/api_testing.go @@ -15,7 +15,6 @@ import ( "github.com/grafana/grafana/pkg/services/ngalert/eval" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tsdb" - "github.com/grafana/grafana/pkg/util" ) type TestingApiSrv struct { @@ -26,11 +25,6 @@ type TestingApiSrv struct { log log.Logger } -func (srv TestingApiSrv) RouteTestReceiverConfig(c *models.ReqContext, body apimodels.ExtendedReceiver) response.Response { - srv.log.Info("RouteTestReceiverConfig: ", "body", body) - return response.JSON(http.StatusOK, util.DynMap{"message": "success"}) -} - func (srv TestingApiSrv) RouteTestRuleConfig(c *models.ReqContext, body apimodels.TestRulePayload) response.Response { recipient := c.Params("Recipient") if recipient == apimodels.GrafanaBackend.String() { diff --git a/pkg/services/ngalert/api/generated_base_api_testing.go b/pkg/services/ngalert/api/generated_base_api_testing.go index 03aee5611f4..bf4dc80c138 100644 --- a/pkg/services/ngalert/api/generated_base_api_testing.go +++ b/pkg/services/ngalert/api/generated_base_api_testing.go @@ -21,7 +21,6 @@ import ( type TestingApiService interface { RouteEvalQueries(*models.ReqContext, apimodels.EvalQueriesPayload) response.Response - RouteTestReceiverConfig(*models.ReqContext, apimodels.ExtendedReceiver) response.Response RouteTestRuleConfig(*models.ReqContext, apimodels.TestRulePayload) response.Response } @@ -37,16 +36,6 @@ func (api *API) RegisterTestingApiEndpoints(srv TestingApiService, m *metrics.Me m, ), ) - group.Post( - toMacaronPath("/api/v1/receiver/test/{Recipient}"), - binding.Bind(apimodels.ExtendedReceiver{}), - metrics.Instrument( - http.MethodPost, - "/api/v1/receiver/test/{Recipient}", - srv.RouteTestReceiverConfig, - m, - ), - ) group.Post( toMacaronPath("/api/v1/rule/test/{Recipient}"), binding.Bind(apimodels.TestRulePayload{}), diff --git a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go index 74fa1491263..70490733096 100644 --- a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go +++ b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go @@ -83,7 +83,10 @@ import ( // 200: Ack // 207: MultiStatus // 400: ValidationError +// 403: PermissionDenied +// 404: AlertManagerNotFound // 408: Failure +// 409: AlertManagerNotReady // swagger:route GET /api/alertmanager/{Recipient}/api/v2/silences alertmanager RouteGetSilences // @@ -118,12 +121,20 @@ import ( // 400: ValidationError // swagger:model -type TestReceiversConfig struct { - Receivers []*PostableApiReceiver `yaml:"receivers,omitempty" json:"receivers,omitempty"` -} +type PermissionDenied struct{} + +// swagger:model +type AlertManagerNotFound struct{} + +// swagger:model +type AlertManagerNotReady struct{} + +// swagger:model +type MultiStatus struct{} // swagger:parameters RoutePostTestReceivers type TestReceiversConfigParams struct { + // in:body Receivers []*PostableApiReceiver `yaml:"receivers,omitempty" json:"receivers,omitempty"` } @@ -311,7 +322,7 @@ type BodyAlertingConfig struct { } // alertmanager routes -// swagger:parameters RoutePostAlertingConfig RouteGetAlertingConfig RouteDeleteAlertingConfig RouteGetAMStatus RouteGetAMAlerts RoutePostAMAlerts RouteGetAMAlertGroups RouteGetSilences RouteCreateSilence RouteGetSilence RouteDeleteSilence RoutePostAlertingConfig +// swagger:parameters RoutePostAlertingConfig RouteGetAlertingConfig RouteDeleteAlertingConfig RouteGetAMStatus RouteGetAMAlerts RoutePostAMAlerts RouteGetAMAlertGroups RouteGetSilences RouteCreateSilence RouteGetSilence RouteDeleteSilence RoutePostAlertingConfig RoutePostTestReceivers // ruler routes // swagger:parameters RouteGetRulesConfig RoutePostNameRulesConfig RouteGetNamespaceRulesConfig RouteDeleteNamespaceRulesConfig RouteGetRulegGroupConfig RouteDeleteRuleGroupConfig // prom routes diff --git a/pkg/services/ngalert/api/tooling/definitions/testing.go b/pkg/services/ngalert/api/tooling/definitions/testing.go index adc2d52ee54..4e01fbf3ec1 100644 --- a/pkg/services/ngalert/api/tooling/definitions/testing.go +++ b/pkg/services/ngalert/api/tooling/definitions/testing.go @@ -12,21 +12,6 @@ import ( "github.com/prometheus/prometheus/promql" ) -// swagger:route Post /api/v1/receiver/test/{Recipient} testing RouteTestReceiverConfig -// -// Test receiver -// -// Consumes: -// - application/json -// -// Produces: -// - application/json -// -// Responses: -// 200: Success -// 412: SmtpNotEnabled -// 500: Failure - // swagger:route Post /api/v1/rule/test/{Recipient} testing RouteTestRuleConfig // // Test rule diff --git a/pkg/services/ngalert/api/tooling/post.json b/pkg/services/ngalert/api/tooling/post.json index a2a6aee0e6a..6cc9506a9e4 100644 --- a/pkg/services/ngalert/api/tooling/post.json +++ b/pkg/services/ngalert/api/tooling/post.json @@ -86,6 +86,14 @@ "type": "object", "x-go-package": "github.com/prometheus/client_golang/api/prometheus/v1" }, + "AlertManagerNotFound": { + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + }, + "AlertManagerNotReady": { + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + }, "AlertManagersResult": { "properties": { "activeAlertManagers": { @@ -1095,6 +1103,10 @@ }, "type": "array" }, + "MultiStatus": { + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + }, "NamespaceConfigResponse": { "additionalProperties": { "items": { @@ -1340,6 +1352,10 @@ "type": "object", "x-go-package": "github.com/prometheus/alertmanager/config" }, + "PermissionDenied": { + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + }, "Point": { "properties": { "T": { @@ -2286,19 +2302,6 @@ "type": "object", "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, - "TestReceiversConfig": { - "properties": { - "receivers": { - "items": { - "$ref": "#/definitions/PostableApiReceiver" - }, - "type": "array", - "x-go-name": "Receivers" - } - }, - "type": "object", - "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" - }, "TestReceiversResult": { "properties": { "notified_at": { @@ -2344,7 +2347,6 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "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\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 RawPath, an optional field which only gets\nset if the default encoding is different from Path.\n\nURL's String method uses the EscapedPath method to obtain the path. See the\nEscapedPath method for more details.", "properties": { "ForceQuery": { "type": "boolean" @@ -2377,9 +2379,9 @@ "$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", - "x-go-package": "net/url" + "x-go-package": "github.com/prometheus/common/config" }, "Userinfo": { "description": "The Userinfo type is an immutable encapsulation of username and\npassword details for a URL. An existing Userinfo value is guaranteed\nto have a username set (potentially empty, as allowed by RFC 2396),\nand optionally a password.", @@ -2546,6 +2548,7 @@ "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" }, "alertGroup": { + "description": "AlertGroup alert group", "properties": { "alerts": { "description": "alerts", @@ -2567,17 +2570,14 @@ "labels", "receiver" ], - "type": "object", - "x-go-name": "AlertGroup", - "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" + "type": "object" }, "alertGroups": { + "description": "AlertGroups alert groups", "items": { "$ref": "#/definitions/alertGroup" }, - "type": "array", - "x-go-name": "AlertGroups", - "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" + "type": "array" }, "alertStatus": { "description": "AlertStatus alert status", @@ -2697,7 +2697,6 @@ "$ref": "#/definitions/Duration" }, "gettableAlert": { - "description": "GettableAlert gettable alert", "properties": { "annotations": { "$ref": "#/definitions/labelSet" @@ -2756,7 +2755,9 @@ "status", "updatedAt" ], - "type": "object" + "type": "object", + "x-go-name": "GettableAlert", + "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" }, "gettableAlerts": { "items": { @@ -2767,7 +2768,6 @@ "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" }, "gettableSilence": { - "description": "GettableSilence gettable silence", "properties": { "comment": { "description": "comment", @@ -2819,7 +2819,9 @@ "status", "updatedAt" ], - "type": "object" + "type": "object", + "x-go-name": "GettableSilence", + "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" }, "gettableSilences": { "items": { @@ -2956,6 +2958,7 @@ "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" }, "postableSilence": { + "description": "PostableSilence postable silence", "properties": { "comment": { "description": "comment", @@ -2995,12 +2998,9 @@ "matchers", "startsAt" ], - "type": "object", - "x-go-name": "PostableSilence", - "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" + "type": "object" }, "receiver": { - "description": "Receiver receiver", "properties": { "name": { "description": "name", @@ -3011,7 +3011,9 @@ "required": [ "name" ], - "type": "object" + "type": "object", + "x-go-name": "Receiver", + "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" }, "silence": { "description": "Silence silence", @@ -3599,13 +3601,22 @@ "operationId": "RoutePostTestReceivers", "parameters": [ { - "in": "query", - "items": { - "$ref": "#/definitions/PostableApiReceiver" - }, + "in": "body", "name": "receivers", - "type": "array", + "schema": { + "items": { + "$ref": "#/definitions/PostableApiReceiver" + }, + "type": "array" + }, "x-go-name": "Receivers" + }, + { + "description": "Recipient should be \"grafana\" for requests to be handled by grafana\nand the numeric datasource id for requests to be forwarded to a datasource", + "in": "path", + "name": "Recipient", + "required": true, + "type": "string" } ], "responses": { @@ -3616,7 +3627,10 @@ } }, "207": { - "$ref": "#/responses/MultiStatus" + "description": "MultiStatus", + "schema": { + "$ref": "#/definitions/MultiStatus" + } }, "400": { "description": "ValidationError", @@ -3624,11 +3638,29 @@ "$ref": "#/definitions/ValidationError" } }, + "403": { + "description": "PermissionDenied", + "schema": { + "$ref": "#/definitions/PermissionDenied" + } + }, + "404": { + "description": "AlertManagerNotFound", + "schema": { + "$ref": "#/definitions/AlertManagerNotFound" + } + }, "408": { "description": "Failure", "schema": { "$ref": "#/definitions/Failure" } + }, + "409": { + "description": "AlertManagerNotReady", + "schema": { + "$ref": "#/definitions/AlertManagerNotReady" + } } }, "summary": "Test Grafana managed receivers without saving them.", @@ -4042,57 +4074,6 @@ ] } }, - "/api/v1/receiver/test/{Recipient}": { - "post": { - "consumes": [ - "application/json" - ], - "description": "Test receiver", - "operationId": "RouteTestReceiverConfig", - "parameters": [ - { - "description": "Recipient should be \"grafana\" for requests to be handled by grafana\nand the numeric datasource id for requests to be forwarded to a datasource", - "in": "path", - "name": "Recipient", - "required": true, - "type": "string" - }, - { - "in": "body", - "name": "Body", - "schema": { - "$ref": "#/definitions/ExtendedReceiver" - } - } - ], - "produces": [ - "application/json" - ], - "responses": { - "200": { - "description": "Success", - "schema": { - "$ref": "#/definitions/Success" - } - }, - "412": { - "description": "SmtpNotEnabled", - "schema": { - "$ref": "#/definitions/SmtpNotEnabled" - } - }, - "500": { - "description": "Failure", - "schema": { - "$ref": "#/definitions/Failure" - } - } - }, - "tags": [ - "testing" - ] - } - }, "/api/v1/rule/test/{Recipient}": { "post": { "consumes": [ diff --git a/pkg/services/ngalert/api/tooling/spec.json b/pkg/services/ngalert/api/tooling/spec.json index 648f972a350..6e89b3344de 100644 --- a/pkg/services/ngalert/api/tooling/spec.json +++ b/pkg/services/ngalert/api/tooling/spec.json @@ -494,13 +494,22 @@ "operationId": "RoutePostTestReceivers", "parameters": [ { - "type": "array", - "items": { - "$ref": "#/definitions/PostableApiReceiver" - }, "x-go-name": "Receivers", "name": "receivers", - "in": "query" + "in": "body", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/PostableApiReceiver" + } + } + }, + { + "type": "string", + "description": "Recipient should be \"grafana\" for requests to be handled by grafana\nand the numeric datasource id for requests to be forwarded to a datasource", + "name": "Recipient", + "in": "path", + "required": true } ], "responses": { @@ -511,7 +520,10 @@ } }, "207": { - "$ref": "#/responses/MultiStatus" + "description": "MultiStatus", + "schema": { + "$ref": "#/definitions/MultiStatus" + } }, "400": { "description": "ValidationError", @@ -519,11 +531,29 @@ "$ref": "#/definitions/ValidationError" } }, + "403": { + "description": "PermissionDenied", + "schema": { + "$ref": "#/definitions/PermissionDenied" + } + }, + "404": { + "description": "AlertManagerNotFound", + "schema": { + "$ref": "#/definitions/AlertManagerNotFound" + } + }, "408": { "description": "Failure", "schema": { "$ref": "#/definitions/Failure" } + }, + "409": { + "description": "AlertManagerNotReady", + "schema": { + "$ref": "#/definitions/AlertManagerNotReady" + } } } } @@ -933,57 +963,6 @@ } } }, - "/api/v1/receiver/test/{Recipient}": { - "post": { - "description": "Test receiver", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "testing" - ], - "operationId": "RouteTestReceiverConfig", - "parameters": [ - { - "type": "string", - "description": "Recipient should be \"grafana\" for requests to be handled by grafana\nand the numeric datasource id for requests to be forwarded to a datasource", - "name": "Recipient", - "in": "path", - "required": true - }, - { - "name": "Body", - "in": "body", - "schema": { - "$ref": "#/definitions/ExtendedReceiver" - } - } - ], - "responses": { - "200": { - "description": "Success", - "schema": { - "$ref": "#/definitions/Success" - } - }, - "412": { - "description": "SmtpNotEnabled", - "schema": { - "$ref": "#/definitions/SmtpNotEnabled" - } - }, - "500": { - "description": "Failure", - "schema": { - "$ref": "#/definitions/Failure" - } - } - } - } - }, "/api/v1/rule/test/{Recipient}": { "post": { "description": "Test rule", @@ -1107,6 +1086,14 @@ }, "x-go-package": "github.com/prometheus/client_golang/api/prometheus/v1" }, + "AlertManagerNotFound": { + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + }, + "AlertManagerNotReady": { + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + }, "AlertManagersResult": { "type": "object", "title": "AlertManagersResult contains the result from querying the alertmanagers endpoint.", @@ -2120,6 +2107,10 @@ }, "$ref": "#/definitions/Matchers" }, + "MultiStatus": { + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + }, "NamespaceConfigResponse": { "type": "object", "additionalProperties": { @@ -2365,6 +2356,10 @@ }, "x-go-package": "github.com/prometheus/alertmanager/config" }, + "PermissionDenied": { + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + }, "Point": { "type": "object", "title": "Point represents a single data point for a given timestamp.", @@ -3311,19 +3306,6 @@ }, "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, - "TestReceiversConfig": { - "type": "object", - "properties": { - "receivers": { - "type": "array", - "items": { - "$ref": "#/definitions/PostableApiReceiver" - }, - "x-go-name": "Receivers" - } - }, - "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" - }, "TestReceiversResult": { "type": "object", "properties": { @@ -3369,9 +3351,8 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "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\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 RawPath, an optional field which only gets\nset if the default encoding is different from Path.\n\nURL's String method uses the EscapedPath method to obtain the path. See the\nEscapedPath method for more details.", "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" @@ -3404,7 +3385,7 @@ "$ref": "#/definitions/Userinfo" } }, - "x-go-package": "net/url" + "x-go-package": "github.com/prometheus/common/config" }, "Userinfo": { "description": "The Userinfo type is an immutable encapsulation of username and\npassword details for a URL. An existing Userinfo value is guaranteed\nto have a username set (potentially empty, as allowed by RFC 2396),\nand optionally a password.", @@ -3571,6 +3552,7 @@ "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" }, "alertGroup": { + "description": "AlertGroup alert group", "type": "object", "required": [ "alerts", @@ -3593,17 +3575,14 @@ "$ref": "#/definitions/receiver" } }, - "x-go-name": "AlertGroup", - "x-go-package": "github.com/prometheus/alertmanager/api/v2/models", "$ref": "#/definitions/alertGroup" }, "alertGroups": { + "description": "AlertGroups alert groups", "type": "array", "items": { "$ref": "#/definitions/alertGroup" }, - "x-go-name": "AlertGroups", - "x-go-package": "github.com/prometheus/alertmanager/api/v2/models", "$ref": "#/definitions/alertGroups" }, "alertStatus": { @@ -3724,7 +3703,6 @@ "$ref": "#/definitions/Duration" }, "gettableAlert": { - "description": "GettableAlert gettable alert", "type": "object", "required": [ "labels", @@ -3784,6 +3762,8 @@ "x-go-name": "UpdatedAt" } }, + "x-go-name": "GettableAlert", + "x-go-package": "github.com/prometheus/alertmanager/api/v2/models", "$ref": "#/definitions/gettableAlert" }, "gettableAlerts": { @@ -3796,7 +3776,6 @@ "$ref": "#/definitions/gettableAlerts" }, "gettableSilence": { - "description": "GettableSilence gettable silence", "type": "object", "required": [ "comment", @@ -3849,6 +3828,8 @@ "x-go-name": "UpdatedAt" } }, + "x-go-name": "GettableSilence", + "x-go-package": "github.com/prometheus/alertmanager/api/v2/models", "$ref": "#/definitions/gettableSilence" }, "gettableSilences": { @@ -3987,6 +3968,7 @@ "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" }, "postableSilence": { + "description": "PostableSilence postable silence", "type": "object", "required": [ "comment", @@ -4027,12 +4009,9 @@ "x-go-name": "StartsAt" } }, - "x-go-name": "PostableSilence", - "x-go-package": "github.com/prometheus/alertmanager/api/v2/models", "$ref": "#/definitions/postableSilence" }, "receiver": { - "description": "Receiver receiver", "type": "object", "required": [ "name" @@ -4044,6 +4023,8 @@ "x-go-name": "Name" } }, + "x-go-name": "Receiver", + "x-go-package": "github.com/prometheus/alertmanager/api/v2/models", "$ref": "#/definitions/receiver" }, "silence": {