Skip to content

Commit

Permalink
address lints
Browse files Browse the repository at this point in the history
  • Loading branch information
matmerr committed Jan 23, 2025
1 parent 735a74e commit 8770822
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
22 changes: 10 additions & 12 deletions pkg/plugin/pktmon/pktmon_grpc_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,7 +29,7 @@ type GRPCManager interface {
Stop() error
}

type PktmonGRPCManager struct {
type WindowsGRPCManager struct {
grpcClient *GRPCClient
stream observerv1.Observer_GetFlowsClient
l *log.ZapLogger
Expand All @@ -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")
Expand All @@ -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")
}
Expand All @@ -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
}

func newGRPCClient() (*GRPCClient, error) {
Expand All @@ -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}
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/pktmon/pktmon_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions pkg/plugin/pktmon/pktmon_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
}

Expand All @@ -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"),
}
Expand Down

0 comments on commit 8770822

Please sign in to comment.