mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
committed by
GitHub
parent
de3e981985
commit
925784f514
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user