Skip to content

Commit

Permalink
api/v2: Delete silence respond with 404 when silence is not found (pr…
Browse files Browse the repository at this point in the history
…ometheus#3352)

Signed-off-by: Emmanuel Lodovice <[email protected]>
  • Loading branch information
emanlodovice authored and radek-ryckowski committed Nov 6, 2023
1 parent 5dd926a commit f8bb27e
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 1 deletion.
3 changes: 3 additions & 0 deletions api/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ func (api *API) deleteSilenceHandler(params silence_ops.DeleteSilenceParams) mid
sid := params.SilenceID.String()
if err := api.silences.Expire(sid); err != nil {
level.Error(logger).Log("msg", "Failed to expire silence", "err", err)
if err == silence.ErrNotFound {
return silence_ops.NewDeleteSilenceNotFound()
}
return silence_ops.NewDeleteSilenceInternalServerError().WithPayload(err.Error())
}
return silence_ops.NewDeleteSilenceOK()
Expand Down
2 changes: 1 addition & 1 deletion api/v2/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func TestDeleteSilenceHandler(t *testing.T) {
}{
{
"unknownSid",
500,
404,
},
{
unexpiredSid,
Expand Down
57 changes: 57 additions & 0 deletions api/v2/client/silence/delete_silence_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ paths:
responses:
'200':
description: Delete silence response
'404':
description: A silence with the specified ID was not found
'500':
$ref: '#/responses/InternalServerError'
/alerts:
Expand Down
6 changes: 6 additions & 0 deletions api/v2/restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions api/v2/restapi/operations/silence/delete_silence_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f8bb27e

Please sign in to comment.