grafana/pkg/services/ngalert/api/forking_prometheus.go
idafurjes 6c5a573772
Chore: Move ReqContext to contexthandler service (#62102)
* Chore: Move ReqContext to contexthandler service

* Rename package to contextmodel

* Generate ngalert files

* Remove unused imports
2023-01-27 08:50:36 +01:00

56 lines
1.8 KiB
Go

package api
import (
"github.com/grafana/grafana/pkg/api/response"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
"github.com/grafana/grafana/pkg/services/datasources"
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
)
type PrometheusApiHandler struct {
ProxySvc *LotexProm
GrafanaSvc *PrometheusSrv
DatasourceCache datasources.CacheService
}
// NewForkingProm implements a set of routes that proxy to various Prometheus-compatible backends.
func NewForkingProm(datasourceCache datasources.CacheService, proxy *LotexProm, grafana *PrometheusSrv) *PrometheusApiHandler {
return &PrometheusApiHandler{
ProxySvc: proxy,
GrafanaSvc: grafana,
DatasourceCache: datasourceCache,
}
}
func (f *PrometheusApiHandler) handleRouteGetAlertStatuses(ctx *contextmodel.ReqContext, dsUID string) response.Response {
t, err := f.getService(ctx)
if err != nil {
return errorToResponse(err)
}
return t.RouteGetAlertStatuses(ctx)
}
func (f *PrometheusApiHandler) handleRouteGetRuleStatuses(ctx *contextmodel.ReqContext, dsUID string) response.Response {
t, err := f.getService(ctx)
if err != nil {
return errorToResponse(err)
}
return t.RouteGetRuleStatuses(ctx)
}
func (f *PrometheusApiHandler) handleRouteGetGrafanaAlertStatuses(ctx *contextmodel.ReqContext) response.Response {
return f.GrafanaSvc.RouteGetAlertStatuses(ctx)
}
func (f *PrometheusApiHandler) handleRouteGetGrafanaRuleStatuses(ctx *contextmodel.ReqContext) response.Response {
return f.GrafanaSvc.RouteGetRuleStatuses(ctx)
}
func (f *PrometheusApiHandler) getService(ctx *contextmodel.ReqContext) (*LotexProm, error) {
_, err := getDatasourceByUID(ctx, f.DatasourceCache, apimodels.LoTexRulerBackend)
if err != nil {
return nil, err
}
return f.ProxySvc, nil
}