From 98f666d0c8310cb8b1234c7f92276ef3a98629df Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Sat, 23 Dec 2023 18:27:05 -0500 Subject: [PATCH] Upgrade golangci-lint to v1.55.2 and fix errors (#5029) ## Description of the changes - Upgrade linter version - Update configuration of depguard - Disable uber-go/atomic and crossdock as deps - Replace invalid crossdock imports with stretchr/testify - Replace uber-go/atomic usage with sync/atomic - in most cases pointers to atomics are not necessary, and likewise initialization to zero values - Fix other test and linter errors revealed by new linter --------- Signed-off-by: Yuri Shkuro --- .golangci.yml | 28 ++++++++++++++----- Makefile | 2 +- cmd/agent/app/reporter/client_metrics.go | 5 ++-- .../app/servers/tbuffered_server_test.go | 8 +++--- cmd/collector/app/root_span_handler_test.go | 6 ++-- cmd/collector/app/span_processor.go | 10 +++---- cmd/collector/app/span_processor_test.go | 28 +++++++++++++------ cmd/es-rollover/app/actions_test.go | 2 +- cmd/es-rollover/app/index_options_test.go | 2 +- cmd/es-rollover/app/init/action_test.go | 2 +- .../app/lookback/time_reference_test.go | 2 +- cmd/es-rollover/app/rollover/action_test.go | 2 +- cmd/internal/flags/service_test.go | 4 +-- pkg/es/filter/alias_test.go | 2 +- pkg/es/filter/date_test.go | 2 +- pkg/queue/bounded_queue.go | 19 ++++++------- pkg/queue/bounded_queue_test.go | 6 ++-- .../leaderelection/leader_election.go | 5 ++-- .../leaderelection/leader_election_test.go | 4 +-- .../static/strategy_store_test.go | 24 ++++++++++------ plugin/storage/badger/lock_test.go | 2 +- .../cassandra/spanstore/writer_test.go | 17 ++++++----- .../storage/grpc/shared/streaming_writer.go | 6 ++-- plugin/storage/memory/lock_test.go | 2 +- plugin/storage/memory/sampling_test.go | 2 +- 25 files changed, 108 insertions(+), 84 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index aad04a8ce0c..b0bfda51686 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -41,7 +41,7 @@ linters: # Check declaration order of types, consts, vars and funcs. - decorder - # Checks if package imports are in a list of acceptable packages. + # Checks if package imports are in a list of acceptable packages (see cfg below). - depguard # Check for two durations multiplied together. @@ -90,12 +90,26 @@ linters: linters-settings: depguard: - list-type: blacklist - include-go-root: true - packages: - - io/ioutil - packages-with-error-message: - - io/ioutil: "Use os or io instead of io/ioutil" + rules: + disallowed-deps: + deny: + - pkg: go.uber.org/atomic + desc: "Use 'sync/atomic' instead of go.uber.org/atomic" + - pkg: io/ioutil + desc: "Use os or io instead of io/ioutil" + - pkg: github.com/hashicorp/go-multierror + desc: "Use errors.Join instead of github.com/hashicorp/go-multierror" + - pkg: go.uber.org/multierr + desc: "Use errors.Join instead of github.com/hashicorp/go-multierror" + # crossdock-go provides assert/require similar to stretchr/testify + # but we never want to use them outside of the crossdock tests. + disallow-crossdock: + deny: + - pkg: github.com/crossdock/crossdock-go + desc: "Do not refer to crossdock from other packages" + files: + - "!**/crossdock/**" + goimports: local-prefixes: github.com/jaegertracing/jaeger gosec: diff --git a/Makefile b/Makefile index 8a9fa8c2881..08fd2e6acfb 100644 --- a/Makefile +++ b/Makefile @@ -492,7 +492,7 @@ draft-release: .PHONY: install-test-tools install-test-tools: - $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.1 + $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 $(GO) install mvdan.cc/gofumpt@latest .PHONY: install-build-tools diff --git a/cmd/agent/app/reporter/client_metrics.go b/cmd/agent/app/reporter/client_metrics.go index 63c90028dd2..c93b60f0b38 100644 --- a/cmd/agent/app/reporter/client_metrics.go +++ b/cmd/agent/app/reporter/client_metrics.go @@ -17,9 +17,9 @@ package reporter import ( "context" "sync" + "sync/atomic" "time" - "go.uber.org/atomic" "go.uber.org/zap" "github.com/jaegertracing/jaeger/pkg/metrics" @@ -75,7 +75,7 @@ type ClientMetricsReporter struct { params ClientMetricsReporterParams clientMetrics *clientMetrics shutdown chan struct{} - closed *atomic.Bool + closed atomic.Bool // map from client-uuid to *lastReceivedClientStats lastReceivedClientStats sync.Map @@ -104,7 +104,6 @@ func WrapWithClientMetrics(params ClientMetricsReporterParams) *ClientMetricsRep params: params, clientMetrics: cm, shutdown: make(chan struct{}), - closed: atomic.NewBool(false), } go r.expireClientMetricsLoop() return r diff --git a/cmd/agent/app/servers/tbuffered_server_test.go b/cmd/agent/app/servers/tbuffered_server_test.go index bf3df2d16ef..6ac1e79482a 100644 --- a/cmd/agent/app/servers/tbuffered_server_test.go +++ b/cmd/agent/app/servers/tbuffered_server_test.go @@ -19,13 +19,13 @@ import ( "context" "io" "sync" + "sync/atomic" "testing" "time" "github.com/apache/thrift/lib/go/thrift" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.uber.org/atomic" "github.com/jaegertracing/jaeger/cmd/agent/app/customtransport" "github.com/jaegertracing/jaeger/cmd/agent/app/servers/thriftudp" @@ -35,7 +35,7 @@ import ( "github.com/jaegertracing/jaeger/thrift-gen/zipkincore" ) -func TestTBufferedServer_SendReceive(t *testing.T) { +func TestTBufferedServerSendReceive(t *testing.T) { metricsFactory := metricstest.NewFactory(0) transport, err := thriftudp.NewTUDPServerTransport("127.0.0.1:0") @@ -101,7 +101,7 @@ type fakeTransport struct { // Second packet is simulated as error. // Third packet is returned as normal, but will be dropped as overflow by the server whose queue size = 1. func (t *fakeTransport) Read(p []byte) (n int, err error) { - packet := t.packet.Inc() + packet := t.packet.Add(1) if packet == 2 { // return some error packet, followed by valid one return 0, io.ErrNoProgress @@ -121,7 +121,7 @@ func (t *fakeTransport) Close() error { return nil } -func TestTBufferedServer_Metrics(t *testing.T) { +func TestTBufferedServerMetrics(t *testing.T) { metricsFactory := metricstest.NewFactory(0) transport := new(fakeTransport) diff --git a/cmd/collector/app/root_span_handler_test.go b/cmd/collector/app/root_span_handler_test.go index b8ce79717f7..10a2eeed51d 100644 --- a/cmd/collector/app/root_span_handler_test.go +++ b/cmd/collector/app/root_span_handler_test.go @@ -15,10 +15,10 @@ package app import ( + "sync/atomic" "testing" "github.com/stretchr/testify/assert" - "go.uber.org/atomic" "go.uber.org/zap" "github.com/jaegertracing/jaeger/model" @@ -30,11 +30,11 @@ type mockAggregator struct { } func (t *mockAggregator) RecordThroughput(service, operation string, samplerType model.SamplerType, probability float64) { - t.callCount.Inc() + t.callCount.Add(1) } func (t *mockAggregator) Start() {} func (t *mockAggregator) Close() error { - t.closeCount.Inc() + t.closeCount.Add(1) return nil } diff --git a/cmd/collector/app/span_processor.go b/cmd/collector/app/span_processor.go index 04e8d43ab36..fff5dae06e4 100644 --- a/cmd/collector/app/span_processor.go +++ b/cmd/collector/app/span_processor.go @@ -18,9 +18,9 @@ package app import ( "context" "sync" + "sync/atomic" "time" - "go.uber.org/atomic" "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/collector/app/processor" @@ -54,8 +54,8 @@ type spanProcessor struct { collectorTags map[string]string dynQueueSizeWarmup uint dynQueueSizeMemory uint - bytesProcessed *atomic.Uint64 - spansProcessed *atomic.Uint64 + bytesProcessed atomic.Uint64 + spansProcessed atomic.Uint64 stopCh chan struct{} } @@ -120,8 +120,6 @@ func newSpanProcessor(spanWriter spanstore.Writer, additional []ProcessSpan, opt stopCh: make(chan struct{}), dynQueueSizeMemory: options.dynQueueSizeMemory, dynQueueSizeWarmup: options.dynQueueSizeWarmup, - bytesProcessed: atomic.NewUint64(0), - spansProcessed: atomic.NewUint64(0), } processSpanFuncs := []ProcessSpan{options.preSave, sp.saveSpan} @@ -173,7 +171,7 @@ func (sp *spanProcessor) saveSpan(span *model.Span, tenant string) { func (sp *spanProcessor) countSpan(span *model.Span, tenant string) { sp.bytesProcessed.Add(uint64(span.Size())) - sp.spansProcessed.Inc() + sp.spansProcessed.Add(1) } func (sp *spanProcessor) ProcessSpans(mSpans []*model.Span, options processor.SpansOptions) ([]bool, error) { diff --git a/cmd/collector/app/span_processor_test.go b/cmd/collector/app/span_processor_test.go index 3f171bee8b0..67e9b79e6ce 100644 --- a/cmd/collector/app/span_processor_test.go +++ b/cmd/collector/app/span_processor_test.go @@ -21,12 +21,12 @@ import ( "io" "reflect" "sync" + "sync/atomic" "testing" "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.uber.org/atomic" "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/collector/app/handler" @@ -296,10 +296,10 @@ type blockingWriter struct { } func (w *blockingWriter) WriteSpan(ctx context.Context, span *model.Span) error { - w.inWriteSpan.Inc() + w.inWriteSpan.Add(1) w.Lock() defer w.Unlock() - w.inWriteSpan.Dec() + w.inWriteSpan.Add(-1) return nil } @@ -443,7 +443,10 @@ func TestSpanProcessorCountSpan(t *testing.T) { m := mb.Namespace(metrics.NSOptions{}) w := &fakeSpanWriter{} - opts := []Option{Options.HostMetrics(m), Options.SpanSizeMetricsEnabled(tt.enableSpanMetrics)} + opts := []Option{ + Options.HostMetrics(m), + Options.SpanSizeMetricsEnabled(tt.enableSpanMetrics), + } if tt.enableDynQueueSizeMem { opts = append(opts, Options.DynQueueSizeMemory(1000)) } else { @@ -456,7 +459,14 @@ func TestSpanProcessorCountSpan(t *testing.T) { p.background(10*time.Millisecond, p.updateGauges) p.processSpan(&model.Span{}, "") - assert.NotEqual(t, uint64(0), p.bytesProcessed) + if tt.enableSpanMetrics { + assert.Eventually(t, + func() bool { return p.spansProcessed.Load() > 0 }, + time.Second, + time.Millisecond, + ) + assert.Greater(t, p.spansProcessed.Load(), uint64(0)) + } for i := 0; i < 10000; i++ { _, g := mb.Snapshot() @@ -558,8 +568,8 @@ func TestUpdateDynQueueSize(t *testing.T) { p := newSpanProcessor(w, nil, Options.QueueSize(tt.initialCapacity), Options.DynQueueSizeWarmup(tt.warmup), Options.DynQueueSizeMemory(tt.sizeInBytes)) assert.EqualValues(t, tt.initialCapacity, p.queue.Capacity()) - p.spansProcessed = atomic.NewUint64(tt.spansProcessed) - p.bytesProcessed = atomic.NewUint64(tt.bytesProcessed) + p.spansProcessed.Store(tt.spansProcessed) + p.bytesProcessed.Store(tt.bytesProcessed) p.updateQueueSize() assert.EqualValues(t, tt.expectedCapacity, p.queue.Capacity()) @@ -579,8 +589,8 @@ func TestStartDynQueueSizeUpdater(t *testing.T) { p := newSpanProcessor(w, nil, Options.QueueSize(100), Options.DynQueueSizeWarmup(1000), Options.DynQueueSizeMemory(oneGiB)) assert.EqualValues(t, 100, p.queue.Capacity()) - p.spansProcessed = atomic.NewUint64(1000) - p.bytesProcessed = atomic.NewUint64(10 * 1024 * p.spansProcessed.Load()) // 10KiB per span + p.spansProcessed.Store(1000) + p.bytesProcessed.Store(10 * 1024 * p.spansProcessed.Load()) // 10KiB per span // 1024 ^ 3 / (10 * 1024) = 104857,6 // ideal queue size = 104857 diff --git a/cmd/es-rollover/app/actions_test.go b/cmd/es-rollover/app/actions_test.go index 389a3b804fb..39cfa647245 100644 --- a/cmd/es-rollover/app/actions_test.go +++ b/cmd/es-rollover/app/actions_test.go @@ -20,9 +20,9 @@ import ( "net/http" "testing" - "github.com/crossdock/crossdock-go/assert" "github.com/spf13/cobra" "github.com/spf13/viper" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap" diff --git a/cmd/es-rollover/app/index_options_test.go b/cmd/es-rollover/app/index_options_test.go index b2fd24059b0..0579062b6ec 100644 --- a/cmd/es-rollover/app/index_options_test.go +++ b/cmd/es-rollover/app/index_options_test.go @@ -17,7 +17,7 @@ package app import ( "testing" - "github.com/crossdock/crossdock-go/assert" + "github.com/stretchr/testify/assert" ) func TestRolloverIndices(t *testing.T) { diff --git a/cmd/es-rollover/app/init/action_test.go b/cmd/es-rollover/app/init/action_test.go index 5b313510210..b23d69a76ee 100644 --- a/cmd/es-rollover/app/init/action_test.go +++ b/cmd/es-rollover/app/init/action_test.go @@ -20,7 +20,7 @@ import ( "strings" "testing" - "github.com/crossdock/crossdock-go/assert" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/jaegertracing/jaeger/cmd/es-rollover/app" diff --git a/cmd/es-rollover/app/lookback/time_reference_test.go b/cmd/es-rollover/app/lookback/time_reference_test.go index 064ef1fa85b..21a5448d856 100644 --- a/cmd/es-rollover/app/lookback/time_reference_test.go +++ b/cmd/es-rollover/app/lookback/time_reference_test.go @@ -18,7 +18,7 @@ import ( "testing" "time" - "github.com/crossdock/crossdock-go/assert" + "github.com/stretchr/testify/assert" ) func TestGetTimeReference(t *testing.T) { diff --git a/cmd/es-rollover/app/rollover/action_test.go b/cmd/es-rollover/app/rollover/action_test.go index 07bc25df949..dbc304c0862 100644 --- a/cmd/es-rollover/app/rollover/action_test.go +++ b/cmd/es-rollover/app/rollover/action_test.go @@ -18,7 +18,7 @@ import ( "errors" "testing" - "github.com/crossdock/crossdock-go/assert" + "github.com/stretchr/testify/assert" "github.com/jaegertracing/jaeger/cmd/es-rollover/app" "github.com/jaegertracing/jaeger/pkg/es/client" diff --git a/cmd/internal/flags/service_test.go b/cmd/internal/flags/service_test.go index 7c7601f470b..1b18cc5df04 100644 --- a/cmd/internal/flags/service_test.go +++ b/cmd/internal/flags/service_test.go @@ -17,12 +17,12 @@ import ( "flag" "os" "reflect" + "sync/atomic" "testing" "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.uber.org/atomic" "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/pkg/healthcheck" @@ -86,7 +86,7 @@ func TestStartErrors(t *testing.T) { } assert.NoError(t, err) - stopped := atomic.NewBool(false) + var stopped atomic.Bool shutdown := func() { stopped.Store(true) } diff --git a/pkg/es/filter/alias_test.go b/pkg/es/filter/alias_test.go index 614c3c0fac0..e230f3e1232 100644 --- a/pkg/es/filter/alias_test.go +++ b/pkg/es/filter/alias_test.go @@ -17,7 +17,7 @@ package filter import ( "testing" - "github.com/crossdock/crossdock-go/assert" + "github.com/stretchr/testify/assert" "github.com/jaegertracing/jaeger/pkg/es/client" ) diff --git a/pkg/es/filter/date_test.go b/pkg/es/filter/date_test.go index 50080284de7..89f7054a69f 100644 --- a/pkg/es/filter/date_test.go +++ b/pkg/es/filter/date_test.go @@ -18,7 +18,7 @@ import ( "testing" "time" - "github.com/crossdock/crossdock-go/assert" + "github.com/stretchr/testify/assert" "github.com/jaegertracing/jaeger/pkg/es/client" ) diff --git a/pkg/queue/bounded_queue.go b/pkg/queue/bounded_queue.go index 7d95ef14ce5..c28031104e6 100644 --- a/pkg/queue/bounded_queue.go +++ b/pkg/queue/bounded_queue.go @@ -21,8 +21,6 @@ import ( "time" "unsafe" - uatomic "go.uber.org/atomic" - "github.com/jaegertracing/jaeger/pkg/metrics" ) @@ -39,9 +37,9 @@ type Consumer interface { type BoundedQueue struct { workers int stopWG sync.WaitGroup - size *uatomic.Uint32 - capacity *uatomic.Uint32 - stopped *uatomic.Uint32 + size atomic.Int32 + capacity atomic.Uint32 + stopped atomic.Uint32 items *chan interface{} onDroppedItem func(item interface{}) factory func() Consumer @@ -52,14 +50,13 @@ type BoundedQueue struct { // callback for dropped items (e.g. useful to emit metrics). func NewBoundedQueue(capacity int, onDroppedItem func(item interface{})) *BoundedQueue { queue := make(chan interface{}, capacity) - return &BoundedQueue{ + bq := &BoundedQueue{ onDroppedItem: onDroppedItem, items: &queue, stopCh: make(chan struct{}), - capacity: uatomic.NewUint32(uint32(capacity)), - stopped: uatomic.NewUint32(0), - size: uatomic.NewUint32(0), } + bq.capacity.Store(uint32(capacity)) + return bq } // StartConsumersWithFactory creates a given number of consumers consuming items @@ -80,7 +77,7 @@ func (q *BoundedQueue) StartConsumersWithFactory(num int, factory func() Consume select { case item, ok := <-queue: if ok { - q.size.Sub(1) + q.size.Add(-1) consumer.Consume(item) } else { // channel closed, finish worker @@ -135,7 +132,7 @@ func (q *BoundedQueue) Produce(item interface{}) bool { return true default: // should not happen, as overflows should have been captured earlier - q.size.Sub(1) + q.size.Add(-1) if q.onDroppedItem != nil { q.onDroppedItem(item) } diff --git a/pkg/queue/bounded_queue_test.go b/pkg/queue/bounded_queue_test.go index 5d3a276f121..aae1fe3d6cb 100644 --- a/pkg/queue/bounded_queue_test.go +++ b/pkg/queue/bounded_queue_test.go @@ -25,7 +25,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - uatomic "go.uber.org/atomic" "go.uber.org/goleak" "github.com/jaegertracing/jaeger/internal/metricstest" @@ -280,7 +279,8 @@ func TestResizeOldQueueIsDrained(t *testing.T) { readyToConsume.Add(1) expected.Add(5) // we expect 5 items to be processed - consumed := uatomic.NewInt32(5) + var consumed atomic.Int32 + consumed.Store(5) first := true q.StartConsumers(1, func(item interface{}) { @@ -292,7 +292,7 @@ func TestResizeOldQueueIsDrained(t *testing.T) { readyToConsume.Wait() - if consumed.Sub(1) >= 0 { + if consumed.Add(-1) >= 0 { // we mark only the first 5 items as done // we *might* get one item more in the queue given the right conditions // but this small difference is OK -- making sure we are processing *exactly* N items diff --git a/plugin/sampling/leaderelection/leader_election.go b/plugin/sampling/leaderelection/leader_election.go index e800263b136..531326f526d 100644 --- a/plugin/sampling/leaderelection/leader_election.go +++ b/plugin/sampling/leaderelection/leader_election.go @@ -17,9 +17,9 @@ package leaderelection import ( "io" "sync" + "sync/atomic" "time" - "go.uber.org/atomic" "go.uber.org/zap" dl "github.com/jaegertracing/jaeger/pkg/distributedlock" @@ -41,7 +41,7 @@ type ElectionParticipant interface { type DistributedElectionParticipant struct { ElectionParticipantOptions lock dl.Lock - isLeader *atomic.Bool + isLeader atomic.Bool resourceName string closeChan chan struct{} wg sync.WaitGroup @@ -60,7 +60,6 @@ func NewElectionParticipant(lock dl.Lock, resourceName string, options ElectionP ElectionParticipantOptions: options, lock: lock, resourceName: resourceName, - isLeader: atomic.NewBool(false), closeChan: make(chan struct{}), } } diff --git a/plugin/sampling/leaderelection/leader_election_test.go b/plugin/sampling/leaderelection/leader_election_test.go index 00dbfb82b8a..aff38c89b1c 100644 --- a/plugin/sampling/leaderelection/leader_election_test.go +++ b/plugin/sampling/leaderelection/leader_election_test.go @@ -22,7 +22,6 @@ import ( "time" "github.com/stretchr/testify/assert" - "go.uber.org/atomic" "go.uber.org/goleak" lmocks "github.com/jaegertracing/jaeger/pkg/distributedlock/mocks" @@ -67,7 +66,6 @@ func TestAcquireLock(t *testing.T) { }, lock: mockLock, resourceName: "sampling_lock", - isLeader: atomic.NewBool(false), } p.setLeader(test.isLeader) @@ -78,7 +76,7 @@ func TestAcquireLock(t *testing.T) { } } -func TestRunAcquireLockLoop_followerOnly(t *testing.T) { +func TestRunAcquireLockLoopFollowerOnly(t *testing.T) { logger, logBuffer := testutils.NewLogger() mockLock := &lmocks.Lock{} mockLock.On("Acquire", "sampling_lock", time.Duration(5*time.Millisecond)).Return(false, errTestLock) diff --git a/plugin/sampling/strategystore/static/strategy_store_test.go b/plugin/sampling/strategystore/static/strategy_store_test.go index 621844fc2c5..b87cbd37f6b 100644 --- a/plugin/sampling/strategystore/static/strategy_store_test.go +++ b/plugin/sampling/strategystore/static/strategy_store_test.go @@ -21,12 +21,12 @@ import ( "net/http/httptest" "os" "strings" + "sync/atomic" "testing" "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.uber.org/atomic" "go.uber.org/zap" "go.uber.org/zap/zaptest/observer" @@ -64,8 +64,10 @@ func strategiesJSON(probability float32) string { // Returns strategies in JSON format. Used for testing // URL option for sampling strategies. -func mockStrategyServer() (*httptest.Server, *atomic.String) { - strategy := atomic.NewString(strategiesJSON(0.8)) +func mockStrategyServer() (*httptest.Server, *atomic.Pointer[string]) { + var strategy atomic.Pointer[string] + value := strategiesJSON(0.8) + strategy.Store(&value) f := func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { case "/bad-content": @@ -83,10 +85,10 @@ func mockStrategyServer() (*httptest.Server, *atomic.String) { default: w.WriteHeader(200) w.Header().Set("Content-Type", "application/json") - w.Write([]byte(strategy.Load())) + w.Write([]byte(*strategy.Load())) } } - return httptest.NewServer(http.HandlerFunc(f)), strategy + return httptest.NewServer(http.HandlerFunc(f)), &strategy } func TestStrategyStoreWithFile(t *testing.T) { @@ -393,11 +395,17 @@ func TestAutoUpdateStrategyWithURL(t *testing.T) { assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8), *s) // verify that reloading in no-op - value := store.reloadSamplingStrategy(store.samplingStrategyLoader(mockServer.URL), mockStrategy.Load()) - assert.Equal(t, mockStrategy.Load(), value) + value := store.reloadSamplingStrategy( + store.samplingStrategyLoader(mockServer.URL), + *mockStrategy.Load(), + ) + assert.Equal(t, *mockStrategy.Load(), value) // update original strategies with new probability of 0.9 - mockStrategy.Store(strategiesJSON(0.9)) + { + v09 := strategiesJSON(0.9) + mockStrategy.Store(&v09) + } // wait for reload timer for i := 0; i < 1000; i++ { // wait up to 1sec diff --git a/plugin/storage/badger/lock_test.go b/plugin/storage/badger/lock_test.go index f973104f9e6..b9b3e5bf584 100644 --- a/plugin/storage/badger/lock_test.go +++ b/plugin/storage/badger/lock_test.go @@ -18,7 +18,7 @@ import ( "testing" "time" - "github.com/crossdock/crossdock-go/assert" + "github.com/stretchr/testify/assert" ) func TestAcquire(t *testing.T) { diff --git a/plugin/storage/cassandra/spanstore/writer_test.go b/plugin/storage/cassandra/spanstore/writer_test.go index 6b808a924c9..7ffead9f651 100644 --- a/plugin/storage/cassandra/spanstore/writer_test.go +++ b/plugin/storage/cassandra/spanstore/writer_test.go @@ -20,12 +20,12 @@ import ( "errors" "fmt" "strings" + "sync/atomic" "testing" "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "go.uber.org/atomic" "go.uber.org/zap" "github.com/jaegertracing/jaeger/internal/metricstest" @@ -360,14 +360,17 @@ func TestStorageMode_IndexOnly_WithFilter(t *testing.T) { func TestStorageMode_IndexOnly_FirehoseSpan(t *testing.T) { withSpanWriter(0, func(w *spanWriterTest) { - serviceWritten := atomic.NewString("") - operationWritten := &atomic.Value{} + var serviceWritten atomic.Pointer[string] + var operationWritten atomic.Pointer[dbmodel.Operation] + empty := "" + serviceWritten.Store(&empty) + operationWritten.Store(&dbmodel.Operation{}) w.writer.serviceNamesWriter = func(serviceName string) error { - serviceWritten.Store(serviceName) + serviceWritten.Store(&serviceName) return nil } w.writer.operationNamesWriter = func(operation dbmodel.Operation) error { - operationWritten.Store(operation) + operationWritten.Store(&operation) return nil } span := &model.Span{ @@ -398,12 +401,12 @@ func TestStorageMode_IndexOnly_FirehoseSpan(t *testing.T) { w.session.AssertExpectations(t) w.session.AssertNotCalled(t, "Query", stringMatcher(tagIndex), matchEverything()) w.session.AssertNotCalled(t, "Query", stringMatcher(durationIndex), matchEverything()) - assert.Equal(t, "planet-express", serviceWritten.Load()) + assert.Equal(t, "planet-express", *serviceWritten.Load()) assert.Equal(t, dbmodel.Operation{ ServiceName: "planet-express", SpanKind: "unspecified", OperationName: "package-delivery", - }, operationWritten.Load()) + }, *operationWritten.Load()) }, StoreIndexesOnly()) } diff --git a/plugin/storage/grpc/shared/streaming_writer.go b/plugin/storage/grpc/shared/streaming_writer.go index b08db32a9f0..fad5d6c0db1 100644 --- a/plugin/storage/grpc/shared/streaming_writer.go +++ b/plugin/storage/grpc/shared/streaming_writer.go @@ -18,8 +18,7 @@ import ( "context" "errors" "fmt" - - "go.uber.org/atomic" + "sync/atomic" "github.com/jaegertracing/jaeger/model" "github.com/jaegertracing/jaeger/proto-gen/storage_v1" @@ -36,13 +35,12 @@ const ( type streamingSpanWriter struct { client storage_v1.StreamingSpanWriterPluginClient streamPool chan storage_v1.StreamingSpanWriterPlugin_WriteSpanStreamClient - closed *atomic.Bool + closed atomic.Bool } func newStreamingSpanWriter(client storage_v1.StreamingSpanWriterPluginClient) *streamingSpanWriter { s := &streamingSpanWriter{ client: client, - closed: atomic.NewBool(false), streamPool: make(chan storage_v1.StreamingSpanWriterPlugin_WriteSpanStreamClient, defaultMaxPoolSize), } return s diff --git a/plugin/storage/memory/lock_test.go b/plugin/storage/memory/lock_test.go index fa036a99f0d..1ea14648ca2 100644 --- a/plugin/storage/memory/lock_test.go +++ b/plugin/storage/memory/lock_test.go @@ -18,7 +18,7 @@ import ( "testing" "time" - "github.com/crossdock/crossdock-go/assert" + "github.com/stretchr/testify/assert" ) func TestAcquire(t *testing.T) { diff --git a/plugin/storage/memory/sampling_test.go b/plugin/storage/memory/sampling_test.go index 046c634f32b..5d4d401a2b7 100644 --- a/plugin/storage/memory/sampling_test.go +++ b/plugin/storage/memory/sampling_test.go @@ -19,7 +19,7 @@ import ( "testing" "time" - "github.com/crossdock/crossdock-go/assert" + "github.com/stretchr/testify/assert" "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model" )