Alerting: Allow administrators delete rules permanently via UI (#101974)

* add query parameter to existing APIs to control the permanent deletion of rules
* add GUID to gettable rule
* add new endpoint /ruler/grafana/api/v1/trash/rule/guid/{RuleGUID} to delete rules from trash permanently

---------

Signed-off-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
This commit is contained in:
Yuri Tseretyan
2025-03-14 16:14:06 -04:00
committed by GitHub
parent e30034a42a
commit 309a2eb4e9
25 changed files with 585 additions and 115 deletions
@@ -23,6 +23,7 @@ type RulerApi interface {
RouteDeleteGrafanaRuleGroupConfig(*contextmodel.ReqContext) response.Response
RouteDeleteNamespaceGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
RouteDeleteNamespaceRulesConfig(*contextmodel.ReqContext) response.Response
RouteDeleteRuleFromTrashByGUID(*contextmodel.ReqContext) response.Response
RouteDeleteRuleGroupConfig(*contextmodel.ReqContext) response.Response
RouteGetGrafanaRuleGroupConfig(*contextmodel.ReqContext) response.Response
RouteGetGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
@@ -55,6 +56,11 @@ func (f *RulerApiHandler) RouteDeleteNamespaceRulesConfig(ctx *contextmodel.ReqC
namespaceParam := web.Params(ctx.Req)[":Namespace"]
return f.handleRouteDeleteNamespaceRulesConfig(ctx, datasourceUIDParam, namespaceParam)
}
func (f *RulerApiHandler) RouteDeleteRuleFromTrashByGUID(ctx *contextmodel.ReqContext) response.Response {
// Parse Path Parameters
ruleGUIDParam := web.Params(ctx.Req)[":RuleGUID"]
return f.handleRouteDeleteRuleFromTrashByGUID(ctx, ruleGUIDParam)
}
func (f *RulerApiHandler) RouteDeleteRuleGroupConfig(ctx *contextmodel.ReqContext) response.Response {
// Parse Path Parameters
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
@@ -177,6 +183,18 @@ func (api *API) RegisterRulerApiEndpoints(srv RulerApi, m *metrics.API) {
m,
),
)
group.Delete(
toMacaronPath("/api/ruler/grafana/api/v1/trash/rule/guid/{RuleGUID}"),
requestmeta.SetOwner(requestmeta.TeamAlerting),
requestmeta.SetSLOGroup(requestmeta.SLOGroupHighSlow),
api.authorize(http.MethodDelete, "/api/ruler/grafana/api/v1/trash/rule/guid/{RuleGUID}"),
metrics.Instrument(
http.MethodDelete,
"/api/ruler/grafana/api/v1/trash/rule/guid/{RuleGUID}",
api.Hooks.Wrap(srv.RouteDeleteRuleFromTrashByGUID),
m,
),
)
group.Delete(
toMacaronPath("/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}"),
requestmeta.SetOwner(requestmeta.TeamAlerting),