mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 02:02:33 +08:00
Plugins: Remove support for deprecated backend plugin protocol version (#34127)
* 33959: Remove support for deprecated backend plugin protocol (v1) * 33959: Remove unused methods * 33959: Remove some additional unused code * 33959: Remove some additional unused code * 33959: Remove datasource plugin wrapper with test * 33959:Remove DefaultProtocolVersion
This commit is contained in:
@ -3,8 +3,6 @@ package grpcplugin
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
datasourceV1 "github.com/grafana/grafana-plugin-model/go/datasource"
|
||||
rendererV1 "github.com/grafana/grafana-plugin-model/go/renderer"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/grpcplugin"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||
@ -12,19 +10,12 @@ import (
|
||||
goplugin "github.com/hashicorp/go-plugin"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultProtocolVersion is the protocol version assumed for legacy clients that don't specify
|
||||
// a particular version or version 1 during their handshake. This is currently the version used
|
||||
// since Grafana launched support for backend plugins.
|
||||
DefaultProtocolVersion = 1
|
||||
)
|
||||
|
||||
// Handshake is the HandshakeConfig used to configure clients and servers.
|
||||
var handshake = goplugin.HandshakeConfig{
|
||||
// The ProtocolVersion is the version that must match between Grafana core
|
||||
// and Grafana plugins. This should be bumped whenever a (breaking) change
|
||||
// happens in one or the other that makes it so that they can't safely communicate.
|
||||
ProtocolVersion: DefaultProtocolVersion,
|
||||
ProtocolVersion: grpcplugin.ProtocolVersion,
|
||||
|
||||
// The magic cookie values should NEVER be changed.
|
||||
MagicCookieKey: grpcplugin.MagicCookieKey,
|
||||
@ -47,16 +38,12 @@ func newClientConfig(executablePath string, env []string, logger log.Logger,
|
||||
}
|
||||
}
|
||||
|
||||
// LegacyStartFunc callback function called when a plugin with old plugin protocol is started.
|
||||
type LegacyStartFunc func(pluginID string, client *LegacyClient, logger log.Logger) error
|
||||
|
||||
// StartFunc callback function called when a plugin with current plugin protocol version is started.
|
||||
type StartFunc func(pluginID string, client *Client, logger log.Logger) error
|
||||
|
||||
// PluginStartFuncs functions called for plugin when started.
|
||||
type PluginStartFuncs struct {
|
||||
OnLegacyStart LegacyStartFunc
|
||||
OnStart StartFunc
|
||||
OnStart StartFunc
|
||||
}
|
||||
|
||||
// PluginDescriptor is a descriptor used for registering backend plugins.
|
||||
@ -86,9 +73,6 @@ func NewBackendPlugin(pluginID, executablePath string, startFns PluginStartFuncs
|
||||
executablePath: executablePath,
|
||||
managed: true,
|
||||
versionedPlugins: map[int]goplugin.PluginSet{
|
||||
DefaultProtocolVersion: {
|
||||
pluginID: &datasourceV1.DatasourcePluginImpl{},
|
||||
},
|
||||
grpcplugin.ProtocolVersion: getV2PluginSet(),
|
||||
},
|
||||
startFns: startFns,
|
||||
@ -102,21 +86,12 @@ func NewRendererPlugin(pluginID, executablePath string, startFns PluginStartFunc
|
||||
executablePath: executablePath,
|
||||
managed: false,
|
||||
versionedPlugins: map[int]goplugin.PluginSet{
|
||||
DefaultProtocolVersion: {
|
||||
pluginID: &rendererV1.RendererPluginImpl{},
|
||||
},
|
||||
grpcplugin.ProtocolVersion: getV2PluginSet(),
|
||||
},
|
||||
startFns: startFns,
|
||||
})
|
||||
}
|
||||
|
||||
// LegacyClient client for communicating with a plugin using the v1 plugin protocol.
|
||||
type LegacyClient struct {
|
||||
DatasourcePlugin datasourceV1.DatasourcePlugin
|
||||
RendererPlugin rendererV1.RendererPlugin
|
||||
}
|
||||
|
||||
// Client client for communicating with a plugin using the current (v2) plugin protocol.
|
||||
type Client struct {
|
||||
DataPlugin grpcplugin.DataClient
|
||||
|
@ -1,97 +0,0 @@
|
||||
package grpcplugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
datasourceV1 "github.com/grafana/grafana-plugin-model/go/datasource"
|
||||
rendererV1 "github.com/grafana/grafana-plugin-model/go/renderer"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/instrumentation"
|
||||
"github.com/hashicorp/go-plugin"
|
||||
)
|
||||
|
||||
type clientV1 struct {
|
||||
logger log.Logger
|
||||
datasourceV1.DatasourcePlugin
|
||||
rendererV1.RendererPlugin
|
||||
}
|
||||
|
||||
func newClientV1(descriptor PluginDescriptor, logger log.Logger, rpcClient plugin.ClientProtocol) (pluginClient, error) {
|
||||
logger.Warn("Plugin uses a deprecated version of Grafana's backend plugin system which will be removed in a future release. " +
|
||||
"Consider upgrading to a newer plugin version or reach out to the plugin repository/developer and request an upgrade.")
|
||||
|
||||
raw, err := rpcClient.Dispense(descriptor.pluginID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c := clientV1{
|
||||
logger: logger,
|
||||
}
|
||||
if plugin, ok := raw.(datasourceV1.DatasourcePlugin); ok {
|
||||
c.DatasourcePlugin = instrumentDatasourcePluginV1(plugin)
|
||||
}
|
||||
|
||||
if plugin, ok := raw.(rendererV1.RendererPlugin); ok {
|
||||
c.RendererPlugin = plugin
|
||||
}
|
||||
|
||||
if descriptor.startFns.OnLegacyStart != nil {
|
||||
legacyClient := &LegacyClient{
|
||||
DatasourcePlugin: c.DatasourcePlugin,
|
||||
RendererPlugin: c.RendererPlugin,
|
||||
}
|
||||
if err := descriptor.startFns.OnLegacyStart(descriptor.pluginID, legacyClient, logger); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
func (c *clientV1) CollectMetrics(ctx context.Context) (*backend.CollectMetricsResult, error) {
|
||||
return nil, backendplugin.ErrMethodNotImplemented
|
||||
}
|
||||
|
||||
func (c *clientV1) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
||||
return nil, backendplugin.ErrMethodNotImplemented
|
||||
}
|
||||
|
||||
func (c *clientV1) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
||||
return backendplugin.ErrMethodNotImplemented
|
||||
}
|
||||
|
||||
func (c *clientV1) SubscribeStream(ctx context.Context, request *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
|
||||
return nil, backendplugin.ErrMethodNotImplemented
|
||||
}
|
||||
|
||||
func (c *clientV1) PublishStream(ctx context.Context, request *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
|
||||
return nil, backendplugin.ErrMethodNotImplemented
|
||||
}
|
||||
|
||||
func (c *clientV1) RunStream(ctx context.Context, request *backend.RunStreamRequest, sender backend.StreamPacketSender) error {
|
||||
return backendplugin.ErrMethodNotImplemented
|
||||
}
|
||||
|
||||
type datasourceV1QueryFunc func(ctx context.Context, req *datasourceV1.DatasourceRequest) (*datasourceV1.DatasourceResponse, error)
|
||||
|
||||
func (fn datasourceV1QueryFunc) Query(ctx context.Context, req *datasourceV1.DatasourceRequest) (*datasourceV1.DatasourceResponse, error) {
|
||||
return fn(ctx, req)
|
||||
}
|
||||
|
||||
func instrumentDatasourcePluginV1(plugin datasourceV1.DatasourcePlugin) datasourceV1.DatasourcePlugin {
|
||||
if plugin == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return datasourceV1QueryFunc(func(ctx context.Context, req *datasourceV1.DatasourceRequest) (*datasourceV1.DatasourceResponse, error) {
|
||||
var resp *datasourceV1.DatasourceResponse
|
||||
err := instrumentation.InstrumentQueryDataRequest(req.Datasource.Type, func() (innerErr error) {
|
||||
resp, innerErr = plugin.Query(ctx, req)
|
||||
return
|
||||
})
|
||||
return resp, err
|
||||
})
|
||||
}
|
@ -59,16 +59,12 @@ func (p *grpcPlugin) Start(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if p.client.NegotiatedVersion() > 1 {
|
||||
p.pluginClient, err = newClientV2(p.descriptor, p.logger, rpcClient)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
p.pluginClient, err = newClientV1(p.descriptor, p.logger, rpcClient)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if p.client.NegotiatedVersion() < 2 {
|
||||
return errors.New("plugin protocol version not supported")
|
||||
}
|
||||
p.pluginClient, err = newClientV2(p.descriptor, p.logger, rpcClient)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if p.pluginClient == nil {
|
||||
|
Reference in New Issue
Block a user