diff --git a/client/allocrunner/taskrunner/plugin_supervisor_hook.go b/client/allocrunner/taskrunner/plugin_supervisor_hook.go index 5774c4548..5169275e8 100644 --- a/client/allocrunner/taskrunner/plugin_supervisor_hook.go +++ b/client/allocrunner/taskrunner/plugin_supervisor_hook.go @@ -294,7 +294,7 @@ func (h *csiPluginSupervisorHook) supervisorLoopOnce(ctx context.Context, socket return false, fmt.Errorf("failed to stat socket: %v", err) } - client, err := csi.NewClient(socketPath) + client, err := csi.NewClient(socketPath, h.logger.Named("csi_client").With("plugin.name", h.task.CSIPluginConfig.ID, "plugin.type", h.task.CSIPluginConfig.Type)) defer client.Close() if err != nil { return false, fmt.Errorf("failed to create csi client: %v", err) diff --git a/client/client.go b/client/client.go index aa9ecbf97..b67ae389e 100644 --- a/client/client.go +++ b/client/client.go @@ -343,10 +343,10 @@ func NewClient(cfg *config.Config, consulCatalog consul.CatalogAPI, consulServic serversContactedOnce: sync.Once{}, dynamicRegistry: dynamicplugins.NewRegistry(map[string]dynamicplugins.PluginDispenser{ dynamicplugins.PluginTypeCSIController: func(info *dynamicplugins.PluginInfo) (interface{}, error) { - return csi.NewClient(info.ConnectionInfo.SocketPath) + return csi.NewClient(info.ConnectionInfo.SocketPath, logger.Named("csi_client").With("plugin.name", info.Name, "plugin.type", "controller")) }, dynamicplugins.PluginTypeCSINode: func(info *dynamicplugins.PluginInfo) (interface{}, error) { - return csi.NewClient(info.ConnectionInfo.SocketPath) + return csi.NewClient(info.ConnectionInfo.SocketPath, logger.Named("csi_client").With("plugin.name", info.Name, "plugin.type", "client")) }, }), } diff --git a/client/pluginmanager/csimanager/instance.go b/client/pluginmanager/csimanager/instance.go index 8aa4e2b06..5240c9b8f 100644 --- a/client/pluginmanager/csimanager/instance.go +++ b/client/pluginmanager/csimanager/instance.go @@ -50,7 +50,7 @@ func newInstanceManager(logger hclog.Logger, updater UpdateNodeCSIInfoFunc, p *d } func (i *instanceManager) run() { - c, err := csi.NewClient(i.info.ConnectionInfo.SocketPath) + c, err := csi.NewClient(i.info.ConnectionInfo.SocketPath, i.logger.Named("csi_client").With("plugin.name", i.info.Name, "plugin.type", i.info.Type)) if err != nil { i.logger.Error("failed to setup instance manager client", "error", err) close(i.shutdownCh) diff --git a/plugins/csi/client.go b/plugins/csi/client.go index 8d45a7f71..556f9142a 100644 --- a/plugins/csi/client.go +++ b/plugins/csi/client.go @@ -7,7 +7,9 @@ import ( "time" csipbv1 "github.com/container-storage-interface/spec/lib/go/csi" + "github.com/hashicorp/go-hclog" "github.com/hashicorp/nomad/helper" + "github.com/hashicorp/nomad/helper/grpc-middleware/logging" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/shared/hclspec" "google.golang.org/grpc" @@ -81,12 +83,12 @@ func (c *client) Close() error { return nil } -func NewClient(addr string) (CSIPlugin, error) { +func NewClient(addr string, logger hclog.Logger) (CSIPlugin, error) { if addr == "" { return nil, fmt.Errorf("address is empty") } - conn, err := newGrpcConn(addr) + conn, err := newGrpcConn(addr, logger) if err != nil { return nil, err } @@ -99,10 +101,12 @@ func NewClient(addr string) (CSIPlugin, error) { }, nil } -func newGrpcConn(addr string) (*grpc.ClientConn, error) { +func newGrpcConn(addr string, logger hclog.Logger) (*grpc.ClientConn, error) { conn, err := grpc.Dial( addr, grpc.WithInsecure(), + grpc.WithUnaryInterceptor(logging.UnaryClientInterceptor(logger)), + grpc.WithStreamInterceptor(logging.StreamClientInterceptor(logger)), grpc.WithDialer(func(target string, timeout time.Duration) (net.Conn, error) { return net.DialTimeout("unix", target, timeout) }),