2021-03-24 06:43:25 -05:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/grafana/grafana/pkg/api/response"
|
2023-01-27 01:50:36 -06:00
|
|
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
2021-03-24 06:43:25 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/datasources"
|
2021-04-19 13:26:04 -05:00
|
|
|
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
2021-03-24 06:43:25 -05:00
|
|
|
)
|
|
|
|
|
2022-07-18 02:08:08 -05:00
|
|
|
type PrometheusApiHandler struct {
|
2022-02-04 11:42:04 -06:00
|
|
|
ProxySvc *LotexProm
|
|
|
|
GrafanaSvc *PrometheusSrv
|
|
|
|
DatasourceCache datasources.CacheService
|
2021-03-24 06:43:25 -05:00
|
|
|
}
|
|
|
|
|
2022-07-18 02:08:08 -05:00
|
|
|
// 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{
|
2021-03-24 06:43:25 -05:00
|
|
|
ProxySvc: proxy,
|
|
|
|
GrafanaSvc: grafana,
|
|
|
|
DatasourceCache: datasourceCache,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *PrometheusApiHandler) handleRouteGetAlertStatuses(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
2022-08-02 08:33:59 -05:00
|
|
|
t, err := f.getService(ctx)
|
2021-03-24 06:43:25 -05:00
|
|
|
if err != nil {
|
2022-08-02 08:33:59 -05:00
|
|
|
return errorToResponse(err)
|
2021-03-24 06:43:25 -05:00
|
|
|
}
|
2022-08-02 08:33:59 -05:00
|
|
|
return t.RouteGetAlertStatuses(ctx)
|
2021-03-24 06:43:25 -05:00
|
|
|
}
|
|
|
|
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *PrometheusApiHandler) handleRouteGetRuleStatuses(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
2022-08-02 08:33:59 -05:00
|
|
|
t, err := f.getService(ctx)
|
2021-03-24 06:43:25 -05:00
|
|
|
if err != nil {
|
2022-08-02 08:33:59 -05:00
|
|
|
return errorToResponse(err)
|
2021-03-24 06:43:25 -05:00
|
|
|
}
|
2022-08-02 08:33:59 -05:00
|
|
|
return t.RouteGetRuleStatuses(ctx)
|
2021-03-24 06:43:25 -05:00
|
|
|
}
|
2022-02-04 11:42:04 -06:00
|
|
|
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *PrometheusApiHandler) handleRouteGetGrafanaAlertStatuses(ctx *contextmodel.ReqContext) response.Response {
|
2022-02-04 11:42:04 -06:00
|
|
|
return f.GrafanaSvc.RouteGetAlertStatuses(ctx)
|
|
|
|
}
|
|
|
|
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *PrometheusApiHandler) handleRouteGetGrafanaRuleStatuses(ctx *contextmodel.ReqContext) response.Response {
|
2022-02-04 11:42:04 -06:00
|
|
|
return f.GrafanaSvc.RouteGetRuleStatuses(ctx)
|
|
|
|
}
|
2022-08-02 08:33:59 -05:00
|
|
|
|
2023-01-27 01:50:36 -06:00
|
|
|
func (f *PrometheusApiHandler) getService(ctx *contextmodel.ReqContext) (*LotexProm, error) {
|
2022-08-02 08:33:59 -05:00
|
|
|
_, err := getDatasourceByUID(ctx, f.DatasourceCache, apimodels.LoTexRulerBackend)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return f.ProxySvc, nil
|
|
|
|
}
|