From 893505ae764ca8b5de4ce7360264beebf2b136ca Mon Sep 17 00:00:00 2001 From: Jonathan Halterman Date: Wed, 13 Mar 2024 18:49:02 -0700 Subject: [PATCH] Migrate from go.uber.org/atomic to sync/atomic Signed-off-by: Jonathan Halterman --- Makefile | 2 +- go.mod | 1 - go.sum | 2 -- objstore.go | 8 ++++---- objstore_test.go | 6 +++--- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index ed5aaf4b..8e1698b4 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ github.com/prometheus/client_golang/prometheus.{DefaultGatherer,DefBuckets,NewUn github.com/prometheus/client_golang/prometheus.{NewCounter,NewCounterVec,NewCounterVec,NewGauge,NewGaugeVec,NewGaugeFunc,\ NewHistorgram,NewHistogramVec,NewSummary,NewSummaryVec}=github.com/prometheus/client_golang/prometheus/promauto.{NewCounter,\ NewCounterVec,NewCounterVec,NewGauge,NewGaugeVec,NewGaugeFunc,NewHistorgram,NewHistogramVec,NewSummary,NewSummaryVec},\ -sync/atomic=go.uber.org/atomic" ./... +go.uber.org/atomic=sync/atomic" ./... @$(FAILLINT) -paths "fmt.{Print,Println,Sprint}" -ignore-tests ./... @echo ">> linting all of the Go files GOGC=${GOGC}" @$(GOLANGCI_LINT) run diff --git a/go.mod b/go.mod index a72cbfa9..e4d1cdf0 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,6 @@ require ( github.com/tencentyun/cos-go-sdk-v5 v0.7.40 go.opentelemetry.io/otel v1.16.0 go.opentelemetry.io/otel/trace v1.16.0 - go.uber.org/atomic v1.9.0 golang.org/x/oauth2 v0.14.0 golang.org/x/sync v0.5.0 google.golang.org/api v0.150.0 diff --git a/go.sum b/go.sum index a4675567..1d0d5126 100644 --- a/go.sum +++ b/go.sum @@ -221,8 +221,6 @@ go.opentelemetry.io/otel v1.16.0 h1:Z7GVAX/UkAXPKsy94IU+i6thsQS4nb7LviLpnaNeW8s= go.opentelemetry.io/otel v1.16.0/go.mod h1:vl0h9NUa1D5s1nv3A5vZOYWn8av4K8Ml6JDeHrT/bx4= go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs= go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0= -go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= -go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= diff --git a/objstore.go b/objstore.go index c9130687..4da28b99 100644 --- a/objstore.go +++ b/objstore.go @@ -430,8 +430,8 @@ func WrapWithMetrics(b Bucket, reg prometheus.Registerer, name string) *metricBu ConstLabels: prometheus.Labels{"bucket": name}, Buckets: prometheus.ExponentialBuckets(2<<14, 2, 16), // 32KiB, 64KiB, ... 1GiB // Use factor=2 for native histograms, which gives similar buckets as the original exponential buckets. - NativeHistogramBucketFactor: 2, - NativeHistogramMaxBucketNumber: 100, + NativeHistogramBucketFactor: 2, + NativeHistogramMaxBucketNumber: 100, NativeHistogramMinResetDuration: 1 * time.Hour, }, []string{"operation"}), @@ -441,8 +441,8 @@ func WrapWithMetrics(b Bucket, reg prometheus.Registerer, name string) *metricBu ConstLabels: prometheus.Labels{"bucket": name}, Buckets: []float64{0.001, 0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120}, // Use the recommended defaults for native histograms with 10% growth factor. - NativeHistogramBucketFactor: 1.1, - NativeHistogramMaxBucketNumber: 100, + NativeHistogramBucketFactor: 1.1, + NativeHistogramMaxBucketNumber: 100, NativeHistogramMinResetDuration: 1 * time.Hour, }, []string{"operation"}), diff --git a/objstore_test.go b/objstore_test.go index ababe62c..a2c53934 100644 --- a/objstore_test.go +++ b/objstore_test.go @@ -10,6 +10,7 @@ import ( "os" "path/filepath" "strings" + "sync/atomic" "testing" "github.com/efficientgo/core/testutil" @@ -17,7 +18,6 @@ import ( "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" promtest "github.com/prometheus/client_golang/prometheus/testutil" - "go.uber.org/atomic" ) func TestMetricBucket_Close(t *testing.T) { @@ -469,7 +469,7 @@ func TestDownloadDir_CleanUp(t *testing.T) { b := unreliableBucket{ Bucket: NewInMemBucket(), n: 3, - current: atomic.NewInt32(0), + current: &atomic.Int32{}, } tempDir := t.TempDir() @@ -492,7 +492,7 @@ type unreliableBucket struct { } func (b unreliableBucket) Get(ctx context.Context, name string) (io.ReadCloser, error) { - if b.current.Inc()%b.n == 0 { + if b.current.Add(1)%b.n == 0 { return nil, errors.Errorf("some error message") } return b.Bucket.Get(ctx, name)