Skip to content

Commit

Permalink
Replace go.uber.org/atomic with sync/atomic (#19385)
Browse files Browse the repository at this point in the history
Co-authored-by: Evan Bradley <[email protected]>
  • Loading branch information
dubonzi and evan-bradley committed Mar 8, 2023
1 parent e7033bd commit 03c7bc0
Show file tree
Hide file tree
Showing 68 changed files with 197 additions and 173 deletions.
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ linters-settings:
list-type: denylist
include-go-root: true
packages-with-error-message:
# See https://github.com/open-telemetry/opentelemetry-collector/issues/5200 for rationale
- sync/atomic: "Use go.uber.org/atomic instead of sync/atomic"
- go.uber.org/atomic: "Use 'sync/atomic' instead of go.uber.org/atomic"
- github.com/pkg/errors: "Use 'errors' or 'fmt' instead of github.com/pkg/errors"
- github.com/hashicorp/go-multierror: "Use go.uber.org/multierr instead of github.com/hashicorp/go-multierror"
# Add a different guard rule so that we can ignore tests.
Expand Down
2 changes: 1 addition & 1 deletion cmd/telemetrygen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ require (
go.opentelemetry.io/otel/sdk v1.14.0
go.opentelemetry.io/otel/sdk/metric v0.37.0
go.opentelemetry.io/otel/trace v1.14.0
go.uber.org/atomic v1.10.0
go.uber.org/zap v1.24.0
golang.org/x/time v0.3.0
google.golang.org/grpc v1.53.0
Expand All @@ -41,6 +40,7 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.37.0 // indirect
go.opentelemetry.io/otel/metric v0.37.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions cmd/telemetrygen/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions cmd/telemetrygen/internal/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
"context"
"fmt"
"sync"
"sync/atomic"
"time"

"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/plog/plogotlp"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
"go.uber.org/atomic"
"go.uber.org/zap"
"golang.org/x/time/rate"
"google.golang.org/grpc"
Expand Down Expand Up @@ -98,9 +98,11 @@ func Run(c *Config, exp exporter, logger *zap.Logger) error {
}

wg := sync.WaitGroup{}
running := atomic.NewBool(true)
res := resource.NewWithAttributes(semconv.SchemaURL, c.GetAttributes()...)

running := &atomic.Bool{}
running.Store(true)

for i := 0; i < c.WorkerCount; i++ {
wg.Add(1)
w := worker{
Expand Down
2 changes: 1 addition & 1 deletion cmd/telemetrygen/internal/logs/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ package logs
import (
"context"
"sync"
"sync/atomic"
"time"

"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/otel/sdk/resource"
"go.uber.org/atomic"
"go.uber.org/zap"
"golang.org/x/time/rate"
)
Expand Down
6 changes: 4 additions & 2 deletions cmd/telemetrygen/internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import (
"context"
"fmt"
"sync"
"sync/atomic"
"time"

semconv "go.opentelemetry.io/collector/semconv/v1.13.0"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
"go.uber.org/atomic"
"go.uber.org/zap"
"golang.org/x/time/rate"
"google.golang.org/grpc"
Expand Down Expand Up @@ -105,9 +105,11 @@ func Run(c *Config, exp sdkmetric.Exporter, logger *zap.Logger) error {
}

wg := sync.WaitGroup{}
running := atomic.NewBool(true)
res := resource.NewWithAttributes(semconv.SchemaURL, c.GetAttributes()...)

running := &atomic.Bool{}
running.Store(true)

for i := 0; i < c.WorkerCount; i++ {
wg.Add(1)
w := worker{
Expand Down
2 changes: 1 addition & 1 deletion cmd/telemetrygen/internal/metrics/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ package metrics
import (
"context"
"sync"
"sync/atomic"
"time"

sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"go.opentelemetry.io/otel/sdk/resource"
"go.uber.org/atomic"
"go.uber.org/zap"
"golang.org/x/time/rate"
)
Expand Down
6 changes: 4 additions & 2 deletions cmd/telemetrygen/internal/traces/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"sync"
"sync/atomic"
"time"

"go.opentelemetry.io/otel"
Expand All @@ -28,7 +29,6 @@ import (
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
"go.uber.org/atomic"
"go.uber.org/zap"
"golang.org/x/time/rate"
"google.golang.org/grpc"
Expand Down Expand Up @@ -127,7 +127,9 @@ func Run(c *Config, logger *zap.Logger) error {
}

wg := sync.WaitGroup{}
running := atomic.NewBool(true)

running := &atomic.Bool{}
running.Store(true)

for i := 0; i < c.WorkerCount; i++ {
wg.Add(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/telemetrygen/internal/traces/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ package traces // import "github.com/open-telemetry/opentelemetry-collector-cont
import (
"context"
"sync"
"sync/atomic"
"time"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
"go.opentelemetry.io/otel/trace"
"go.uber.org/atomic"
"go.uber.org/zap"
"golang.org/x/time/rate"
)
Expand Down
4 changes: 2 additions & 2 deletions exporter/carbonexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"runtime"
"strconv"
"sync"
"sync/atomic"
"testing"
"time"

Expand All @@ -34,7 +35,6 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
conventions "go.opentelemetry.io/collector/semconv/v1.9.0"
"go.uber.org/atomic"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
)
Expand Down Expand Up @@ -187,7 +187,7 @@ func Test_connPool_Concurrency(t *testing.T) {
concurrentWriters := 3
writesPerRoutine := 3

doneFlag := atomic.NewBool(false)
doneFlag := &atomic.Bool{}
defer func() {
doneFlag.Store(true)
}()
Expand Down
2 changes: 1 addition & 1 deletion exporter/carbonexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
go.opentelemetry.io/collector/exporter v0.73.0
go.opentelemetry.io/collector/pdata v1.0.0-rc7
go.opentelemetry.io/collector/semconv v0.73.0
go.uber.org/atomic v1.10.0
)

require (
Expand All @@ -36,6 +35,7 @@ require (
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/metric v0.37.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.8.0 // indirect
Expand Down
10 changes: 5 additions & 5 deletions exporter/clickhouseexporter/exporter_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ import (
"database/sql/driver"
"fmt"
"strings"
"sync/atomic"
"testing"
"time"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.uber.org/atomic"
"go.uber.org/zap/zaptest"
)

func TestExporter_pushMetricsData(t *testing.T) {
t.Parallel()
t.Run("push success", func(t *testing.T) {
var items atomic.Int32
items := &atomic.Int32{}
initClickhouseTestServer(t, func(query string, values []driver.Value) error {
if strings.HasPrefix(query, "INSERT") {
items.Inc()
items.Add(1)
}
return nil
})
Expand All @@ -56,10 +56,10 @@ func TestExporter_pushMetricsData(t *testing.T) {
require.Error(t, err)
})
t.Run("check Resource metadata and scope metadata", func(t *testing.T) {
var items atomic.Int32
items := &atomic.Int32{}
initClickhouseTestServer(t, func(query string, values []driver.Value) error {
if strings.HasPrefix(query, "INSERT") {
items.Inc()
items.Add(1)
if strings.HasPrefix(query, "INSERT INTO otel_metrics_exponential_histogram") {
require.Equal(t, "Resource SchemaUrl 1", values[1])
require.Equal(t, "Scope name 1", values[2])
Expand Down
2 changes: 1 addition & 1 deletion exporter/clickhouseexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
go.opentelemetry.io/collector/exporter v0.73.0
go.opentelemetry.io/collector/pdata v1.0.0-rc7
go.opentelemetry.io/collector/semconv v0.73.0
go.uber.org/atomic v1.10.0
go.uber.org/multierr v1.9.0
go.uber.org/zap v1.24.0
)
Expand Down Expand Up @@ -51,6 +50,7 @@ require (
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/metric v0.37.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion exporter/elasticsearchexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
go.opentelemetry.io/collector/confmap v0.73.0
go.opentelemetry.io/collector/exporter v0.73.0
go.opentelemetry.io/collector/pdata v1.0.0-rc7
go.uber.org/atomic v1.10.0
go.uber.org/multierr v1.9.0
go.uber.org/zap v1.24.0
)
Expand All @@ -41,6 +40,7 @@ require (
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/metric v0.37.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions exporter/elasticsearchexporter/logs_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (
"net/http"
"runtime"
"sync"
"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"
)
Expand Down Expand Up @@ -199,13 +199,13 @@ func TestExporter_PushEvent(t *testing.T) {
handlers := map[string]func(attempts *atomic.Int64) bulkHandler{
"fail http request": func(attempts *atomic.Int64) bulkHandler {
return func([]itemRequest) ([]itemResponse, error) {
attempts.Inc()
attempts.Add(1)
return nil, &httpTestError{message: "oops"}
}
},
"fail item": func(attempts *atomic.Int64) bulkHandler {
return func(docs []itemRequest) ([]itemResponse, error) {
attempts.Inc()
attempts.Add(1)
return itemsReportStatus(docs, http.StatusTooManyRequests)
}
},
Expand All @@ -217,7 +217,7 @@ func TestExporter_PushEvent(t *testing.T) {
for name, configurer := range configurations {
t.Run(name, func(t *testing.T) {
t.Parallel()
attempts := atomic.NewInt64(0)
attempts := &atomic.Int64{}
server := newESTestServer(t, handler(attempts))

testConfig := configurer(server.URL)
Expand All @@ -233,9 +233,9 @@ func TestExporter_PushEvent(t *testing.T) {
})

t.Run("do not retry invalid request", func(t *testing.T) {
attempts := atomic.NewInt64(0)
attempts := &atomic.Int64{}
server := newESTestServer(t, func(docs []itemRequest) ([]itemResponse, error) {
attempts.Inc()
attempts.Add(1)
return nil, &httpTestError{message: "oops", status: http.StatusBadRequest}
})

Expand Down Expand Up @@ -267,9 +267,9 @@ func TestExporter_PushEvent(t *testing.T) {
})

t.Run("do not retry bad item", func(t *testing.T) {
attempts := atomic.NewInt64(0)
attempts := &atomic.Int64{}
server := newESTestServer(t, func(docs []itemRequest) ([]itemResponse, error) {
attempts.Inc()
attempts.Add(1)
return itemsReportStatus(docs, http.StatusBadRequest)
})

Expand Down
Loading

0 comments on commit 03c7bc0

Please sign in to comment.