mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 17:43:35 -06:00
* 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>
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
/*Package api contains base API implementation of unified alerting
|
|
*
|
|
*Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
|
*
|
|
*Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them.
|
|
*/
|
|
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/grafana/grafana/pkg/api/response"
|
|
"github.com/grafana/grafana/pkg/api/routing"
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
|
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
|
)
|
|
|
|
type HistoryApi interface {
|
|
RouteGetStateHistory(*contextmodel.ReqContext) response.Response
|
|
}
|
|
|
|
func (f *HistoryApiHandler) RouteGetStateHistory(ctx *contextmodel.ReqContext) response.Response {
|
|
return f.handleRouteGetStateHistory(ctx)
|
|
}
|
|
|
|
func (api *API) RegisterHistoryApiEndpoints(srv HistoryApi, m *metrics.API) {
|
|
api.RouteRegister.Group("", func(group routing.RouteRegister) {
|
|
group.Get(
|
|
toMacaronPath("/api/v1/rules/history"),
|
|
api.authorize(http.MethodGet, "/api/v1/rules/history"),
|
|
metrics.Instrument(
|
|
http.MethodGet,
|
|
"/api/v1/rules/history",
|
|
api.Hooks.Wrap(srv.RouteGetStateHistory),
|
|
m,
|
|
),
|
|
)
|
|
}, middleware.ReqSignedIn)
|
|
}
|