ds/query: use datasourceId if it exists in the request (#41446)

This commit is contained in:
Ryan McKinley 2021-11-09 07:11:09 -08:00 committed by GitHub
parent 8d22733666
commit 490d21fc5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -122,6 +122,16 @@ func (hs *HTTPServer) getDataSourceFromQuery(c *models.ReqContext, query *simple
return grafanads.DataSourceModel(c.OrgId), nil
}
// use datasourceId if it exists
id := query.Get("datasourceId").MustInt64(0)
if id > 0 {
ds, err = hs.DataSourceCache.GetDatasource(id, c.SignedInUser, c.SkipCache)
if err != nil {
return nil, hs.handleGetDataSourceError(err, id)
}
return ds, nil
}
if uid != "" {
ds, err = hs.DataSourceCache.GetDatasourceByUID(uid, c.SignedInUser, c.SkipCache)
if err != nil {
@ -130,16 +140,7 @@ func (hs *HTTPServer) getDataSourceFromQuery(c *models.ReqContext, query *simple
return ds, nil
}
// Fallback to the datasourceId
id, err := query.Get("datasourceId").Int64()
if err != nil {
return nil, response.Error(http.StatusBadRequest, "Query missing data source ID/UID", nil)
}
ds, err = hs.DataSourceCache.GetDatasource(id, c.SignedInUser, c.SkipCache)
if err != nil {
return nil, hs.handleGetDataSourceError(err, id)
}
return ds, nil
return nil, response.Error(http.StatusBadRequest, "Query missing data source ID/UID", nil)
}
func toMacronResponse(qdr *backend.QueryDataResponse) response.Response {