Alerting: Allow hooking into request handler functions. (#67000)

* Alerting: Allow hooking into request handler functions.

Adds a facility to AlertNG for hooking into API handlers, allowing the
replacement of request handlers for specific paths. One of goals of this
approach was to allow hooking as late as possible in the request, e.g.
after all middleware has been applied, to simplfiy usage.

* Update pkg/services/ngalert/api/hooks.go

Co-authored-by: gotjosh <josue.abreu@gmail.com>

* Update pkg/services/ngalert/api/hooks.go

Co-authored-by: gotjosh <josue.abreu@gmail.com>

* Update pkg/services/ngalert/ngalert.go

Co-authored-by: gotjosh <josue.abreu@gmail.com>

* Fixes to review comments

* Fix passing logger in

---------

Co-authored-by: gotjosh <josue.abreu@gmail.com>
This commit is contained in:
Steve Simpson
2023-04-24 18:18:44 +02:00
committed by GitHub
parent 68a277b53b
commit 9effb9a708
11 changed files with 135 additions and 81 deletions

View File

@@ -68,7 +68,7 @@ func (api *API) RegisterTestingApiEndpoints(srv TestingApi, m *metrics.API) {
metrics.Instrument(
http.MethodPost,
"/api/v1/rule/backtest",
srv.BacktestConfig,
api.Hooks.Wrap(srv.BacktestConfig),
m,
),
)
@@ -78,7 +78,7 @@ func (api *API) RegisterTestingApiEndpoints(srv TestingApi, m *metrics.API) {
metrics.Instrument(
http.MethodPost,
"/api/v1/eval",
srv.RouteEvalQueries,
api.Hooks.Wrap(srv.RouteEvalQueries),
m,
),
)
@@ -88,7 +88,7 @@ func (api *API) RegisterTestingApiEndpoints(srv TestingApi, m *metrics.API) {
metrics.Instrument(
http.MethodPost,
"/api/v1/rule/test/{DatasourceUID}",
srv.RouteTestRuleConfig,
api.Hooks.Wrap(srv.RouteTestRuleConfig),
m,
),
)
@@ -98,7 +98,7 @@ func (api *API) RegisterTestingApiEndpoints(srv TestingApi, m *metrics.API) {
metrics.Instrument(
http.MethodPost,
"/api/v1/rule/test/grafana",
srv.RouteTestRuleGrafanaConfig,
api.Hooks.Wrap(srv.RouteTestRuleGrafanaConfig),
m,
),
)