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

committed by
GitHub

parent
38d2357bb8
commit
1714fa598c
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"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/log"
|
||||
)
|
||||
@ -70,7 +71,7 @@ func (cp *corePlugin) Target() backendplugin.Target {
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -78,7 +79,7 @@ func (cp *corePlugin) CheckHealth(ctx context.Context, req *backend.CheckHealthR
|
||||
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) {
|
||||
@ -86,7 +87,7 @@ func (cp *corePlugin) QueryData(ctx context.Context, req *backend.QueryDataReque
|
||||
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 {
|
||||
@ -94,26 +95,26 @@ func (cp *corePlugin) CallResource(ctx context.Context, req *backend.CallResourc
|
||||
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) {
|
||||
if cp.StreamHandler != nil {
|
||||
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) {
|
||||
if cp.StreamHandler != nil {
|
||||
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 {
|
||||
if cp.StreamHandler != nil {
|
||||
return cp.StreamHandler.RunStream(ctx, req, sender)
|
||||
}
|
||||
return backendplugin.ErrMethodNotImplemented
|
||||
return plugins.ErrMethodNotImplemented
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"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/log"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -23,13 +23,13 @@ func TestCorePlugin(t *testing.T) {
|
||||
require.False(t, p.Exited())
|
||||
|
||||
_, 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)
|
||||
require.Equal(t, backendplugin.ErrMethodNotImplemented, err)
|
||||
require.Equal(t, plugins.ErrMethodNotImplemented, err)
|
||||
|
||||
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) {
|
||||
@ -56,7 +56,7 @@ func TestCorePlugin(t *testing.T) {
|
||||
require.False(t, p.Exited())
|
||||
|
||||
_, 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{})
|
||||
require.NoError(t, err)
|
||||
|
Reference in New Issue
Block a user