diff --git a/pkg/registry/apis/datasource/sub_query.go b/pkg/registry/apis/datasource/sub_query.go index 1fdd151014e..cc6d0edc22a 100644 --- a/pkg/registry/apis/datasource/sub_query.go +++ b/pkg/registry/apis/datasource/sub_query.go @@ -69,6 +69,7 @@ func (r *subQueryREST) Connect(ctx context.Context, name string, opts runtime.Ob } if dsRef != nil && dsRef.UID != name { responder.Error(fmt.Errorf("expected query body datasource and request to match")) + return } ctx = backend.WithGrafanaConfig(ctx, pluginCtx.GrafanaConfig) diff --git a/pkg/registry/apis/datasource/sub_resource.go b/pkg/registry/apis/datasource/sub_resource.go index f8f56baf92e..a9b1e259a7b 100644 --- a/pkg/registry/apis/datasource/sub_resource.go +++ b/pkg/registry/apis/datasource/sub_resource.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "net/http" + "net/url" "strings" "github.com/grafana/grafana-plugin-sdk-go/backend" @@ -66,12 +67,21 @@ func (r *subResourceREST) Connect(ctx context.Context, name string, opts runtime return } - path := req.URL.Path[idx+len("/resource"):] + clonedReq := req.Clone(req.Context()) + rawURL := req.URL.Path[idx+len("/resource"):] + + clonedReq.URL = &url.URL{ + Path: rawURL, + RawQuery: clonedReq.URL.RawQuery, + } + err = r.builder.client.CallResource(ctx, &backend.CallResourceRequest{ PluginContext: pluginCtx, - Path: path, + Path: clonedReq.URL.Path, Method: req.Method, + URL: req.URL.String(), Body: body, + Headers: req.Header, }, httpresponsesender.New(w)) if err != nil {