From 10650ae196bab87fe0e08db01c61713968442ec1 Mon Sep 17 00:00:00 2001 From: Nathan Verzemnieks Date: Fri, 9 Jan 2026 12:34:36 +0100 Subject: [PATCH] Trying a different approach using a go-plugin RunnerFunc --- .../backendplugin/grpcplugin/client.go | 22 +++++++++---------- .../backendplugin/grpcplugin/client_proto.go | 6 +++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/plugins/backendplugin/grpcplugin/client.go b/pkg/plugins/backendplugin/grpcplugin/client.go index 8f6e3fe209f..82d61ad9667 100644 --- a/pkg/plugins/backendplugin/grpcplugin/client.go +++ b/pkg/plugins/backendplugin/grpcplugin/client.go @@ -65,16 +65,7 @@ func newClientConfig(descriptor PluginDescriptor, env []string, logger log.Logge if runtime.GOOS == "linux" && descriptor.containerMode.enabled { return containerClientConfig(executablePath, descriptor.containerMode.image, descriptor.containerMode.tag, logger, versionedPlugins, skipHostEnvVars, tracer) } - - logger.Debug("Using process mode", "os", runtime.GOOS, "executablePath", executablePath) - - // We can ignore gosec G201 here, since the dynamic part of executablePath comes from the plugin definition - // nolint:gosec - cmd := exec.Command(executablePath, descriptor.executableArgs...) - cmd.Env = env - cfg := &goplugin.ClientConfig{ - Cmd: cmd, HandshakeConfig: handshake, VersionedPlugins: versionedPlugins, SkipHostEnv: skipHostEnvVars, @@ -91,8 +82,15 @@ func newClientConfig(descriptor PluginDescriptor, env []string, logger log.Logge }, } - if descriptor.cmdEditor != nil { - descriptor.cmdEditor(cfg.Cmd) + if descriptor.runnerFunc != nil { + cfg.RunnerFunc = descriptor.runnerFunc + logger.Debug("Using runner mode", "os", runtime.GOOS, "executablePath", executablePath) + } else { + logger.Debug("Using process mode", "os", runtime.GOOS, "executablePath", executablePath) + // We can ignore gosec G201 here, since the dynamic part of executablePath comes from the plugin definition + // nolint:gosec + cfg.Cmd = exec.Command(executablePath, descriptor.executableArgs...) + cfg.Cmd.Env = env } return cfg @@ -133,7 +131,7 @@ type PluginDescriptor struct { skipHostEnvVars bool managed bool containerMode containerModeOpts - cmdEditor func(*exec.Cmd) + runnerFunc func(l hclog.Logger, cmd *exec.Cmd, tmpDir string) (runner.Runner, error) versionedPlugins map[int]goplugin.PluginSet startRendererFn StartRendererFunc } diff --git a/pkg/plugins/backendplugin/grpcplugin/client_proto.go b/pkg/plugins/backendplugin/grpcplugin/client_proto.go index 2279a0e63ba..f76494664cc 100644 --- a/pkg/plugins/backendplugin/grpcplugin/client_proto.go +++ b/pkg/plugins/backendplugin/grpcplugin/client_proto.go @@ -3,6 +3,8 @@ package grpcplugin import ( "context" "errors" + "github.com/hashicorp/go-hclog" + "github.com/hashicorp/go-plugin/runner" "os/exec" "go.opentelemetry.io/otel/trace" @@ -50,10 +52,10 @@ type ProtoClientOpts struct { ExecutableArgs []string Env []string ContainerMode ContainerModeOpts + RunnerFunc func(l hclog.Logger, cmd *exec.Cmd, tmpDir string) (runner.Runner, error) SkipHostEnvVars bool Logger log.Logger Tracer trace.Tracer - CmdEditor func(*exec.Cmd) } type ContainerModeOpts struct { @@ -75,7 +77,7 @@ func NewProtoClient(opts ProtoClientOpts) (ProtoClient, error) { image: opts.ContainerMode.Image, tag: opts.ContainerMode.Tag, }, - cmdEditor: opts.CmdEditor, + runnerFunc: opts.RunnerFunc, skipHostEnvVars: opts.SkipHostEnvVars, }, opts.Logger,