mirror of
https://github.com/grafana/grafana.git
synced 2025-07-28 14:12:09 +08:00
Chore: Refactor backend plugin errors (#74928)
This commit is contained in:

committed by
GitHub

parent
38d2357bb8
commit
1714fa598c
@ -235,15 +235,15 @@ func TestDataSourceQueryError(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
request: reqValid,
|
request: reqValid,
|
||||||
clientErr: backendplugin.ErrPluginUnavailable,
|
clientErr: plugins.ErrPluginUnavailable,
|
||||||
expectedStatus: http.StatusInternalServerError,
|
expectedStatus: http.StatusInternalServerError,
|
||||||
expectedBody: `{"message":"Internal server error","messageId":"plugin.unavailable","statusCode":500,"traceID":""}`,
|
expectedBody: `{"message":"Plugin unavailable","messageId":"plugin.unavailable","statusCode":500,"traceID":""}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
request: reqValid,
|
request: reqValid,
|
||||||
clientErr: backendplugin.ErrMethodNotImplemented,
|
clientErr: plugins.ErrMethodNotImplemented,
|
||||||
expectedStatus: http.StatusNotImplemented,
|
expectedStatus: http.StatusNotFound,
|
||||||
expectedBody: `{"message":"Not implemented","messageId":"plugin.notImplemented","statusCode":501,"traceID":""}`,
|
expectedBody: `{"message":"Method not implemented","messageId":"plugin.notImplemented","statusCode":404,"traceID":""}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
request: reqValid,
|
request: reqValid,
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
"github.com/grafana/grafana/pkg/plugins"
|
||||||
"github.com/grafana/grafana/pkg/web"
|
"github.com/grafana/grafana/pkg/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ func (hs *HTTPServer) pluginMetricsEndpoint(ctx *web.Context) {
|
|||||||
|
|
||||||
resp, err := hs.pluginClient.CollectMetrics(ctx.Req.Context(), &backend.CollectMetricsRequest{PluginContext: backend.PluginContext{PluginID: pluginID}})
|
resp, err := hs.pluginClient.CollectMetrics(ctx.Req.Context(), &backend.CollectMetricsRequest{PluginContext: backend.PluginContext{PluginID: pluginID}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, backendplugin.ErrPluginNotRegistered) {
|
if errors.Is(err, plugins.ErrPluginNotRegistered) {
|
||||||
ctx.Resp.WriteHeader(http.StatusNotFound)
|
ctx.Resp.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/api/routing"
|
"github.com/grafana/grafana/pkg/api/routing"
|
||||||
"github.com/grafana/grafana/pkg/plugins"
|
"github.com/grafana/grafana/pkg/plugins"
|
||||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/web/webtest"
|
"github.com/grafana/grafana/pkg/web/webtest"
|
||||||
)
|
)
|
||||||
@ -152,7 +151,7 @@ func (c *fakePluginClientMetrics) CollectMetrics(ctx context.Context, req *backe
|
|||||||
metrics, exists := c.store[req.PluginContext.PluginID]
|
metrics, exists := c.store[req.PluginContext.PluginID]
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, backendplugin.ErrPluginNotRegistered
|
return nil, plugins.ErrPluginNotRegistered
|
||||||
}
|
}
|
||||||
|
|
||||||
return &backend.CollectMetricsResult{
|
return &backend.CollectMetricsResult{
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/api/response"
|
"github.com/grafana/grafana/pkg/api/response"
|
||||||
"github.com/grafana/grafana/pkg/middleware/requestmeta"
|
"github.com/grafana/grafana/pkg/middleware/requestmeta"
|
||||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
|
||||||
"github.com/grafana/grafana/pkg/plugins/httpresponsesender"
|
"github.com/grafana/grafana/pkg/plugins/httpresponsesender"
|
||||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||||
"github.com/grafana/grafana/pkg/services/datasources"
|
"github.com/grafana/grafana/pkg/services/datasources"
|
||||||
@ -125,16 +124,6 @@ func (hs *HTTPServer) makePluginResourceRequest(w http.ResponseWriter, req *http
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleCallResourceError(err error, reqCtx *contextmodel.ReqContext) {
|
func handleCallResourceError(err error, reqCtx *contextmodel.ReqContext) {
|
||||||
if errors.Is(err, backendplugin.ErrPluginUnavailable) {
|
|
||||||
reqCtx.JsonApiErr(http.StatusServiceUnavailable, "Plugin unavailable", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if errors.Is(err, backendplugin.ErrMethodNotImplemented) {
|
|
||||||
reqCtx.JsonApiErr(http.StatusNotFound, "Not found", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := response.ErrOrFallback(http.StatusInternalServerError, "Failed to call resource", err)
|
resp := response.ErrOrFallback(http.StatusInternalServerError, "Failed to call resource", err)
|
||||||
resp.WriteTo(reqCtx)
|
resp.WriteTo(reqCtx)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/api/dtos"
|
"github.com/grafana/grafana/pkg/api/dtos"
|
||||||
"github.com/grafana/grafana/pkg/api/response"
|
"github.com/grafana/grafana/pkg/api/response"
|
||||||
"github.com/grafana/grafana/pkg/plugins"
|
"github.com/grafana/grafana/pkg/plugins"
|
||||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
|
||||||
"github.com/grafana/grafana/pkg/plugins/repo"
|
"github.com/grafana/grafana/pkg/plugins/repo"
|
||||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||||
@ -492,18 +491,6 @@ func (hs *HTTPServer) UninstallPlugin(c *contextmodel.ReqContext) response.Respo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func translatePluginRequestErrorToAPIError(err error) response.Response {
|
func translatePluginRequestErrorToAPIError(err error) response.Response {
|
||||||
if errors.Is(err, backendplugin.ErrPluginNotRegistered) {
|
|
||||||
return response.Error(http.StatusNotFound, "Plugin not found", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if errors.Is(err, backendplugin.ErrMethodNotImplemented) {
|
|
||||||
return response.Error(http.StatusNotFound, "Not found", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if errors.Is(err, backendplugin.ErrPluginUnavailable) {
|
|
||||||
return response.Error(http.StatusServiceUnavailable, "Plugin unavailable", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.ErrOrFallback(http.StatusInternalServerError, "Plugin request failed", err)
|
return response.ErrOrFallback(http.StatusInternalServerError, "Plugin request failed", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/plugins"
|
||||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||||
"github.com/grafana/grafana/pkg/plugins/log"
|
"github.com/grafana/grafana/pkg/plugins/log"
|
||||||
)
|
)
|
||||||
@ -70,7 +71,7 @@ func (cp *corePlugin) Target() backendplugin.Target {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cp *corePlugin) CollectMetrics(_ context.Context, _ *backend.CollectMetricsRequest) (*backend.CollectMetricsResult, error) {
|
func (cp *corePlugin) CollectMetrics(_ context.Context, _ *backend.CollectMetricsRequest) (*backend.CollectMetricsResult, error) {
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *corePlugin) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
func (cp *corePlugin) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
||||||
@ -78,7 +79,7 @@ func (cp *corePlugin) CheckHealth(ctx context.Context, req *backend.CheckHealthR
|
|||||||
return cp.CheckHealthHandler.CheckHealth(ctx, req)
|
return cp.CheckHealthHandler.CheckHealth(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *corePlugin) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
func (cp *corePlugin) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||||
@ -86,7 +87,7 @@ func (cp *corePlugin) QueryData(ctx context.Context, req *backend.QueryDataReque
|
|||||||
return cp.QueryDataHandler.QueryData(ctx, req)
|
return cp.QueryDataHandler.QueryData(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *corePlugin) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
func (cp *corePlugin) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
||||||
@ -94,26 +95,26 @@ func (cp *corePlugin) CallResource(ctx context.Context, req *backend.CallResourc
|
|||||||
return cp.CallResourceHandler.CallResource(ctx, req, sender)
|
return cp.CallResourceHandler.CallResource(ctx, req, sender)
|
||||||
}
|
}
|
||||||
|
|
||||||
return backendplugin.ErrMethodNotImplemented
|
return plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *corePlugin) SubscribeStream(ctx context.Context, req *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
|
func (cp *corePlugin) SubscribeStream(ctx context.Context, req *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
|
||||||
if cp.StreamHandler != nil {
|
if cp.StreamHandler != nil {
|
||||||
return cp.StreamHandler.SubscribeStream(ctx, req)
|
return cp.StreamHandler.SubscribeStream(ctx, req)
|
||||||
}
|
}
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *corePlugin) PublishStream(ctx context.Context, req *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
|
func (cp *corePlugin) PublishStream(ctx context.Context, req *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
|
||||||
if cp.StreamHandler != nil {
|
if cp.StreamHandler != nil {
|
||||||
return cp.StreamHandler.PublishStream(ctx, req)
|
return cp.StreamHandler.PublishStream(ctx, req)
|
||||||
}
|
}
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *corePlugin) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error {
|
func (cp *corePlugin) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error {
|
||||||
if cp.StreamHandler != nil {
|
if cp.StreamHandler != nil {
|
||||||
return cp.StreamHandler.RunStream(ctx, req, sender)
|
return cp.StreamHandler.RunStream(ctx, req, sender)
|
||||||
}
|
}
|
||||||
return backendplugin.ErrMethodNotImplemented
|
return plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
"github.com/grafana/grafana/pkg/plugins"
|
||||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/coreplugin"
|
"github.com/grafana/grafana/pkg/plugins/backendplugin/coreplugin"
|
||||||
"github.com/grafana/grafana/pkg/plugins/log"
|
"github.com/grafana/grafana/pkg/plugins/log"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -23,13 +23,13 @@ func TestCorePlugin(t *testing.T) {
|
|||||||
require.False(t, p.Exited())
|
require.False(t, p.Exited())
|
||||||
|
|
||||||
_, err = p.CollectMetrics(context.Background(), &backend.CollectMetricsRequest{})
|
_, err = p.CollectMetrics(context.Background(), &backend.CollectMetricsRequest{})
|
||||||
require.Equal(t, backendplugin.ErrMethodNotImplemented, err)
|
require.Equal(t, plugins.ErrMethodNotImplemented, err)
|
||||||
|
|
||||||
_, err = p.CheckHealth(context.Background(), nil)
|
_, err = p.CheckHealth(context.Background(), nil)
|
||||||
require.Equal(t, backendplugin.ErrMethodNotImplemented, err)
|
require.Equal(t, plugins.ErrMethodNotImplemented, err)
|
||||||
|
|
||||||
err = p.CallResource(context.Background(), nil, nil)
|
err = p.CallResource(context.Background(), nil, nil)
|
||||||
require.Equal(t, backendplugin.ErrMethodNotImplemented, err)
|
require.Equal(t, plugins.ErrMethodNotImplemented, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("New core plugin with handlers set in opts should return expected values", func(t *testing.T) {
|
t.Run("New core plugin with handlers set in opts should return expected values", func(t *testing.T) {
|
||||||
@ -56,7 +56,7 @@ func TestCorePlugin(t *testing.T) {
|
|||||||
require.False(t, p.Exited())
|
require.False(t, p.Exited())
|
||||||
|
|
||||||
_, err = p.CollectMetrics(context.Background(), &backend.CollectMetricsRequest{})
|
_, err = p.CollectMetrics(context.Background(), &backend.CollectMetricsRequest{})
|
||||||
require.Equal(t, backendplugin.ErrMethodNotImplemented, err)
|
require.Equal(t, plugins.ErrMethodNotImplemented, err)
|
||||||
|
|
||||||
_, err = p.CheckHealth(context.Background(), &backend.CheckHealthRequest{})
|
_, err = p.CheckHealth(context.Background(), &backend.CheckHealthRequest{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
package backendplugin
|
|
||||||
|
|
||||||
import "errors"
|
|
||||||
|
|
||||||
var (
|
|
||||||
// ErrPluginNotRegistered error returned when plugin is not registered.
|
|
||||||
ErrPluginNotRegistered = errors.New("plugin not registered")
|
|
||||||
// ErrPluginUnavailable error returned when plugin is unavailable.
|
|
||||||
ErrPluginUnavailable = errors.New("plugin unavailable")
|
|
||||||
// ErrMethodNotImplemented error returned when plugin method not implemented.
|
|
||||||
ErrMethodNotImplemented = errors.New("method not implemented")
|
|
||||||
)
|
|
@ -13,7 +13,7 @@ import (
|
|||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
"github.com/grafana/grafana/pkg/plugins"
|
||||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/pluginextensionv2"
|
"github.com/grafana/grafana/pkg/plugins/backendplugin/pluginextensionv2"
|
||||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/secretsmanagerplugin"
|
"github.com/grafana/grafana/pkg/plugins/backendplugin/secretsmanagerplugin"
|
||||||
"github.com/grafana/grafana/pkg/plugins/log"
|
"github.com/grafana/grafana/pkg/plugins/log"
|
||||||
@ -130,7 +130,7 @@ func (c *ClientV2) CollectMetrics(ctx context.Context, req *backend.CollectMetri
|
|||||||
|
|
||||||
func (c *ClientV2) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
func (c *ClientV2) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
||||||
if c.DiagnosticsClient == nil {
|
if c.DiagnosticsClient == nil {
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
protoContext := backend.ToProto().PluginContext(req.PluginContext)
|
protoContext := backend.ToProto().PluginContext(req.PluginContext)
|
||||||
@ -151,7 +151,7 @@ func (c *ClientV2) CheckHealth(ctx context.Context, req *backend.CheckHealthRequ
|
|||||||
|
|
||||||
func (c *ClientV2) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
func (c *ClientV2) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||||
if c.DataClient == nil {
|
if c.DataClient == nil {
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
protoReq := backend.ToProto().QueryDataRequest(req)
|
protoReq := backend.ToProto().QueryDataRequest(req)
|
||||||
@ -159,7 +159,7 @@ func (c *ClientV2) QueryData(ctx context.Context, req *backend.QueryDataRequest)
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if status.Code(err) == codes.Unimplemented {
|
if status.Code(err) == codes.Unimplemented {
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("%v: %w", "Failed to query data", err)
|
return nil, fmt.Errorf("%v: %w", "Failed to query data", err)
|
||||||
@ -170,14 +170,14 @@ func (c *ClientV2) QueryData(ctx context.Context, req *backend.QueryDataRequest)
|
|||||||
|
|
||||||
func (c *ClientV2) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
func (c *ClientV2) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
||||||
if c.ResourceClient == nil {
|
if c.ResourceClient == nil {
|
||||||
return backendplugin.ErrMethodNotImplemented
|
return plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
protoReq := backend.ToProto().CallResourceRequest(req)
|
protoReq := backend.ToProto().CallResourceRequest(req)
|
||||||
protoStream, err := c.ResourceClient.CallResource(ctx, protoReq)
|
protoStream, err := c.ResourceClient.CallResource(ctx, protoReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if status.Code(err) == codes.Unimplemented {
|
if status.Code(err) == codes.Unimplemented {
|
||||||
return backendplugin.ErrMethodNotImplemented
|
return plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("%v: %w", "Failed to call resource", err)
|
return fmt.Errorf("%v: %w", "Failed to call resource", err)
|
||||||
@ -187,7 +187,7 @@ func (c *ClientV2) CallResource(ctx context.Context, req *backend.CallResourceRe
|
|||||||
protoResp, err := protoStream.Recv()
|
protoResp, err := protoStream.Recv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if status.Code(err) == codes.Unimplemented {
|
if status.Code(err) == codes.Unimplemented {
|
||||||
return backendplugin.ErrMethodNotImplemented
|
return plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
if errors.Is(err, io.EOF) {
|
if errors.Is(err, io.EOF) {
|
||||||
@ -205,7 +205,7 @@ func (c *ClientV2) CallResource(ctx context.Context, req *backend.CallResourceRe
|
|||||||
|
|
||||||
func (c *ClientV2) SubscribeStream(ctx context.Context, req *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
|
func (c *ClientV2) SubscribeStream(ctx context.Context, req *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
|
||||||
if c.StreamClient == nil {
|
if c.StreamClient == nil {
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
protoResp, err := c.StreamClient.SubscribeStream(ctx, backend.ToProto().SubscribeStreamRequest(req))
|
protoResp, err := c.StreamClient.SubscribeStream(ctx, backend.ToProto().SubscribeStreamRequest(req))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -216,7 +216,7 @@ func (c *ClientV2) SubscribeStream(ctx context.Context, req *backend.SubscribeSt
|
|||||||
|
|
||||||
func (c *ClientV2) PublishStream(ctx context.Context, req *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
|
func (c *ClientV2) PublishStream(ctx context.Context, req *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
|
||||||
if c.StreamClient == nil {
|
if c.StreamClient == nil {
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
protoResp, err := c.StreamClient.PublishStream(ctx, backend.ToProto().PublishStreamRequest(req))
|
protoResp, err := c.StreamClient.PublishStream(ctx, backend.ToProto().PublishStreamRequest(req))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -227,14 +227,14 @@ func (c *ClientV2) PublishStream(ctx context.Context, req *backend.PublishStream
|
|||||||
|
|
||||||
func (c *ClientV2) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error {
|
func (c *ClientV2) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error {
|
||||||
if c.StreamClient == nil {
|
if c.StreamClient == nil {
|
||||||
return backendplugin.ErrMethodNotImplemented
|
return plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
protoReq := backend.ToProto().RunStreamRequest(req)
|
protoReq := backend.ToProto().RunStreamRequest(req)
|
||||||
protoStream, err := c.StreamClient.RunStream(ctx, protoReq)
|
protoStream, err := c.StreamClient.RunStream(ctx, protoReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if status.Code(err) == codes.Unimplemented {
|
if status.Code(err) == codes.Unimplemented {
|
||||||
return backendplugin.ErrMethodNotImplemented
|
return plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%v: %w", "Failed to call resource", err)
|
return fmt.Errorf("%v: %w", "Failed to call resource", err)
|
||||||
}
|
}
|
||||||
@ -243,7 +243,7 @@ func (c *ClientV2) RunStream(ctx context.Context, req *backend.RunStreamRequest,
|
|||||||
p, err := protoStream.Recv()
|
p, err := protoStream.Recv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if status.Code(err) == codes.Unimplemented {
|
if status.Code(err) == codes.Unimplemented {
|
||||||
return backendplugin.ErrMethodNotImplemented
|
return plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
if errors.Is(err, io.EOF) {
|
if errors.Is(err, io.EOF) {
|
||||||
return nil
|
return nil
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/hashicorp/go-plugin"
|
"github.com/hashicorp/go-plugin"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/process"
|
"github.com/grafana/grafana/pkg/infra/process"
|
||||||
|
"github.com/grafana/grafana/pkg/plugins"
|
||||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||||
"github.com/grafana/grafana/pkg/plugins/log"
|
"github.com/grafana/grafana/pkg/plugins/log"
|
||||||
)
|
)
|
||||||
@ -141,7 +142,7 @@ func (p *grpcPlugin) getPluginClient() (pluginClient, bool) {
|
|||||||
func (p *grpcPlugin) CollectMetrics(ctx context.Context, req *backend.CollectMetricsRequest) (*backend.CollectMetricsResult, error) {
|
func (p *grpcPlugin) CollectMetrics(ctx context.Context, req *backend.CollectMetricsRequest) (*backend.CollectMetricsResult, error) {
|
||||||
pluginClient, ok := p.getPluginClient()
|
pluginClient, ok := p.getPluginClient()
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, backendplugin.ErrPluginUnavailable
|
return nil, plugins.ErrPluginUnavailable
|
||||||
}
|
}
|
||||||
return pluginClient.CollectMetrics(ctx, req)
|
return pluginClient.CollectMetrics(ctx, req)
|
||||||
}
|
}
|
||||||
@ -149,7 +150,7 @@ func (p *grpcPlugin) CollectMetrics(ctx context.Context, req *backend.CollectMet
|
|||||||
func (p *grpcPlugin) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
func (p *grpcPlugin) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
||||||
pluginClient, ok := p.getPluginClient()
|
pluginClient, ok := p.getPluginClient()
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, backendplugin.ErrPluginUnavailable
|
return nil, plugins.ErrPluginUnavailable
|
||||||
}
|
}
|
||||||
return pluginClient.CheckHealth(ctx, req)
|
return pluginClient.CheckHealth(ctx, req)
|
||||||
}
|
}
|
||||||
@ -157,7 +158,7 @@ func (p *grpcPlugin) CheckHealth(ctx context.Context, req *backend.CheckHealthRe
|
|||||||
func (p *grpcPlugin) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
func (p *grpcPlugin) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||||
pluginClient, ok := p.getPluginClient()
|
pluginClient, ok := p.getPluginClient()
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, backendplugin.ErrPluginUnavailable
|
return nil, plugins.ErrPluginUnavailable
|
||||||
}
|
}
|
||||||
|
|
||||||
return pluginClient.QueryData(ctx, req)
|
return pluginClient.QueryData(ctx, req)
|
||||||
@ -166,7 +167,7 @@ func (p *grpcPlugin) QueryData(ctx context.Context, req *backend.QueryDataReques
|
|||||||
func (p *grpcPlugin) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
func (p *grpcPlugin) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
||||||
pluginClient, ok := p.getPluginClient()
|
pluginClient, ok := p.getPluginClient()
|
||||||
if !ok {
|
if !ok {
|
||||||
return backendplugin.ErrPluginUnavailable
|
return plugins.ErrPluginUnavailable
|
||||||
}
|
}
|
||||||
return pluginClient.CallResource(ctx, req, sender)
|
return pluginClient.CallResource(ctx, req, sender)
|
||||||
}
|
}
|
||||||
@ -174,7 +175,7 @@ func (p *grpcPlugin) CallResource(ctx context.Context, req *backend.CallResource
|
|||||||
func (p *grpcPlugin) SubscribeStream(ctx context.Context, request *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
|
func (p *grpcPlugin) SubscribeStream(ctx context.Context, request *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
|
||||||
pluginClient, ok := p.getPluginClient()
|
pluginClient, ok := p.getPluginClient()
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, backendplugin.ErrPluginUnavailable
|
return nil, plugins.ErrPluginUnavailable
|
||||||
}
|
}
|
||||||
return pluginClient.SubscribeStream(ctx, request)
|
return pluginClient.SubscribeStream(ctx, request)
|
||||||
}
|
}
|
||||||
@ -182,7 +183,7 @@ func (p *grpcPlugin) SubscribeStream(ctx context.Context, request *backend.Subsc
|
|||||||
func (p *grpcPlugin) PublishStream(ctx context.Context, request *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
|
func (p *grpcPlugin) PublishStream(ctx context.Context, request *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
|
||||||
pluginClient, ok := p.getPluginClient()
|
pluginClient, ok := p.getPluginClient()
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, backendplugin.ErrPluginUnavailable
|
return nil, plugins.ErrPluginUnavailable
|
||||||
}
|
}
|
||||||
return pluginClient.PublishStream(ctx, request)
|
return pluginClient.PublishStream(ctx, request)
|
||||||
}
|
}
|
||||||
@ -190,7 +191,7 @@ func (p *grpcPlugin) PublishStream(ctx context.Context, request *backend.Publish
|
|||||||
func (p *grpcPlugin) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error {
|
func (p *grpcPlugin) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error {
|
||||||
pluginClient, ok := p.getPluginClient()
|
pluginClient, ok := p.getPluginClient()
|
||||||
if !ok {
|
if !ok {
|
||||||
return backendplugin.ErrPluginUnavailable
|
return plugins.ErrPluginUnavailable
|
||||||
}
|
}
|
||||||
return pluginClient.RunStream(ctx, req, sender)
|
return pluginClient.RunStream(ctx, req, sender)
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,24 @@ package plugins
|
|||||||
import "github.com/grafana/grafana/pkg/util/errutil"
|
import "github.com/grafana/grafana/pkg/util/errutil"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
errPluginNotRegisteredBase = errutil.NotFound("plugin.notRegistered",
|
||||||
|
errutil.WithPublicMessage("Plugin not registered"))
|
||||||
// ErrPluginNotRegistered error returned when a plugin is not registered.
|
// ErrPluginNotRegistered error returned when a plugin is not registered.
|
||||||
ErrPluginNotRegistered = errutil.NotFound("plugin.notRegistered")
|
ErrPluginNotRegistered = errPluginNotRegisteredBase.Errorf("plugin not registered")
|
||||||
// ErrHealthCheckFailed error returned when a plugin health check failed.
|
|
||||||
ErrHealthCheckFailed = errutil.Internal("plugin.failedHealthCheck")
|
errPluginUnavailableBase = errutil.Internal("plugin.unavailable",
|
||||||
|
errutil.WithPublicMessage("Plugin unavailable"))
|
||||||
// ErrPluginUnavailable error returned when a plugin is unavailable.
|
// ErrPluginUnavailable error returned when a plugin is unavailable.
|
||||||
ErrPluginUnavailable = errutil.Internal("plugin.unavailable")
|
ErrPluginUnavailable = errPluginUnavailableBase.Errorf("plugin unavailable")
|
||||||
|
|
||||||
|
errMethodNotImplementedBase = errutil.NotFound("plugin.notImplemented",
|
||||||
|
errutil.WithPublicMessage("Method not implemented"))
|
||||||
// ErrMethodNotImplemented error returned when a plugin method is not implemented.
|
// ErrMethodNotImplemented error returned when a plugin method is not implemented.
|
||||||
ErrMethodNotImplemented = errutil.NotImplemented("plugin.notImplemented")
|
ErrMethodNotImplemented = errMethodNotImplementedBase.Errorf("method not implemented")
|
||||||
|
|
||||||
// ErrPluginDownstreamError error returned when a plugin request fails.
|
// ErrPluginDownstreamError error returned when a plugin request fails.
|
||||||
ErrPluginDownstreamError = errutil.Internal("plugin.downstreamError",
|
// Exposed as a base error to wrap it with plugin downstream errors.
|
||||||
|
ErrPluginDownstreamErrorBase = errutil.Internal("plugin.downstreamError",
|
||||||
errutil.WithPublicMessage("An error occurred within the plugin"),
|
errutil.WithPublicMessage("An error occurred within the plugin"),
|
||||||
errutil.WithDownstream())
|
errutil.WithDownstream())
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/plugins"
|
"github.com/grafana/grafana/pkg/plugins"
|
||||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
|
||||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/instrumentation"
|
"github.com/grafana/grafana/pkg/plugins/backendplugin/instrumentation"
|
||||||
"github.com/grafana/grafana/pkg/plugins/config"
|
"github.com/grafana/grafana/pkg/plugins/config"
|
||||||
"github.com/grafana/grafana/pkg/plugins/manager/registry"
|
"github.com/grafana/grafana/pkg/plugins/manager/registry"
|
||||||
@ -48,7 +47,7 @@ func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest)
|
|||||||
|
|
||||||
p, exists := s.plugin(ctx, req.PluginContext.PluginID)
|
p, exists := s.plugin(ctx, req.PluginContext.PluginID)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, plugins.ErrPluginNotRegistered.Errorf("%w", backendplugin.ErrPluginNotRegistered)
|
return nil, plugins.ErrPluginNotRegistered
|
||||||
}
|
}
|
||||||
|
|
||||||
var totalBytes float64
|
var totalBytes float64
|
||||||
@ -65,15 +64,15 @@ func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest)
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, backendplugin.ErrMethodNotImplemented) {
|
if errors.Is(err, plugins.ErrMethodNotImplemented) {
|
||||||
return nil, plugins.ErrMethodNotImplemented.Errorf("%w", backendplugin.ErrMethodNotImplemented)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if errors.Is(err, backendplugin.ErrPluginUnavailable) {
|
if errors.Is(err, plugins.ErrPluginUnavailable) {
|
||||||
return nil, plugins.ErrPluginUnavailable.Errorf("%w", backendplugin.ErrPluginUnavailable)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, plugins.ErrPluginDownstreamError.Errorf("client: failed to query data: %w", err)
|
return nil, plugins.ErrPluginDownstreamErrorBase.Errorf("client: failed to query data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for refID, res := range resp.Responses {
|
for refID, res := range resp.Responses {
|
||||||
@ -99,7 +98,7 @@ func (s *Service) CallResource(ctx context.Context, req *backend.CallResourceReq
|
|||||||
|
|
||||||
p, exists := s.plugin(ctx, req.PluginContext.PluginID)
|
p, exists := s.plugin(ctx, req.PluginContext.PluginID)
|
||||||
if !exists {
|
if !exists {
|
||||||
return backendplugin.ErrPluginNotRegistered
|
return plugins.ErrPluginNotRegistered
|
||||||
}
|
}
|
||||||
|
|
||||||
totalBytes := float64(len(req.Body))
|
totalBytes := float64(len(req.Body))
|
||||||
@ -132,7 +131,7 @@ func (s *Service) CallResource(ctx context.Context, req *backend.CallResourceReq
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return plugins.ErrPluginDownstreamError.Errorf("client: failed to call resources: %w", err)
|
return plugins.ErrPluginDownstreamErrorBase.Errorf("client: failed to call resources: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -145,7 +144,7 @@ func (s *Service) CollectMetrics(ctx context.Context, req *backend.CollectMetric
|
|||||||
|
|
||||||
p, exists := s.plugin(ctx, req.PluginContext.PluginID)
|
p, exists := s.plugin(ctx, req.PluginContext.PluginID)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, backendplugin.ErrPluginNotRegistered
|
return nil, plugins.ErrPluginNotRegistered
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp *backend.CollectMetricsResult
|
var resp *backend.CollectMetricsResult
|
||||||
@ -156,7 +155,7 @@ func (s *Service) CollectMetrics(ctx context.Context, req *backend.CollectMetric
|
|||||||
return
|
return
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, plugins.ErrPluginDownstreamError.Errorf("client: failed to collect metrics: %w", err)
|
return nil, plugins.ErrPluginDownstreamErrorBase.Errorf("client: failed to collect metrics: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
@ -169,7 +168,7 @@ func (s *Service) CheckHealth(ctx context.Context, req *backend.CheckHealthReque
|
|||||||
|
|
||||||
p, exists := s.plugin(ctx, req.PluginContext.PluginID)
|
p, exists := s.plugin(ctx, req.PluginContext.PluginID)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, backendplugin.ErrPluginNotRegistered
|
return nil, plugins.ErrPluginNotRegistered
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp *backend.CheckHealthResult
|
var resp *backend.CheckHealthResult
|
||||||
@ -181,15 +180,15 @@ func (s *Service) CheckHealth(ctx context.Context, req *backend.CheckHealthReque
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, backendplugin.ErrMethodNotImplemented) {
|
if errors.Is(err, plugins.ErrMethodNotImplemented) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if errors.Is(err, backendplugin.ErrPluginUnavailable) {
|
if errors.Is(err, plugins.ErrPluginUnavailable) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, plugins.ErrPluginDownstreamError.Errorf("client: failed to check health: %w", err)
|
return nil, plugins.ErrPluginDownstreamErrorBase.Errorf("client: failed to check health: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
@ -202,7 +201,7 @@ func (s *Service) SubscribeStream(ctx context.Context, req *backend.SubscribeStr
|
|||||||
|
|
||||||
plugin, exists := s.plugin(ctx, req.PluginContext.PluginID)
|
plugin, exists := s.plugin(ctx, req.PluginContext.PluginID)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, backendplugin.ErrPluginNotRegistered
|
return nil, plugins.ErrPluginNotRegistered
|
||||||
}
|
}
|
||||||
|
|
||||||
return plugin.SubscribeStream(ctx, req)
|
return plugin.SubscribeStream(ctx, req)
|
||||||
@ -215,7 +214,7 @@ func (s *Service) PublishStream(ctx context.Context, req *backend.PublishStreamR
|
|||||||
|
|
||||||
plugin, exists := s.plugin(ctx, req.PluginContext.PluginID)
|
plugin, exists := s.plugin(ctx, req.PluginContext.PluginID)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, backendplugin.ErrPluginNotRegistered
|
return nil, plugins.ErrPluginNotRegistered
|
||||||
}
|
}
|
||||||
|
|
||||||
return plugin.PublishStream(ctx, req)
|
return plugin.PublishStream(ctx, req)
|
||||||
@ -232,7 +231,7 @@ func (s *Service) RunStream(ctx context.Context, req *backend.RunStreamRequest,
|
|||||||
|
|
||||||
plugin, exists := s.plugin(ctx, req.PluginContext.PluginID)
|
plugin, exists := s.plugin(ctx, req.PluginContext.PluginID)
|
||||||
if !exists {
|
if !exists {
|
||||||
return backendplugin.ErrPluginNotRegistered
|
return plugins.ErrPluginNotRegistered
|
||||||
}
|
}
|
||||||
|
|
||||||
return plugin.RunStream(ctx, req, sender)
|
return plugin.RunStream(ctx, req, sender)
|
||||||
|
@ -30,16 +30,16 @@ func TestQueryData(t *testing.T) {
|
|||||||
expectedError error
|
expectedError error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
err: backendplugin.ErrPluginUnavailable,
|
err: plugins.ErrPluginUnavailable,
|
||||||
expectedError: plugins.ErrPluginUnavailable,
|
expectedError: plugins.ErrPluginUnavailable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
err: backendplugin.ErrMethodNotImplemented,
|
err: plugins.ErrMethodNotImplemented,
|
||||||
expectedError: plugins.ErrMethodNotImplemented,
|
expectedError: plugins.ErrMethodNotImplemented,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
err: errors.New("surprise surprise"),
|
err: errors.New("surprise surprise"),
|
||||||
expectedError: plugins.ErrPluginDownstreamError,
|
expectedError: plugins.ErrPluginDownstreamErrorBase,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ func TestCheckHealth(t *testing.T) {
|
|||||||
client := ProvideService(registry, &config.Cfg{})
|
client := ProvideService(registry, &config.Cfg{})
|
||||||
_, err := client.CheckHealth(context.Background(), &backend.CheckHealthRequest{})
|
_, err := client.CheckHealth(context.Background(), &backend.CheckHealthRequest{})
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.ErrorIs(t, err, backendplugin.ErrPluginNotRegistered)
|
require.ErrorIs(t, err, plugins.ErrPluginNotRegistered)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("non-empty plugin registry", func(t *testing.T) {
|
t.Run("non-empty plugin registry", func(t *testing.T) {
|
||||||
@ -87,17 +87,17 @@ func TestCheckHealth(t *testing.T) {
|
|||||||
expectedError error
|
expectedError error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
err: backendplugin.ErrPluginUnavailable,
|
err: plugins.ErrPluginUnavailable,
|
||||||
expectedError: backendplugin.ErrPluginUnavailable,
|
expectedError: plugins.ErrPluginUnavailable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
||||||
err: backendplugin.ErrMethodNotImplemented,
|
err: plugins.ErrMethodNotImplemented,
|
||||||
expectedError: backendplugin.ErrMethodNotImplemented,
|
expectedError: plugins.ErrMethodNotImplemented,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
err: errors.New("surprise surprise"),
|
err: errors.New("surprise surprise"),
|
||||||
expectedError: plugins.ErrPluginDownstreamError,
|
expectedError: plugins.ErrPluginDownstreamErrorBase,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ func (pc *FakePluginClient) CollectMetrics(ctx context.Context, req *backend.Col
|
|||||||
return pc.CollectMetricsHandlerFunc(ctx, req)
|
return pc.CollectMetricsHandlerFunc(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *FakePluginClient) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
func (pc *FakePluginClient) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
||||||
@ -135,7 +135,7 @@ func (pc *FakePluginClient) CheckHealth(ctx context.Context, req *backend.CheckH
|
|||||||
return pc.CheckHealthHandlerFunc(ctx, req)
|
return pc.CheckHealthHandlerFunc(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *FakePluginClient) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
func (pc *FakePluginClient) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||||
@ -143,7 +143,7 @@ func (pc *FakePluginClient) QueryData(ctx context.Context, req *backend.QueryDat
|
|||||||
return pc.QueryDataHandlerFunc(ctx, req)
|
return pc.QueryDataHandlerFunc(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *FakePluginClient) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
func (pc *FakePluginClient) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
||||||
@ -151,19 +151,19 @@ func (pc *FakePluginClient) CallResource(ctx context.Context, req *backend.CallR
|
|||||||
return pc.CallResourceHandlerFunc(ctx, req, sender)
|
return pc.CallResourceHandlerFunc(ctx, req, sender)
|
||||||
}
|
}
|
||||||
|
|
||||||
return backendplugin.ErrMethodNotImplemented
|
return plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *FakePluginClient) SubscribeStream(_ context.Context, _ *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
|
func (pc *FakePluginClient) SubscribeStream(_ context.Context, _ *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *FakePluginClient) PublishStream(_ context.Context, _ *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
|
func (pc *FakePluginClient) PublishStream(_ context.Context, _ *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *FakePluginClient) RunStream(_ context.Context, _ *backend.RunStreamRequest, _ *backend.StreamSender) error {
|
func (pc *FakePluginClient) RunStream(_ context.Context, _ *backend.RunStreamRequest, _ *backend.StreamSender) error {
|
||||||
return backendplugin.ErrMethodNotImplemented
|
return plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
type FakePluginRegistry struct {
|
type FakePluginRegistry struct {
|
||||||
|
@ -288,7 +288,7 @@ func (p *Plugin) Target() backendplugin.Target {
|
|||||||
func (p *Plugin) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
func (p *Plugin) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||||
pluginClient, ok := p.Client()
|
pluginClient, ok := p.Client()
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, backendplugin.ErrPluginUnavailable
|
return nil, ErrPluginUnavailable
|
||||||
}
|
}
|
||||||
return pluginClient.QueryData(ctx, req)
|
return pluginClient.QueryData(ctx, req)
|
||||||
}
|
}
|
||||||
@ -296,7 +296,7 @@ func (p *Plugin) QueryData(ctx context.Context, req *backend.QueryDataRequest) (
|
|||||||
func (p *Plugin) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
func (p *Plugin) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
||||||
pluginClient, ok := p.Client()
|
pluginClient, ok := p.Client()
|
||||||
if !ok {
|
if !ok {
|
||||||
return backendplugin.ErrPluginUnavailable
|
return ErrPluginUnavailable
|
||||||
}
|
}
|
||||||
return pluginClient.CallResource(ctx, req, sender)
|
return pluginClient.CallResource(ctx, req, sender)
|
||||||
}
|
}
|
||||||
@ -304,7 +304,7 @@ func (p *Plugin) CallResource(ctx context.Context, req *backend.CallResourceRequ
|
|||||||
func (p *Plugin) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
func (p *Plugin) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
||||||
pluginClient, ok := p.Client()
|
pluginClient, ok := p.Client()
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, backendplugin.ErrPluginUnavailable
|
return nil, ErrPluginUnavailable
|
||||||
}
|
}
|
||||||
return pluginClient.CheckHealth(ctx, req)
|
return pluginClient.CheckHealth(ctx, req)
|
||||||
}
|
}
|
||||||
@ -312,7 +312,7 @@ func (p *Plugin) CheckHealth(ctx context.Context, req *backend.CheckHealthReques
|
|||||||
func (p *Plugin) CollectMetrics(ctx context.Context, req *backend.CollectMetricsRequest) (*backend.CollectMetricsResult, error) {
|
func (p *Plugin) CollectMetrics(ctx context.Context, req *backend.CollectMetricsRequest) (*backend.CollectMetricsResult, error) {
|
||||||
pluginClient, ok := p.Client()
|
pluginClient, ok := p.Client()
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, backendplugin.ErrPluginUnavailable
|
return nil, ErrPluginUnavailable
|
||||||
}
|
}
|
||||||
return pluginClient.CollectMetrics(ctx, req)
|
return pluginClient.CollectMetrics(ctx, req)
|
||||||
}
|
}
|
||||||
@ -320,7 +320,7 @@ func (p *Plugin) CollectMetrics(ctx context.Context, req *backend.CollectMetrics
|
|||||||
func (p *Plugin) SubscribeStream(ctx context.Context, req *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
|
func (p *Plugin) SubscribeStream(ctx context.Context, req *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
|
||||||
pluginClient, ok := p.Client()
|
pluginClient, ok := p.Client()
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, backendplugin.ErrPluginUnavailable
|
return nil, ErrPluginUnavailable
|
||||||
}
|
}
|
||||||
return pluginClient.SubscribeStream(ctx, req)
|
return pluginClient.SubscribeStream(ctx, req)
|
||||||
}
|
}
|
||||||
@ -328,7 +328,7 @@ func (p *Plugin) SubscribeStream(ctx context.Context, req *backend.SubscribeStre
|
|||||||
func (p *Plugin) PublishStream(ctx context.Context, req *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
|
func (p *Plugin) PublishStream(ctx context.Context, req *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
|
||||||
pluginClient, ok := p.Client()
|
pluginClient, ok := p.Client()
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, backendplugin.ErrPluginUnavailable
|
return nil, ErrPluginUnavailable
|
||||||
}
|
}
|
||||||
return pluginClient.PublishStream(ctx, req)
|
return pluginClient.PublishStream(ctx, req)
|
||||||
}
|
}
|
||||||
@ -336,7 +336,7 @@ func (p *Plugin) PublishStream(ctx context.Context, req *backend.PublishStreamRe
|
|||||||
func (p *Plugin) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error {
|
func (p *Plugin) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error {
|
||||||
pluginClient, ok := p.Client()
|
pluginClient, ok := p.Client()
|
||||||
if !ok {
|
if !ok {
|
||||||
return backendplugin.ErrPluginUnavailable
|
return ErrPluginUnavailable
|
||||||
}
|
}
|
||||||
return pluginClient.RunStream(ctx, req, sender)
|
return pluginClient.RunStream(ctx, req, sender)
|
||||||
}
|
}
|
||||||
|
@ -880,7 +880,7 @@ func (tp *testPlugin) Target() backendplugin.Target {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tp *testPlugin) CollectMetrics(_ context.Context, _ *backend.CollectMetricsRequest) (*backend.CollectMetricsResult, error) {
|
func (tp *testPlugin) CollectMetrics(_ context.Context, _ *backend.CollectMetricsRequest) (*backend.CollectMetricsResult, error) {
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tp *testPlugin) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
func (tp *testPlugin) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
||||||
@ -888,7 +888,7 @@ func (tp *testPlugin) CheckHealth(ctx context.Context, req *backend.CheckHealthR
|
|||||||
return tp.CheckHealthHandler.CheckHealth(ctx, req)
|
return tp.CheckHealthHandler.CheckHealth(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tp *testPlugin) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
func (tp *testPlugin) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||||
@ -896,7 +896,7 @@ func (tp *testPlugin) QueryData(ctx context.Context, req *backend.QueryDataReque
|
|||||||
return tp.QueryDataHandler.QueryData(ctx, req)
|
return tp.QueryDataHandler.QueryData(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tp *testPlugin) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
func (tp *testPlugin) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
||||||
@ -904,28 +904,28 @@ func (tp *testPlugin) CallResource(ctx context.Context, req *backend.CallResourc
|
|||||||
return tp.CallResourceHandler.CallResource(ctx, req, sender)
|
return tp.CallResourceHandler.CallResource(ctx, req, sender)
|
||||||
}
|
}
|
||||||
|
|
||||||
return backendplugin.ErrMethodNotImplemented
|
return plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tp *testPlugin) SubscribeStream(ctx context.Context, req *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
|
func (tp *testPlugin) SubscribeStream(ctx context.Context, req *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
|
||||||
if tp.StreamHandler != nil {
|
if tp.StreamHandler != nil {
|
||||||
return tp.StreamHandler.SubscribeStream(ctx, req)
|
return tp.StreamHandler.SubscribeStream(ctx, req)
|
||||||
}
|
}
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tp *testPlugin) PublishStream(ctx context.Context, req *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
|
func (tp *testPlugin) PublishStream(ctx context.Context, req *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
|
||||||
if tp.StreamHandler != nil {
|
if tp.StreamHandler != nil {
|
||||||
return tp.StreamHandler.PublishStream(ctx, req)
|
return tp.StreamHandler.PublishStream(ctx, req)
|
||||||
}
|
}
|
||||||
return nil, backendplugin.ErrMethodNotImplemented
|
return nil, plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tp *testPlugin) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error {
|
func (tp *testPlugin) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error {
|
||||||
if tp.StreamHandler != nil {
|
if tp.StreamHandler != nil {
|
||||||
return tp.StreamHandler.RunStream(ctx, req, sender)
|
return tp.StreamHandler.RunStream(ctx, req, sender)
|
||||||
}
|
}
|
||||||
return backendplugin.ErrMethodNotImplemented
|
return plugins.ErrMethodNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func metricRequestWithQueries(t *testing.T, rawQueries ...string) dtos.MetricRequest {
|
func metricRequestWithQueries(t *testing.T, rawQueries ...string) dtos.MetricRequest {
|
||||||
|
Reference in New Issue
Block a user