Alerting: Modify endpoint for testing a datasource rule using the UID (#48070)

* Modify testing endpoint to expect the datasource UID

* Update docs
This commit is contained in:
Sofia Papagiannaki
2022-05-17 14:10:20 +03:00
committed by GitHub
parent de3e981985
commit 925784f514
10 changed files with 49 additions and 61 deletions

View File

@@ -70,26 +70,24 @@ func (srv TestingApiSrv) RouteTestGrafanaRuleConfig(c *models.ReqContext, body a
}
func (srv TestingApiSrv) RouteTestRuleConfig(c *models.ReqContext, body apimodels.TestRulePayload) response.Response {
datasourceID := web.Params(c.Req)[":DatasourceID"]
if body.Type() != apimodels.LoTexRulerBackend {
return ErrResp(http.StatusBadRequest, errors.New("unexpected payload"), "")
}
var path string
if datasourceID, err := strconv.ParseInt(datasourceID, 10, 64); err == nil {
ds, err := srv.DatasourceCache.GetDatasource(context.Background(), datasourceID, c.SignedInUser, c.SkipCache)
if err != nil {
return ErrResp(http.StatusInternalServerError, err, "failed to get datasource")
}
datasourceUID := web.Params(c.Req)[":DatasourceUID"]
ds, err := srv.DatasourceCache.GetDatasourceByUID(context.Background(), datasourceUID, c.SignedInUser, c.SkipCache)
if err != nil {
return ErrResp(http.StatusInternalServerError, err, "failed to get datasource")
}
switch ds.Type {
case "loki":
path = "loki/api/v1/query"
case "prometheus":
path = "api/v1/query"
default:
return ErrResp(http.StatusBadRequest, fmt.Errorf("unexpected datasource type %s", ds.Type), "")
}
switch ds.Type {
case "loki":
path = "loki/api/v1/query"
case "prometheus":
path = "api/v1/query"
default:
return ErrResp(http.StatusBadRequest, fmt.Errorf("unexpected datasource type %s", ds.Type), "")
}
t := timeNow()