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