mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 16:22:10 +08:00
chore: move DatasourceUid parsing to ruler instead (#95972)
Reverts #95629 This reverts commit 3adc7c8771fb3c5b67e4dfb2905b8cebd0f7088a.
This commit is contained in:
@ -80,7 +80,7 @@ func (p *queryParser) parseRequest(ctx context.Context, input *query.QueryDataRe
|
|||||||
return rsp, MakePublicQueryError(q.RefID, "multiple queries with same refId")
|
return rsp, MakePublicQueryError(q.RefID, "multiple queries with same refId")
|
||||||
}
|
}
|
||||||
|
|
||||||
ds, err := p.getValidDataSourceRef(ctx, q)
|
ds, err := p.getValidDataSourceRef(ctx, q.Datasource, q.DatasourceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rsp, err
|
return rsp, err
|
||||||
}
|
}
|
||||||
@ -194,30 +194,16 @@ func getTimeRangeForQuery(parentTimerange, queryTimerange *data.TimeRange) data.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *queryParser) getValidDataSourceRef(ctx context.Context, dataQuery data.DataQuery) (*data.DataSourceRef, error) {
|
func (p *queryParser) getValidDataSourceRef(ctx context.Context, ds *data.DataSourceRef, id int64) (*data.DataSourceRef, error) {
|
||||||
ds := dataQuery.Datasource
|
|
||||||
id := dataQuery.DatasourceID
|
|
||||||
|
|
||||||
if ds == nil {
|
if ds == nil {
|
||||||
if id == 0 {
|
if id == 0 {
|
||||||
return nil, NewErrorWithRefID(dataQuery.RefID, fmt.Errorf("missing datasource reference or id"))
|
return nil, fmt.Errorf("missing datasource reference or id")
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.legacy == nil {
|
if p.legacy == nil {
|
||||||
return nil, fmt.Errorf("legacy datasource lookup unsupported (id:%d)", id)
|
return nil, fmt.Errorf("legacy datasource lookup unsupported (id:%d)", id)
|
||||||
}
|
}
|
||||||
return p.legacy.GetDataSourceFromDeprecatedFields(ctx, "", id)
|
return p.legacy.GetDataSourceFromDeprecatedFields(ctx, "", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ds.UID[0] == '$' {
|
|
||||||
uid, ok := dataQuery.Get("datasourceUid")
|
|
||||||
if ok {
|
|
||||||
return p.legacy.GetDataSourceFromDeprecatedFields(ctx, uid.(string), 0) // uid can be name in this scenario
|
|
||||||
} else {
|
|
||||||
return nil, NewErrorWithRefID(dataQuery.RefID, fmt.Errorf("missing datasource reference or id"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ds.Type == "" {
|
if ds.Type == "" {
|
||||||
if ds.UID == "" {
|
if ds.UID == "" {
|
||||||
return nil, fmt.Errorf("missing name/uid in data source reference")
|
return nil, fmt.Errorf("missing name/uid in data source reference")
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
{
|
|
||||||
"description": "datasource uid is variable",
|
|
||||||
"input": {
|
|
||||||
"from": "now-6",
|
|
||||||
"to": "now",
|
|
||||||
"queries": [
|
|
||||||
{
|
|
||||||
"refId": "A",
|
|
||||||
"datasource": {
|
|
||||||
"type": "",
|
|
||||||
"uid": "${datasource}"
|
|
||||||
},
|
|
||||||
"datasourceUid": "XYX",
|
|
||||||
"expr": "2"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"expect": {
|
|
||||||
"requests": [
|
|
||||||
{
|
|
||||||
"pluginId": "plugin-bbb",
|
|
||||||
"uid": "XYX",
|
|
||||||
"request": {
|
|
||||||
"from": "now-6",
|
|
||||||
"to": "now",
|
|
||||||
"queries": [
|
|
||||||
{
|
|
||||||
"refId": "A",
|
|
||||||
"datasource": {
|
|
||||||
"type": "",
|
|
||||||
"uid": "${datasource}"
|
|
||||||
},
|
|
||||||
"datasourceUid": "XYX",
|
|
||||||
"expr": "2"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user