From 9b0644e5c8918e325d6fc5b9fb360965b9550f5c Mon Sep 17 00:00:00 2001 From: Adam Simpson Date: Thu, 7 Nov 2024 21:48:29 -0500 Subject: [PATCH] chore: move DatasourceUid parsing to ruler instead (#95972) Reverts #95629 This reverts commit 3adc7c8771fb3c5b67e4dfb2905b8cebd0f7088a. --- pkg/registry/apis/query/parser.go | 20 ++------- .../apis/query/testdata/legacy-ds-uid.json | 41 ------------------- 2 files changed, 3 insertions(+), 58 deletions(-) delete mode 100644 pkg/registry/apis/query/testdata/legacy-ds-uid.json diff --git a/pkg/registry/apis/query/parser.go b/pkg/registry/apis/query/parser.go index aba60550ef7..98ae81fbd64 100644 --- a/pkg/registry/apis/query/parser.go +++ b/pkg/registry/apis/query/parser.go @@ -80,7 +80,7 @@ func (p *queryParser) parseRequest(ctx context.Context, input *query.QueryDataRe 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 { 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) { - ds := dataQuery.Datasource - id := dataQuery.DatasourceID - +func (p *queryParser) getValidDataSourceRef(ctx context.Context, ds *data.DataSourceRef, id int64) (*data.DataSourceRef, error) { if ds == nil { 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 { return nil, fmt.Errorf("legacy datasource lookup unsupported (id:%d)", 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.UID == "" { return nil, fmt.Errorf("missing name/uid in data source reference") diff --git a/pkg/registry/apis/query/testdata/legacy-ds-uid.json b/pkg/registry/apis/query/testdata/legacy-ds-uid.json deleted file mode 100644 index 41f6960f8bd..00000000000 --- a/pkg/registry/apis/query/testdata/legacy-ds-uid.json +++ /dev/null @@ -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" - } - ] - } - } - ] - } -} \ No newline at end of file