Alerting: Get grafana-managed alert rule by UID (#86845)

* Add auth checks and test

* Check user is authorized to view rule and add tests

* Change naming

* Update Swagger params

* Update auth test and swagger gen

* Update swagger gen

* Change response to GettableExtendedRuleNode

* openapi3-gen

* Update tests with refactors models pkg
This commit is contained in:
Fayzal Ghantiwala
2024-05-02 15:24:59 +01:00
committed by GitHub
parent 9e6de035c0
commit df25e9197e
12 changed files with 227 additions and 13 deletions
@@ -28,6 +28,7 @@ type RulerApi interface {
RouteGetGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
RouteGetNamespaceGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
RouteGetNamespaceRulesConfig(*contextmodel.ReqContext) response.Response
RouteGetRuleByUID(*contextmodel.ReqContext) response.Response
RouteGetRulegGroupConfig(*contextmodel.ReqContext) response.Response
RouteGetRulesConfig(*contextmodel.ReqContext) response.Response
RouteGetRulesForExport(*contextmodel.ReqContext) response.Response
@@ -80,6 +81,11 @@ func (f *RulerApiHandler) RouteGetNamespaceRulesConfig(ctx *contextmodel.ReqCont
namespaceParam := web.Params(ctx.Req)[":Namespace"]
return f.handleRouteGetNamespaceRulesConfig(ctx, datasourceUIDParam, namespaceParam)
}
func (f *RulerApiHandler) RouteGetRuleByUID(ctx *contextmodel.ReqContext) response.Response {
// Parse Path Parameters
ruleUIDParam := web.Params(ctx.Req)[":RuleUID"]
return f.handleRouteGetRuleByUID(ctx, ruleUIDParam)
}
func (f *RulerApiHandler) RouteGetRulegGroupConfig(ctx *contextmodel.ReqContext) response.Response {
// Parse Path Parameters
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
@@ -225,6 +231,18 @@ func (api *API) RegisterRulerApiEndpoints(srv RulerApi, m *metrics.API) {
m,
),
)
group.Get(
toMacaronPath("/api/ruler/grafana/api/v1/rule/{RuleUID}"),
requestmeta.SetOwner(requestmeta.TeamAlerting),
requestmeta.SetSLOGroup(requestmeta.SLOGroupHighSlow),
api.authorize(http.MethodGet, "/api/ruler/grafana/api/v1/rule/{RuleUID}"),
metrics.Instrument(
http.MethodGet,
"/api/ruler/grafana/api/v1/rule/{RuleUID}",
api.Hooks.Wrap(srv.RouteGetRuleByUID),
m,
),
)
group.Get(
toMacaronPath("/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}"),
requestmeta.SetOwner(requestmeta.TeamAlerting),