Alerting: Rule Modify Export APIs (#75322)
* extend RuleStore interface to get namespace by UID * add new export API endpoints * implement request handlers * update authorization and wire handlers to paths * add folder error matchers to errorToResponse * add tests for export methods
This commit is contained in:
@@ -30,8 +30,10 @@ type RulerApi interface {
|
||||
RouteGetNamespaceRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetRulegGroupConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetRulesForExport(*contextmodel.ReqContext) response.Response
|
||||
RoutePostNameGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RoutePostNameRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RoutePostRulesGroupForExport(*contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) RouteDeleteGrafanaRuleGroupConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
@@ -90,6 +92,9 @@ func (f *RulerApiHandler) RouteGetRulesConfig(ctx *contextmodel.ReqContext) resp
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetRulesConfig(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteGetRulesForExport(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetRulesForExport(ctx)
|
||||
}
|
||||
func (f *RulerApiHandler) RoutePostNameGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
@@ -111,6 +116,16 @@ func (f *RulerApiHandler) RoutePostNameRulesConfig(ctx *contextmodel.ReqContext)
|
||||
}
|
||||
return f.handleRoutePostNameRulesConfig(ctx, conf, datasourceUIDParam, namespaceParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RoutePostRulesGroupForExport(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
// Parse Request Body
|
||||
conf := apimodels.PostableRuleGroupConfig{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
return f.handleRoutePostRulesGroupForExport(ctx, conf, namespaceParam)
|
||||
}
|
||||
|
||||
func (api *API) RegisterRulerApiEndpoints(srv RulerApi, m *metrics.API) {
|
||||
api.RouteRegister.Group("", func(group routing.RouteRegister) {
|
||||
@@ -234,6 +249,17 @@ func (api *API) RegisterRulerApiEndpoints(srv RulerApi, m *metrics.API) {
|
||||
m,
|
||||
),
|
||||
)
|
||||
group.Get(
|
||||
toMacaronPath("/api/ruler/grafana/api/v1/export/rules"),
|
||||
requestmeta.SetOwner(requestmeta.TeamAlerting),
|
||||
api.authorize(http.MethodGet, "/api/ruler/grafana/api/v1/export/rules"),
|
||||
metrics.Instrument(
|
||||
http.MethodGet,
|
||||
"/api/ruler/grafana/api/v1/export/rules",
|
||||
api.Hooks.Wrap(srv.RouteGetRulesForExport),
|
||||
m,
|
||||
),
|
||||
)
|
||||
group.Post(
|
||||
toMacaronPath("/api/ruler/grafana/api/v1/rules/{Namespace}"),
|
||||
requestmeta.SetOwner(requestmeta.TeamAlerting),
|
||||
@@ -258,5 +284,16 @@ func (api *API) RegisterRulerApiEndpoints(srv RulerApi, m *metrics.API) {
|
||||
m,
|
||||
),
|
||||
)
|
||||
group.Post(
|
||||
toMacaronPath("/api/ruler/grafana/api/v1/rules/{Namespace}/export"),
|
||||
requestmeta.SetOwner(requestmeta.TeamAlerting),
|
||||
api.authorize(http.MethodPost, "/api/ruler/grafana/api/v1/rules/{Namespace}/export"),
|
||||
metrics.Instrument(
|
||||
http.MethodPost,
|
||||
"/api/ruler/grafana/api/v1/rules/{Namespace}/export",
|
||||
api.Hooks.Wrap(srv.RoutePostRulesGroupForExport),
|
||||
m,
|
||||
),
|
||||
)
|
||||
}, middleware.ReqSignedIn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user