Alerting: Support deleting rule groups in the provisioning API (#83514)

* Alerting: feat: support deleting rule groups in the provisioning API

Adds support for DELETE to the provisioning API's alert rule groups route, which allows deleting the rule group with a
single API call. Previously, groups were deleted by deleting rules one-by-one.

Fixes #81860

This change doesn't add any new paths to the API, only new methods.

---------

Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
This commit is contained in:
Joe Blubaugh
2024-02-28 10:19:02 -05:00
committed by GitHub
co-authored by Yuri Tseretyan
parent 467302480f
commit b905777ba9
12 changed files with 307 additions and 9 deletions
@@ -21,6 +21,7 @@ import (
type ProvisioningApi interface {
RouteDeleteAlertRule(*contextmodel.ReqContext) response.Response
RouteDeleteAlertRuleGroup(*contextmodel.ReqContext) response.Response
RouteDeleteContactpoints(*contextmodel.ReqContext) response.Response
RouteDeleteMuteTiming(*contextmodel.ReqContext) response.Response
RouteDeleteTemplate(*contextmodel.ReqContext) response.Response
@@ -57,6 +58,12 @@ func (f *ProvisioningApiHandler) RouteDeleteAlertRule(ctx *contextmodel.ReqConte
uIDParam := web.Params(ctx.Req)[":UID"]
return f.handleRouteDeleteAlertRule(ctx, uIDParam)
}
func (f *ProvisioningApiHandler) RouteDeleteAlertRuleGroup(ctx *contextmodel.ReqContext) response.Response {
// Parse Path Parameters
folderUIDParam := web.Params(ctx.Req)[":FolderUID"]
groupParam := web.Params(ctx.Req)[":Group"]
return f.handleRouteDeleteAlertRuleGroup(ctx, folderUIDParam, groupParam)
}
func (f *ProvisioningApiHandler) RouteDeleteContactpoints(ctx *contextmodel.ReqContext) response.Response {
// Parse Path Parameters
uIDParam := web.Params(ctx.Req)[":UID"]
@@ -237,6 +244,18 @@ func (api *API) RegisterProvisioningApiEndpoints(srv ProvisioningApi, m *metrics
m,
),
)
group.Delete(
toMacaronPath("/api/v1/provisioning/folder/{FolderUID}/rule-groups/{Group}"),
requestmeta.SetOwner(requestmeta.TeamAlerting),
requestmeta.SetSLOGroup(requestmeta.SLOGroupHighSlow),
api.authorize(http.MethodDelete, "/api/v1/provisioning/folder/{FolderUID}/rule-groups/{Group}"),
metrics.Instrument(
http.MethodDelete,
"/api/v1/provisioning/folder/{FolderUID}/rule-groups/{Group}",
api.Hooks.Wrap(srv.RouteDeleteAlertRuleGroup),
m,
),
)
group.Delete(
toMacaronPath("/api/v1/provisioning/contact-points/{UID}"),
requestmeta.SetOwner(requestmeta.TeamAlerting),