From e9ec87dc67a7a8d147d6d57954512706e823eec1 Mon Sep 17 00:00:00 2001 From: Domas Date: Mon, 22 Feb 2021 16:51:31 +0200 Subject: [PATCH] fix silences --- pkg/api/alertmanager.go | 23 +++++------ spec.json | 86 +++++++++++++++++++++++++++-------------- 2 files changed, 68 insertions(+), 41 deletions(-) diff --git a/pkg/api/alertmanager.go b/pkg/api/alertmanager.go index f687da7cc7d..2e7f8f39e20 100644 --- a/pkg/api/alertmanager.go +++ b/pkg/api/alertmanager.go @@ -59,7 +59,7 @@ import ( // get silences // // Responses: -// 200: Silences +// 200: GettableSilences // 400: ValidationError // swagger:route POST /api/v1/silences alertmanager RouteCreateSilence @@ -67,7 +67,7 @@ import ( // create silence // // Responses: -// 201: Silence +// 201: GettableSilence // 400: ValidationError // swagger:route GET /api/v1/silence/{SilenceId} alertmanager RouteGetSilence @@ -75,7 +75,7 @@ import ( // get silence // // Responses: -// 200: Silence +// 200: GettableSilence // 400: ValidationError // swagger:route DELETE /api/v1/silence/{SilenceId} alertmanager RouteDeleteSilence @@ -88,13 +88,8 @@ import ( // swagger:parameters RouteCreateSilence type CreateSilenceParams struct { - // ID of any existing silence to overwrite // in:body - // required: false - Id string `json:"id"` - - // in:body - Body Silence + Body SilenceBody } //swagger:parameters RouteGetSilence RouteDeleteSilence @@ -104,10 +99,16 @@ type GetDeleteSilenceParams struct { } // swagger:model -type Silence amv2.Silence +type SilenceBody struct { + Idd string `json:"id"` + amv2.Silence +} // swagger:model -type Silences []amv2.Silence +type GettableSilences []amv2.GettableSilences + +// swagger:model +type GetableSilence amv2.Silence // swagger:model type GettableAlerts amv2.GettableAlerts diff --git a/spec.json b/spec.json index f01dc6d04ae..902ef53a00e 100644 --- a/spec.json +++ b/spec.json @@ -510,10 +510,7 @@ ], "responses": { "200": { - "description": "Silence", - "schema": { - "$ref": "#/definitions/Silence" - } + "$ref": "#/responses/GettableSilence" }, "400": { "description": "ValidationError", @@ -562,9 +559,9 @@ "operationId": "RouteGetSilences", "responses": { "200": { - "description": "Silences", + "description": "GettableSilences", "schema": { - "$ref": "#/definitions/Silences" + "$ref": "#/definitions/GettableSilences" } }, "400": { @@ -582,29 +579,17 @@ ], "operationId": "RouteCreateSilence", "parameters": [ - { - "x-go-name": "Id", - "description": "ID of any existing silence to overwrite", - "name": "id", - "in": "body", - "schema": { - "type": "string" - } - }, { "name": "Body", "in": "body", "schema": { - "$ref": "#/definitions/Silence" + "$ref": "#/definitions/SilenceBody" } } ], "responses": { "201": { - "description": "Silence", - "schema": { - "$ref": "#/definitions/Silence" - } + "$ref": "#/responses/GettableSilence" }, "400": { "description": "ValidationError", @@ -1310,9 +1295,19 @@ }, "x-go-package": "github.com/grafana/alerting-api/pkg/api" }, + "GetableSilence": { + "$ref": "#/definitions/silence" + }, "GettableAlerts": { "$ref": "#/definitions/gettableAlerts" }, + "GettableSilences": { + "type": "array", + "items": { + "$ref": "#/definitions/gettableSilences" + }, + "x-go-package": "github.com/grafana/alerting-api/pkg/api" + }, "GlobalConfig": { "description": "GlobalConfig defines configuration parameters that are valid globally\nunless overwritten.", "type": "object", @@ -2110,13 +2105,45 @@ }, "x-go-package": "github.com/grafana/grafana/pkg/components/securejsondata" }, - "Silence": { - "$ref": "#/definitions/silence" - }, - "Silences": { - "type": "array", - "items": { - "$ref": "#/definitions/silence" + "SilenceBody": { + "type": "object", + "required": [ + "comment", + "createdBy", + "endsAt", + "matchers", + "startsAt" + ], + "properties": { + "comment": { + "description": "comment", + "type": "string", + "x-go-name": "Comment" + }, + "createdBy": { + "description": "created by", + "type": "string", + "x-go-name": "CreatedBy" + }, + "endsAt": { + "description": "ends at", + "type": "string", + "format": "date-time", + "x-go-name": "EndsAt" + }, + "id": { + "type": "string", + "x-go-name": "Idd" + }, + "matchers": { + "$ref": "#/definitions/matchers" + }, + "startsAt": { + "description": "starts at", + "type": "string", + "format": "date-time", + "x-go-name": "StartsAt" + } }, "x-go-package": "github.com/grafana/alerting-api/pkg/api" }, @@ -2329,9 +2356,8 @@ "x-go-package": "github.com/prometheus/common/config" }, "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" @@ -2364,7 +2390,7 @@ "$ref": "#/definitions/Userinfo" } }, - "x-go-package": "net/url" + "x-go-package": "github.com/prometheus/common/config" }, "UpdateDashboardAclCommand": { "type": "object",