From d24986ecfd3c7eec6712812c712b33388be873a2 Mon Sep 17 00:00:00 2001 From: Mathew Merrick Date: Thu, 23 Jan 2025 14:28:23 -0800 Subject: [PATCH] address lints --- pkg/plugin/pktmon/pktmon_grpc_windows.go | 22 ++++++++++------------ pkg/plugin/pktmon/pktmon_windows.go | 2 +- pkg/plugin/pktmon/pktmon_windows_test.go | 9 ++++++--- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pkg/plugin/pktmon/pktmon_grpc_windows.go b/pkg/plugin/pktmon/pktmon_grpc_windows.go index 06300a27e3..c63e068b5a 100644 --- a/pkg/plugin/pktmon/pktmon_grpc_windows.go +++ b/pkg/plugin/pktmon/pktmon_grpc_windows.go @@ -18,9 +18,7 @@ import ( "google.golang.org/grpc/credentials/insecure" ) -var ( - ErrNilStream = errors.New("stream is nil") -) +var ErrNilStream = errors.New("stream is nil") type GRPCManager interface { SetupStream() error @@ -31,7 +29,7 @@ type GRPCManager interface { Stop() error } -type PktmonGRPCManager struct { +type WindowsGRPCManager struct { grpcClient *GRPCClient stream observerv1.Observer_GetFlowsClient l *log.ZapLogger @@ -41,7 +39,7 @@ type PktmonGRPCManager struct { errWriter *zapio.Writer } -func (p *PktmonGRPCManager) SetupStream() error { +func (p *WindowsGRPCManager) SetupStream() error { var err error fn := func() error { p.l.Info("creating pktmon client") @@ -60,7 +58,7 @@ func (p *PktmonGRPCManager) SetupStream() error { return nil } -func (p *PktmonGRPCManager) StartStream(ctx context.Context) error { +func (p *WindowsGRPCManager) StartStream(ctx context.Context) error { if p.grpcClient == nil { return errors.Wrapf(ErrNilGrpcClient, "unable to start stream") } @@ -81,12 +79,12 @@ func (p *PktmonGRPCManager) StartStream(ctx context.Context) error { return nil } -func (p *PktmonGRPCManager) ReceiveFromStream() (*observerv1.GetFlowsResponse, error) { +func (p *WindowsGRPCManager) ReceiveFromStream() (*observerv1.GetFlowsResponse, error) { if p.stream == nil { return nil, errors.Wrapf(ErrNilStream, "unable to receive from stream") } - return p.stream.Recv() + return p.stream.Recv() //nolint:wrapcheck // wrapcheck is disabled because we want to return the error as is } func newGRPCClient() (*GRPCClient, error) { @@ -112,15 +110,15 @@ func newGRPCClient() (*GRPCClient, error) { retryPolicyStr := string(bytes) - conn, err := grpc.Dial(fmt.Sprintf("%s:%s", "unix", socket), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultServiceConfig(retryPolicyStr)) + conn, err := grpc.NewClient(fmt.Sprintf("%s:%s", "unix", socket), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultServiceConfig(retryPolicyStr)) if err != nil { - return nil, errors.Wrapf(err, "failed to dial pktmon server:") + return nil, errors.Wrapf(err, "failed to dial pktmon server") } return &GRPCClient{observerv1.NewObserverClient(conn)}, nil } -func (p *PktmonGRPCManager) RunPktMonServer(ctx context.Context) error { +func (p *WindowsGRPCManager) RunPktMonServer(ctx context.Context) error { p.stdWriter = &zapio.Writer{Log: p.l.Logger, Level: zap.InfoLevel} defer p.stdWriter.Close() p.errWriter = &zapio.Writer{Log: p.l.Logger, Level: zap.ErrorLevel} @@ -152,7 +150,7 @@ func (p *PktmonGRPCManager) RunPktMonServer(ctx context.Context) error { return errors.Wrapf(ErrUnexpectedExit, "pktmon server exited unexpectedly") } -func (p *PktmonGRPCManager) Stop() error { +func (p *WindowsGRPCManager) Stop() error { if p.pktmonCmd != nil { err := p.pktmonCmd.Process.Kill() if err != nil { diff --git a/pkg/plugin/pktmon/pktmon_windows.go b/pkg/plugin/pktmon/pktmon_windows.go index edd0311400..6688596d80 100644 --- a/pkg/plugin/pktmon/pktmon_windows.go +++ b/pkg/plugin/pktmon/pktmon_windows.go @@ -53,7 +53,7 @@ func New(*kcfg.Config) registry.Plugin { } func (p *Plugin) Init() error { - p.grpcManager = &PktmonGRPCManager{ + p.grpcManager = &WindowsGRPCManager{ l: p.l, } return nil diff --git a/pkg/plugin/pktmon/pktmon_windows_test.go b/pkg/plugin/pktmon/pktmon_windows_test.go index c78a1b1fe5..1451957739 100644 --- a/pkg/plugin/pktmon/pktmon_windows_test.go +++ b/pkg/plugin/pktmon/pktmon_windows_test.go @@ -6,6 +6,7 @@ import ( observerv1 "github.com/cilium/cilium/api/v1/observer" "github.com/microsoft/retina/pkg/log" + "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -24,7 +25,7 @@ func (p *TestGRPCManager) RunPktMonServer(ctx context.Context) error { return nil } -func (p *TestGRPCManager) StartStream(ctx context.Context) error { +func (p *TestGRPCManager) StartStream(_ context.Context) error { return nil } @@ -40,7 +41,9 @@ func (p *TestGRPCManager) Stop() error { func TestStart(t *testing.T) { opts := log.GetDefaultLogOpts() - log.SetupZapLogger(opts) + _, err := log.SetupZapLogger(opts) + require.NoError(t, err) + p := &Plugin{ l: log.Logger().Named("test"), } @@ -60,7 +63,7 @@ func TestStart(t *testing.T) { } // Start the Plugin. - err := p.Start(ctx) + err = p.Start(ctx) // Check if the error is nil. if stat, ok := status.FromError(err); ok { if stat.Code() != codes.Canceled {