diff --git a/pkg/registry/apis/query/query_test.go b/pkg/registry/apis/query/query_test.go index a1861361b11..431e03f22a2 100644 --- a/pkg/registry/apis/query/query_test.go +++ b/pkg/registry/apis/query/query_test.go @@ -16,6 +16,7 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/data" dataapi "github.com/grafana/grafana-plugin-sdk-go/experimental/apis/data/v0alpha1" + "github.com/grafana/grafana/pkg/apimachinery/identity" queryapi "github.com/grafana/grafana/pkg/apis/query/v0alpha1" "github.com/grafana/grafana/pkg/expr" "github.com/grafana/grafana/pkg/infra/log" @@ -45,6 +46,14 @@ func loadTestdataFrames(t *testing.T, filename string) *backend.QueryDataRespons return result } +type mockUser struct { + identity.Requester +} + +func (mu mockUser) GetOrgID() int64 { + return -1 +} + func TestQueryAPI(t *testing.T) { testCases := []struct { name string @@ -167,7 +176,9 @@ func TestQueryAPI(t *testing.T) { legacyDatasourceLookup: &mockLegacyDataSourceLookup{}, } - req := httptest.NewRequest(http.MethodPost, "/some-path", bytes.NewReader([]byte(tc.queryJSON))) + reqCtx := identity.WithRequester(context.Background(), mockUser{}) + + req := httptest.NewRequestWithContext(reqCtx, http.MethodPost, "/some-path", bytes.NewReader([]byte(tc.queryJSON))) req.Header.Set("Content-Type", "application/json") // Set optional headers diff --git a/pkg/services/query/query.go b/pkg/services/query/query.go index db4ab88781c..6b49dcb91a3 100644 --- a/pkg/services/query/query.go +++ b/pkg/services/query/query.go @@ -234,7 +234,13 @@ func QueryData(ctx context.Context, log log.Logger, dscache datasources.CacheSer headers: headers, concurrentQueryLimit: 16, // TODO: make it configurable } - return s.QueryDataNew(ctx, nil, false, reqDTO) + + user, err := identity.GetRequester(ctx) + if err != nil { + return nil, err + } + + return s.QueryDataNew(ctx, user, false, reqDTO) } // handleExpressions handles queries when there is an expression.