Plugins: Expose backendplugin for client proto interface (#86207)

* first pass

* tidy

* add err check

* remove comment

* simplify

* remove unused stuff

* add backend()

* use SDK commit

* add codeowners for go.mod

* fix go.mod

* bump SDK

* go work sync
This commit is contained in:
Will Browne
2024-04-17 18:47:01 +02:00
committed by GitHub
parent 4bb0b78abb
commit dceb83ab42
10 changed files with 316 additions and 127 deletions
@@ -9,6 +9,8 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/genproto/pluginv2"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/backendplugin"
"github.com/grafana/grafana/pkg/plugins/log"
)
@@ -27,6 +29,8 @@ type ProtoClient interface {
PID(context.Context) (string, error)
PluginID() string
PluginVersion() string
PluginJSON() plugins.JSONData
Backend() backendplugin.Plugin
Logger() log.Logger
Start(context.Context) error
Stop(context.Context) error
@@ -36,13 +40,13 @@ type ProtoClient interface {
type protoClient struct {
plugin *grpcPlugin
pluginVersion string
pluginJSON plugins.JSONData
mu sync.RWMutex
}
type ProtoClientOpts struct {
PluginID string
PluginVersion string
PluginJSON plugins.JSONData
ExecutablePath string
ExecutableArgs []string
Env []string
@@ -52,7 +56,7 @@ type ProtoClientOpts struct {
func NewProtoClient(opts ProtoClientOpts) (ProtoClient, error) {
p := newGrpcPlugin(
PluginDescriptor{
pluginID: opts.PluginID,
pluginID: opts.PluginJSON.ID,
managed: true,
executablePath: opts.ExecutablePath,
executableArgs: opts.ExecutableArgs,
@@ -62,7 +66,7 @@ func NewProtoClient(opts ProtoClientOpts) (ProtoClient, error) {
func() []string { return opts.Env },
)
return &protoClient{plugin: p, pluginVersion: opts.PluginVersion}, nil
return &protoClient{plugin: p, pluginVersion: opts.PluginJSON.Info.Version, pluginJSON: opts.PluginJSON}, nil
}
func (r *protoClient) PID(ctx context.Context) (string, error) {
@@ -80,6 +84,14 @@ func (r *protoClient) PluginVersion() string {
return r.pluginVersion
}
func (r *protoClient) PluginJSON() plugins.JSONData {
return r.pluginJSON
}
func (r *protoClient) Backend() backendplugin.Plugin {
return r.plugin
}
func (r *protoClient) Logger() log.Logger {
return r.plugin.logger
}