datasources: querier: adjust the query-client (#99805)
This commit is contained in:
@@ -3,7 +3,6 @@ package client
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -14,6 +13,7 @@ import (
|
||||
|
||||
query "github.com/grafana/grafana/pkg/apis/query/v0alpha1"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/registry/apis/query/clientapi"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
|
||||
@@ -36,11 +36,11 @@ type pluginRegistry struct {
|
||||
dataSourcesService datasources.DataSourceService
|
||||
}
|
||||
|
||||
var _ data.QueryDataClient = (*pluginClient)(nil)
|
||||
var _ clientapi.QueryDataClient = (*pluginClient)(nil)
|
||||
var _ query.DataSourceApiServerRegistry = (*pluginRegistry)(nil)
|
||||
|
||||
// NewQueryClientForPluginClient creates a client that delegates to the internal plugins.Client stack
|
||||
func NewQueryClientForPluginClient(p plugins.Client, ctx *plugincontext.Provider) data.QueryDataClient {
|
||||
func NewQueryClientForPluginClient(p plugins.Client, ctx *plugincontext.Provider) clientapi.QueryDataClient {
|
||||
return &pluginClient{
|
||||
pluginClient: p,
|
||||
pCtxProvider: ctx,
|
||||
@@ -57,19 +57,19 @@ func NewDataSourceRegistryFromStore(pluginStore pluginstore.Store,
|
||||
}
|
||||
|
||||
// ExecuteQueryData implements QueryHelper.
|
||||
func (d *pluginClient) QueryData(ctx context.Context, req data.QueryDataRequest) (int, *backend.QueryDataResponse, error) {
|
||||
func (d *pluginClient) QueryData(ctx context.Context, req data.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||
queries, dsRef, err := data.ToDataSourceQueries(req)
|
||||
if err != nil {
|
||||
return http.StatusBadRequest, nil, err
|
||||
return nil, err
|
||||
}
|
||||
if dsRef == nil {
|
||||
return http.StatusBadRequest, nil, fmt.Errorf("expected single datasource request")
|
||||
return nil, fmt.Errorf("expected single datasource request")
|
||||
}
|
||||
|
||||
// NOTE: this depends on uid unique across datasources
|
||||
settings, err := d.pCtxProvider.GetDataSourceInstanceSettings(ctx, dsRef.UID)
|
||||
if err != nil {
|
||||
return http.StatusBadRequest, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
qdr := &backend.QueryDataRequest{
|
||||
@@ -77,14 +77,14 @@ func (d *pluginClient) QueryData(ctx context.Context, req data.QueryDataRequest)
|
||||
}
|
||||
qdr.PluginContext, err = d.pCtxProvider.PluginContextForDataSource(ctx, settings)
|
||||
if err != nil {
|
||||
return http.StatusBadRequest, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rsp, err := d.pluginClient.QueryData(ctx, qdr)
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, rsp, err
|
||||
return rsp, err
|
||||
}
|
||||
return query.GetResponseCode(rsp), rsp, err
|
||||
return rsp, err
|
||||
}
|
||||
|
||||
// GetDatasourceAPI implements DataSourceRegistry.
|
||||
|
||||
@@ -3,45 +3,23 @@ package client
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
data "github.com/grafana/grafana-plugin-sdk-go/experimental/apis/data/v0alpha1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
query "github.com/grafana/grafana/pkg/apis/query/v0alpha1"
|
||||
testdata "github.com/grafana/grafana/pkg/tsdb/grafana-testdata-datasource"
|
||||
)
|
||||
|
||||
type testdataDummy struct{}
|
||||
|
||||
var _ data.QueryDataClient = (*testdataDummy)(nil)
|
||||
var _ query.DataSourceApiServerRegistry = (*testdataDummy)(nil)
|
||||
|
||||
// NewTestDataClient creates a runner that only works with testdata
|
||||
func NewTestDataClient() data.QueryDataClient {
|
||||
return &testdataDummy{}
|
||||
}
|
||||
|
||||
// NewTestDataRegistry returns a registry that only knows about testdata
|
||||
func NewTestDataRegistry() query.DataSourceApiServerRegistry {
|
||||
return &testdataDummy{}
|
||||
}
|
||||
|
||||
// ExecuteQueryData implements QueryHelper.
|
||||
func (d *testdataDummy) QueryData(ctx context.Context, req data.QueryDataRequest) (int, *backend.QueryDataResponse, error) {
|
||||
queries, _, err := data.ToDataSourceQueries(req)
|
||||
if err != nil {
|
||||
return http.StatusBadRequest, nil, err
|
||||
}
|
||||
|
||||
qdr := &backend.QueryDataRequest{Queries: queries}
|
||||
rsp, err := testdata.ProvideService().QueryData(ctx, qdr)
|
||||
return query.GetResponseCode(rsp), rsp, err
|
||||
}
|
||||
|
||||
// GetDatasourceAPI implements DataSourceRegistry.
|
||||
func (*testdataDummy) GetDatasourceGroupVersion(pluginId string) (schema.GroupVersion, error) {
|
||||
if pluginId == "testdata" || pluginId == "grafana-testdata-datasource" {
|
||||
|
||||
Reference in New Issue
Block a user