2021-03-11 13:28:00 -06:00
|
|
|
/*Package api contains base API implementation of unified alerting
|
|
|
|
*
|
2021-04-09 04:55:41 -05:00
|
|
|
*Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
2021-03-11 13:28:00 -06:00
|
|
|
*
|
2021-04-09 04:55:41 -05:00
|
|
|
*Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them.
|
2021-03-11 13:28:00 -06:00
|
|
|
*/
|
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2021-04-28 15:59:15 -05:00
|
|
|
"net/http"
|
|
|
|
|
2021-03-11 13:28:00 -06:00
|
|
|
"github.com/grafana/grafana/pkg/api/response"
|
|
|
|
"github.com/grafana/grafana/pkg/api/routing"
|
2022-03-24 16:13:47 -05:00
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
2023-08-29 05:43:33 -05:00
|
|
|
"github.com/grafana/grafana/pkg/middleware/requestmeta"
|
2023-01-27 01:50:36 -06:00
|
|
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
2021-04-19 13:26:04 -05:00
|
|
|
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
2021-04-30 11:28:06 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
2021-12-13 02:22:57 -06:00
|
|
|
"github.com/grafana/grafana/pkg/web"
|
2021-03-11 13:28:00 -06:00
|
|
|
)
|
|
|
|
|
2022-07-18 02:08:08 -05:00
|
|
|
type TestingApi interface {
|
2023-01-27 01:50:36 -06:00
|
|
|
BacktestConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
RouteEvalQueries(*contextmodel.ReqContext) response.Response
|
|
|
|
RouteTestRuleConfig(*contextmodel.ReqContext) response.Response
|
|
|
|
RouteTestRuleGrafanaConfig(*contextmodel.ReqContext) response.Response
|
2021-03-11 13:28:00 -06:00
|
|
|
}
|
|
|
|
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *TestingApiHandler) BacktestConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-12-14 08:44:14 -06:00
|
|
|
// Parse Request Body
|
|
|
|
conf := apimodels.BacktestConfig{}
|
|
|
|
if err := web.Bind(ctx.Req, &conf); err != nil {
|
|
|
|
return response.Error(http.StatusBadRequest, "bad request data", err)
|
|
|
|
}
|
2023-01-25 15:01:42 -06:00
|
|
|
return f.handleBacktestConfig(ctx, conf)
|
2022-12-14 08:44:14 -06:00
|
|
|
}
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *TestingApiHandler) RouteEvalQueries(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Request Body
|
2021-12-13 02:22:57 -06:00
|
|
|
conf := apimodels.EvalQueriesPayload{}
|
|
|
|
if err := web.Bind(ctx.Req, &conf); err != nil {
|
|
|
|
return response.Error(http.StatusBadRequest, "bad request data", err)
|
|
|
|
}
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRouteEvalQueries(ctx, conf)
|
2021-12-13 02:22:57 -06:00
|
|
|
}
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *TestingApiHandler) RouteTestRuleConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Path Parameters
|
2022-06-23 15:13:39 -05:00
|
|
|
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Request Body
|
2021-12-13 02:22:57 -06:00
|
|
|
conf := apimodels.TestRulePayload{}
|
|
|
|
if err := web.Bind(ctx.Req, &conf); err != nil {
|
|
|
|
return response.Error(http.StatusBadRequest, "bad request data", err)
|
|
|
|
}
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRouteTestRuleConfig(ctx, conf, datasourceUIDParam)
|
2021-12-13 02:22:57 -06:00
|
|
|
}
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *TestingApiHandler) RouteTestRuleGrafanaConfig(ctx *contextmodel.ReqContext) response.Response {
|
2022-07-18 02:08:08 -05:00
|
|
|
// Parse Request Body
|
2023-06-08 17:59:54 -05:00
|
|
|
conf := apimodels.PostableExtendedRuleNodeExtended{}
|
2022-02-04 11:42:04 -06:00
|
|
|
if err := web.Bind(ctx.Req, &conf); err != nil {
|
|
|
|
return response.Error(http.StatusBadRequest, "bad request data", err)
|
|
|
|
}
|
2022-07-18 02:08:08 -05:00
|
|
|
return f.handleRouteTestRuleGrafanaConfig(ctx, conf)
|
2022-02-04 11:42:04 -06:00
|
|
|
}
|
|
|
|
|
2022-07-18 02:08:08 -05:00
|
|
|
func (api *API) RegisterTestingApiEndpoints(srv TestingApi, m *metrics.API) {
|
2021-03-11 13:28:00 -06:00
|
|
|
api.RouteRegister.Group("", func(group routing.RouteRegister) {
|
2022-12-14 08:44:14 -06:00
|
|
|
group.Post(
|
|
|
|
toMacaronPath("/api/v1/rule/backtest"),
|
2023-08-29 05:43:33 -05:00
|
|
|
requestmeta.SetOwner(requestmeta.TeamAlerting),
|
2023-09-29 07:56:48 -05:00
|
|
|
requestmeta.SetSLOGroup(requestmeta.SLOGroupHighSlow),
|
2022-12-14 08:44:14 -06:00
|
|
|
api.authorize(http.MethodPost, "/api/v1/rule/backtest"),
|
|
|
|
metrics.Instrument(
|
|
|
|
http.MethodPost,
|
|
|
|
"/api/v1/rule/backtest",
|
2023-04-24 11:18:44 -05:00
|
|
|
api.Hooks.Wrap(srv.BacktestConfig),
|
2022-12-14 08:44:14 -06:00
|
|
|
m,
|
|
|
|
),
|
|
|
|
)
|
2021-04-28 15:59:15 -05:00
|
|
|
group.Post(
|
|
|
|
toMacaronPath("/api/v1/eval"),
|
2023-08-29 05:43:33 -05:00
|
|
|
requestmeta.SetOwner(requestmeta.TeamAlerting),
|
2023-09-29 07:56:48 -05:00
|
|
|
requestmeta.SetSLOGroup(requestmeta.SLOGroupHighSlow),
|
2022-02-04 11:42:04 -06:00
|
|
|
api.authorize(http.MethodPost, "/api/v1/eval"),
|
2021-04-30 11:28:06 -05:00
|
|
|
metrics.Instrument(
|
2021-04-28 15:59:15 -05:00
|
|
|
http.MethodPost,
|
|
|
|
"/api/v1/eval",
|
2023-04-24 11:18:44 -05:00
|
|
|
api.Hooks.Wrap(srv.RouteEvalQueries),
|
2021-04-30 11:28:06 -05:00
|
|
|
m,
|
2021-04-28 15:59:15 -05:00
|
|
|
),
|
|
|
|
)
|
|
|
|
group.Post(
|
2022-05-17 06:10:20 -05:00
|
|
|
toMacaronPath("/api/v1/rule/test/{DatasourceUID}"),
|
2023-08-29 05:43:33 -05:00
|
|
|
requestmeta.SetOwner(requestmeta.TeamAlerting),
|
2023-09-29 07:56:48 -05:00
|
|
|
requestmeta.SetSLOGroup(requestmeta.SLOGroupHighSlow),
|
2022-05-17 06:10:20 -05:00
|
|
|
api.authorize(http.MethodPost, "/api/v1/rule/test/{DatasourceUID}"),
|
2021-04-30 11:28:06 -05:00
|
|
|
metrics.Instrument(
|
2021-04-28 15:59:15 -05:00
|
|
|
http.MethodPost,
|
2022-05-17 06:10:20 -05:00
|
|
|
"/api/v1/rule/test/{DatasourceUID}",
|
2023-04-24 11:18:44 -05:00
|
|
|
api.Hooks.Wrap(srv.RouteTestRuleConfig),
|
2021-04-30 11:28:06 -05:00
|
|
|
m,
|
2021-04-28 15:59:15 -05:00
|
|
|
),
|
|
|
|
)
|
2022-02-04 11:42:04 -06:00
|
|
|
group.Post(
|
|
|
|
toMacaronPath("/api/v1/rule/test/grafana"),
|
2023-08-29 05:43:33 -05:00
|
|
|
requestmeta.SetOwner(requestmeta.TeamAlerting),
|
2023-09-29 07:56:48 -05:00
|
|
|
requestmeta.SetSLOGroup(requestmeta.SLOGroupHighSlow),
|
2022-02-04 11:42:04 -06:00
|
|
|
api.authorize(http.MethodPost, "/api/v1/rule/test/grafana"),
|
|
|
|
metrics.Instrument(
|
|
|
|
http.MethodPost,
|
|
|
|
"/api/v1/rule/test/grafana",
|
2023-04-24 11:18:44 -05:00
|
|
|
api.Hooks.Wrap(srv.RouteTestRuleGrafanaConfig),
|
2022-02-04 11:42:04 -06:00
|
|
|
m,
|
|
|
|
),
|
|
|
|
)
|
2022-03-24 16:13:47 -05:00
|
|
|
}, middleware.ReqSignedIn)
|
2021-03-11 13:28:00 -06:00
|
|
|
}
|