From 6eff15a430caff57981f6c67a5c4cfd413b5a415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20=C5=9Awi=C4=85tek?= Date: Mon, 11 Nov 2024 16:48:26 +0100 Subject: [PATCH] Fix some lint errors (cherry picked from commit bd23b8d039bffc1537afe219ef9c94af4520e150) --- cmd/operator-opamp-bridge/metrics/reporter.go | 2 +- cmd/operator-opamp-bridge/operator/client.go | 2 +- internal/components/component.go | 2 +- internal/components/exporters/helpers_test.go | 6 +++--- internal/components/extensions/helpers_test.go | 6 +++--- .../components/receivers/single_endpoint_receiver_test.go | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/operator-opamp-bridge/metrics/reporter.go b/cmd/operator-opamp-bridge/metrics/reporter.go index 5afc573056..131704a246 100644 --- a/cmd/operator-opamp-bridge/metrics/reporter.go +++ b/cmd/operator-opamp-bridge/metrics/reporter.go @@ -107,7 +107,7 @@ func NewMetricReporter(logger logr.Logger, dest *protobufs.TelemetryConnectionSe reporter.meter = provider.Meter("opamp") - reporter.process, err = process.NewProcess(int32(os.Getpid())) + reporter.process, err = process.NewProcess(int32(os.Getpid())) //nolint: gosec // this is guaranteed to not overflow if err != nil { return nil, fmt.Errorf("cannot query own process: %w", err) } diff --git a/cmd/operator-opamp-bridge/operator/client.go b/cmd/operator-opamp-bridge/operator/client.go index 1033e40cff..bba972b952 100644 --- a/cmd/operator-opamp-bridge/operator/client.go +++ b/cmd/operator-opamp-bridge/operator/client.go @@ -117,7 +117,7 @@ func (c Client) Apply(name string, namespace string, configmap *protobufs.AgentC } func (c Client) validateComponents(collectorConfig *v1beta1.Config) error { - if c.componentsAllowed == nil || len(c.componentsAllowed) == 0 { + if len(c.componentsAllowed) == 0 { return nil } diff --git a/internal/components/component.go b/internal/components/component.go index 5c8975b9c2..b2341177e8 100644 --- a/internal/components/component.go +++ b/internal/components/component.go @@ -89,7 +89,7 @@ func PortFromEndpoint(endpoint string) (int32, error) { return UnsetPort, PortNotFoundErr } - return int32(port), err + return int32(port), err //nolint: gosec // disable G115, this is guaranteed to not overflow due to the bitSize in the ParseInt call } type ParserRetriever func(string) Parser diff --git a/internal/components/exporters/helpers_test.go b/internal/components/exporters/helpers_test.go index 77fb67aced..0e74b2bba3 100644 --- a/internal/components/exporters/helpers_test.go +++ b/internal/components/exporters/helpers_test.go @@ -54,7 +54,7 @@ func TestExporterComponentParsers(t *testing.T) { for _, tt := range []struct { exporterName string parserName string - defaultPort int + defaultPort int32 }{ {"prometheus", "__prometheus", 8888}, } { @@ -88,7 +88,7 @@ func TestExporterComponentParsers(t *testing.T) { assert.NoError(t, err) assert.Len(t, ports, 1) assert.EqualValues(t, tt.defaultPort, ports[0].Port) - assert.Equal(t, naming.PortName(tt.exporterName, int32(tt.defaultPort)), ports[0].Name) + assert.Equal(t, naming.PortName(tt.exporterName, tt.defaultPort), ports[0].Name) }) t.Run("allows port to be overridden", func(t *testing.T) { @@ -104,7 +104,7 @@ func TestExporterComponentParsers(t *testing.T) { assert.NoError(t, err) assert.Len(t, ports, 1) assert.EqualValues(t, 65535, ports[0].Port) - assert.Equal(t, naming.PortName(tt.exporterName, int32(tt.defaultPort)), ports[0].Name) + assert.Equal(t, naming.PortName(tt.exporterName, tt.defaultPort), ports[0].Name) }) }) } diff --git a/internal/components/extensions/helpers_test.go b/internal/components/extensions/helpers_test.go index 826072aef9..b747e3a9ec 100644 --- a/internal/components/extensions/helpers_test.go +++ b/internal/components/extensions/helpers_test.go @@ -54,7 +54,7 @@ func TestExtensionsComponentParsers(t *testing.T) { for _, tt := range []struct { exporterName string parserName string - defaultPort int + defaultPort int32 }{ {"health_check", "__health_check", 13133}, } { @@ -88,7 +88,7 @@ func TestExtensionsComponentParsers(t *testing.T) { assert.NoError(t, err) assert.Len(t, ports, 1) assert.EqualValues(t, tt.defaultPort, ports[0].Port) - assert.Equal(t, naming.PortName(tt.exporterName, int32(tt.defaultPort)), ports[0].Name) + assert.Equal(t, naming.PortName(tt.exporterName, tt.defaultPort), ports[0].Name) }) t.Run("allows port to be overridden", func(t *testing.T) { @@ -104,7 +104,7 @@ func TestExtensionsComponentParsers(t *testing.T) { assert.NoError(t, err) assert.Len(t, ports, 1) assert.EqualValues(t, 65535, ports[0].Port) - assert.Equal(t, naming.PortName(tt.exporterName, int32(tt.defaultPort)), ports[0].Name) + assert.Equal(t, naming.PortName(tt.exporterName, tt.defaultPort), ports[0].Name) }) }) } diff --git a/internal/components/receivers/single_endpoint_receiver_test.go b/internal/components/receivers/single_endpoint_receiver_test.go index abb866a8d8..4811323c97 100644 --- a/internal/components/receivers/single_endpoint_receiver_test.go +++ b/internal/components/receivers/single_endpoint_receiver_test.go @@ -64,7 +64,7 @@ func TestDownstreamParsers(t *testing.T) { desc string receiverName string parserName string - defaultPort int + defaultPort int32 listenAddrParser bool }{ {"zipkin", "zipkin", "__zipkin", 9411, false}, @@ -118,7 +118,7 @@ func TestDownstreamParsers(t *testing.T) { assert.NoError(t, err) assert.Len(t, ports, 1) assert.EqualValues(t, tt.defaultPort, ports[0].Port) - assert.Equal(t, naming.PortName(tt.receiverName, int32(tt.defaultPort)), ports[0].Name) + assert.Equal(t, naming.PortName(tt.receiverName, tt.defaultPort), ports[0].Name) }) t.Run("allows port to be overridden", func(t *testing.T) { @@ -142,7 +142,7 @@ func TestDownstreamParsers(t *testing.T) { assert.NoError(t, err) assert.Len(t, ports, 1) assert.EqualValues(t, 65535, ports[0].Port) - assert.Equal(t, naming.PortName(tt.receiverName, int32(tt.defaultPort)), ports[0].Name) + assert.Equal(t, naming.PortName(tt.receiverName, tt.defaultPort), ports[0].Name) }) t.Run("returns a default config", func(t *testing.T) {