ds-querier: handle response-headers explicitly (#107304)
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/registry/apis/query/clientapi"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/adapters"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext"
|
||||
@@ -109,8 +110,34 @@ func getGrafanaDataSourceSettings(ctx context.Context) (*backend.DataSourceInsta
|
||||
return adapters.ModelToInstanceSettings(ds, decryptFunc)
|
||||
}
|
||||
|
||||
func (d *pluginClient) QueryData(ctx context.Context, req data.QueryDataRequest) (*clientapi.Response, error) {
|
||||
// middlewares may set response-http-headers through context, so we need to do extra steps
|
||||
// first we create an isolated context to be used by query-data
|
||||
isolatedCtx := contexthandler.CopyWithReqContext(ctx)
|
||||
|
||||
qdr, err := d.innerQueryData(isolatedCtx, req)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rsp := &clientapi.Response{
|
||||
QDR: qdr,
|
||||
Headers: nil,
|
||||
}
|
||||
|
||||
// we extract the response-headers from the isolated context, and return them explicitly
|
||||
// in the clientapi.Response structure
|
||||
reqCtx := contexthandler.FromContext(isolatedCtx)
|
||||
if reqCtx != nil {
|
||||
rsp.Headers = reqCtx.Resp.Header()
|
||||
}
|
||||
|
||||
return rsp, nil
|
||||
}
|
||||
|
||||
// ExecuteQueryData implements QueryHelper.
|
||||
func (d *pluginClient) QueryData(ctx context.Context, req data.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||
func (d *pluginClient) innerQueryData(ctx context.Context, req data.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||
queries, dsRef, err := data.ToDataSourceQueries(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user