From 165e5d246675a985686c4e1e8beb643f5abc4d2d Mon Sep 17 00:00:00 2001 From: FlamingSaint Date: Mon, 3 Jun 2024 07:56:29 +0530 Subject: [PATCH 1/3] Enable Lint Rule: bare-return Signed-off-by: FlamingSaint --- .golangci.yml | 3 --- pkg/fswatcher/fswatcher_test.go | 2 +- pkg/gzipfs/gzip.go | 2 +- pkg/httpmetrics/metrics.go | 2 +- pkg/kafka/auth/plaintext.go | 5 ++++- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4fc8712d020..d0aaeaa4e3a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -220,9 +220,6 @@ linters-settings: - name: early-return disabled: true # enable after cleanup - - name: bare-return - disabled: true - # enable after cleanup - name: empty-lines disabled: true # investigate, could be real bugs. But didn't recent Go version changed loop variables semantics? diff --git a/pkg/fswatcher/fswatcher_test.go b/pkg/fswatcher/fswatcher_test.go index 68a431e9e02..870812b47bf 100644 --- a/pkg/fswatcher/fswatcher_test.go +++ b/pkg/fswatcher/fswatcher_test.go @@ -47,7 +47,7 @@ func createTestFiles(t *testing.T) (file1 string, file2 string, file3 string) { err = os.WriteFile(file3, []byte("test data"), 0o600) require.NoError(t, err) - return + return file1, file2, file3 } func TestFSWatcherAddFiles(t *testing.T) { diff --git a/pkg/gzipfs/gzip.go b/pkg/gzipfs/gzip.go index cc58883f94a..8aca8c51c5d 100644 --- a/pkg/gzipfs/gzip.go +++ b/pkg/gzipfs/gzip.go @@ -60,7 +60,7 @@ func (f *file) Read(buf []byte) (n int, err error) { return n, io.EOF } f.offset += n - return + return n, nil } func (f file) Close() error { diff --git a/pkg/httpmetrics/metrics.go b/pkg/httpmetrics/metrics.go index 097c4bd1b68..0db8cc5e47d 100644 --- a/pkg/httpmetrics/metrics.go +++ b/pkg/httpmetrics/metrics.go @@ -149,5 +149,5 @@ func (r *requestDurations) buildTimer(metricsFactory metrics.Factory, key record "method": key.method, }, }) - return + return out } diff --git a/pkg/kafka/auth/plaintext.go b/pkg/kafka/auth/plaintext.go index 092047dbbfd..d31817ca674 100644 --- a/pkg/kafka/auth/plaintext.go +++ b/pkg/kafka/auth/plaintext.go @@ -44,7 +44,10 @@ func (x *scramClient) Begin(userName, password, authzID string) (err error) { // called repeatedly until it errors or `Done` returns true. func (x *scramClient) Step(challenge string) (response string, err error) { response, err = x.ClientConversation.Step(challenge) - return + if err != nil { + return "", err + } + return response, nil } // Done should return true when the SCRAM conversation From 424d5e49f21d4422e396c535fc4aa7ef205ced5e Mon Sep 17 00:00:00 2001 From: FlamingSaint Date: Mon, 3 Jun 2024 08:58:31 +0530 Subject: [PATCH 2/3] Add suggested changes Signed-off-by: FlamingSaint --- pkg/gzipfs/gzip.go | 4 ++-- pkg/kafka/auth/plaintext.go | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/gzipfs/gzip.go b/pkg/gzipfs/gzip.go index 8aca8c51c5d..d2e342c4aff 100644 --- a/pkg/gzipfs/gzip.go +++ b/pkg/gzipfs/gzip.go @@ -50,12 +50,12 @@ func (f file) Stat() (fs.FileInfo, error) { }, nil } -func (f *file) Read(buf []byte) (n int, err error) { +func (f *file) Read(buf []byte) (int, error) { if len(buf) > len(f.content)-f.offset { buf = buf[0:len(f.content[f.offset:])] } - n = copy(buf, f.content[f.offset:]) + n := copy(buf, f.content[f.offset:]) if n == len(f.content)-f.offset { return n, io.EOF } diff --git a/pkg/kafka/auth/plaintext.go b/pkg/kafka/auth/plaintext.go index d31817ca674..4f4e0147b74 100644 --- a/pkg/kafka/auth/plaintext.go +++ b/pkg/kafka/auth/plaintext.go @@ -42,12 +42,8 @@ func (x *scramClient) Begin(userName, password, authzID string) (err error) { // Step steps client through the SCRAM exchange. It is // called repeatedly until it errors or `Done` returns true. -func (x *scramClient) Step(challenge string) (response string, err error) { - response, err = x.ClientConversation.Step(challenge) - if err != nil { - return "", err - } - return response, nil +func (x *scramClient) Step(challenge string) (string, error) { + return x.ClientConversation.Step(challenge) } // Done should return true when the SCRAM conversation From d1455f2fd238f3d6402a440539b9fa78e7824d7b Mon Sep 17 00:00:00 2001 From: FlamingSaint Date: Mon, 3 Jun 2024 10:02:00 +0530 Subject: [PATCH 3/3] Enable Lint Rule: empty-lines Signed-off-by: FlamingSaint --- .golangci.yml | 3 --- cmd/collector/app/collector.go | 1 - cmd/query/app/server.go | 1 - cmd/query/app/server_test.go | 2 -- pkg/kafka/auth/plaintext.go | 1 - plugin/sampling/strategystore/static/strategy_store.go | 1 - plugin/storage/badger/spanstore/reader.go | 1 - plugin/storage/cassandra/spanstore/reader_test.go | 1 - plugin/storage/memory/memory.go | 1 - 9 files changed, 12 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d0aaeaa4e3a..fd0eb328043 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -219,9 +219,6 @@ linters-settings: # enable after cleanup - name: early-return disabled: true - # enable after cleanup - - name: empty-lines - disabled: true # investigate, could be real bugs. But didn't recent Go version changed loop variables semantics? - name: range-val-address disabled: true diff --git a/cmd/collector/app/collector.go b/cmd/collector/app/collector.go index ad6eeca364a..31c9e4532d8 100644 --- a/cmd/collector/app/collector.go +++ b/cmd/collector/app/collector.go @@ -154,7 +154,6 @@ func (c *Collector) Start(options *flags.CollectorOptions) error { return fmt.Errorf("could not start Zipkin receiver: %w", err) } c.zipkinReceiver = zipkinReceiver - } if options.OTLP.Enabled { diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index 719f3957778..8e1af7662c3 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -205,7 +205,6 @@ func createHTTPServer( return nil, err } server.TLSConfig = tlsCfg - } server.staticHandlerCloser = RegisterStaticHandler(r, logger, queryOpts, querySvc.GetCapabilities()) diff --git a/cmd/query/app/server_test.go b/cmd/query/app/server_test.go index cd6ab915b1e..be12ed6449d 100644 --- a/cmd/query/app/server_test.go +++ b/cmd/query/app/server_test.go @@ -382,9 +382,7 @@ func TestServerHTTPTLS(t *testing.T) { if conn != nil { clientClose = conn.Close } - } else { - conn, err1 := net.DialTimeout("tcp", "localhost:"+fmt.Sprintf("%d", ports.QueryHTTP), 2*time.Second) clientError = err1 clientClose = nil diff --git a/pkg/kafka/auth/plaintext.go b/pkg/kafka/auth/plaintext.go index 4f4e0147b74..81d940bb130 100644 --- a/pkg/kafka/auth/plaintext.go +++ b/pkg/kafka/auth/plaintext.go @@ -83,7 +83,6 @@ func setPlainTextConfiguration(config *PlainTextConfig, saramaConfig *sarama.Con default: return fmt.Errorf("config plaintext.mechanism error: %s, only support 'SCRAM-SHA-256' or 'SCRAM-SHA-512' or 'PLAIN'", config.Mechanism) - } return nil } diff --git a/plugin/sampling/strategystore/static/strategy_store.go b/plugin/sampling/strategystore/static/strategy_store.go index fdf9959a9d8..05debf2d720 100644 --- a/plugin/sampling/strategystore/static/strategy_store.go +++ b/plugin/sampling/strategystore/static/strategy_store.go @@ -278,7 +278,6 @@ func (h *strategyStore) parseStrategies(strategies *strategies) { opS := newStore.serviceStrategies[s.Service].OperationSampling if opS == nil { - // Service does not have its own per-operation rules, so copy (by value) from the default strategy. newOpS := *newStore.defaultStrategy.OperationSampling diff --git a/plugin/storage/badger/spanstore/reader.go b/plugin/storage/badger/spanstore/reader.go index f33dce1136d..484deeaa575 100644 --- a/plugin/storage/badger/spanstore/reader.go +++ b/plugin/storage/badger/spanstore/reader.go @@ -280,7 +280,6 @@ func serviceQueries(query *spanstore.TraceQueryParameters, indexSeeks [][]byte) } else if !tagQueryUsed { // Tag query already reduces the search set with a serviceName indexSearchKey = append(indexSearchKey, serviceNameIndexKey) indexSearchKey = append(indexSearchKey, []byte(query.ServiceName)...) - } if len(indexSearchKey) > 0 { diff --git a/plugin/storage/cassandra/spanstore/reader_test.go b/plugin/storage/cassandra/spanstore/reader_test.go index 65ebe9e198d..946fdb45de4 100644 --- a/plugin/storage/cassandra/spanstore/reader_test.go +++ b/plugin/storage/cassandra/spanstore/reader_test.go @@ -402,7 +402,6 @@ func TestSpanReaderFindTraces(t *testing.T) { if testCase.queryDuration { queryParams.DurationMin = time.Minute queryParams.DurationMax = time.Minute * 3 - } res, err := r.reader.FindTraces(context.Background(), queryParams) if testCase.expectedError == "" { diff --git a/plugin/storage/memory/memory.go b/plugin/storage/memory/memory.go index d8da0b6ca2f..cae11e3ae8a 100644 --- a/plugin/storage/memory/memory.go +++ b/plugin/storage/memory/memory.go @@ -187,7 +187,6 @@ func (st *Store) WriteSpan(ctx context.Context, span *model.Span) error { // update the ring with the trace id m.ids[m.index] = &span.TraceID } - } m.traces[span.TraceID].Spans = append(m.traces[span.TraceID].Spans, span)