Skip to content

Commit

Permalink
refactor: replace uber atomic with stdlib atomic types (#39853)
Browse files Browse the repository at this point in the history
* refactor: replace uber atomic with stdlib atomic types

Go 1.19 added new atomic types. Migrate usage of go.uber.org/atomic to sync/atomic
and drop the dependency.

* refactor: store concrete type instead of pointer

* Update input.go

* lint: fix linting errors
  • Loading branch information
kruskall authored Jun 13, 2024
1 parent 974ace6 commit 9d2b48d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 53 deletions.
58 changes: 29 additions & 29 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24852,35 +24852,6 @@ Contents of probable licence file $GOMODCACHE/go.mongodb.org/[email protected]
limitations under the License.


--------------------------------------------------------------------------------
Dependency : go.uber.org/atomic
Version: v1.11.0
Licence type (autodetected): MIT
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/go.uber.org/[email protected]/LICENSE.txt:

Copyright (c) 2016 Uber Technologies, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


--------------------------------------------------------------------------------
Dependency : go.uber.org/multierr
Version: v1.11.0
Expand Down Expand Up @@ -55030,6 +55001,35 @@ Contents of probable licence file $GOMODCACHE/go.opentelemetry.io/otel/trace@v1.
limitations under the License.


--------------------------------------------------------------------------------
Dependency : go.uber.org/atomic
Version: v1.11.0
Licence type (autodetected): MIT
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/go.uber.org/[email protected]/LICENSE.txt:

Copyright (c) 2016 Uber Technologies, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


--------------------------------------------------------------------------------
Dependency : go.uber.org/goleak
Version: v1.3.0
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ require (
go.elastic.co/ecszap v1.0.2
go.elastic.co/go-licence-detector v0.6.0
go.etcd.io/bbolt v1.3.6
go.uber.org/atomic v1.11.0
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.22.0
Expand Down
8 changes: 4 additions & 4 deletions x-pack/filebeat/input/http_endpoint/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
"sort"
"strconv"
"strings"
"sync/atomic"
"time"

"github.com/google/cel-go/cel"
"github.com/google/cel-go/checker/decls"
"github.com/google/cel-go/common/types"
"github.com/google/cel-go/common/types/ref"
"go.uber.org/atomic"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"google.golang.org/protobuf/types/known/structpb"
Expand Down Expand Up @@ -53,8 +53,8 @@ type handler struct {
publish func(beat.Event)
log *logp.Logger
validator apiValidator
txBaseID string // Random value to make transaction IDs unique.
txIDCounter *atomic.Uint64 // Transaction ID counter that is incremented for each request.
txBaseID string // Random value to make transaction IDs unique.
txIDCounter atomic.Uint64 // Transaction ID counter that is incremented for each request.

reqLogger *zap.Logger
host, scheme string
Expand Down Expand Up @@ -290,7 +290,7 @@ func (h *handler) logRequest(txID string, r *http.Request, status int, respBody
}

func (h *handler) nextTxID() string {
count := h.txIDCounter.Inc()
count := h.txIDCounter.Add(1)
return h.formatTxID(count)
}

Expand Down
8 changes: 3 additions & 5 deletions x-pack/filebeat/input/http_endpoint/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/rcrowley/go-metrics"
"go.elastic.co/ecszap"
"go.uber.org/atomic"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

Expand Down Expand Up @@ -327,10 +326,9 @@ func (s *server) getErr() error {

func newHandler(ctx context.Context, c config, prg *program, pub func(beat.Event), log *logp.Logger, metrics *inputMetrics) http.Handler {
h := &handler{
ctx: ctx,
log: log,
txBaseID: newID(),
txIDCounter: atomic.NewUint64(0),
ctx: ctx,
log: log,
txBaseID: newID(),

publish: pub,
metrics: metrics,
Expand Down
23 changes: 11 additions & 12 deletions x-pack/filebeat/input/internal/httplog/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"net/http"
"net/http/httputil"
"strconv"
"sync/atomic"
"time"

"go.uber.org/atomic"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

Expand All @@ -36,22 +36,21 @@ type contextKey string
// responses to the provided logger. Transaction creation is logged to log.
func NewLoggingRoundTripper(next http.RoundTripper, logger *zap.Logger, maxBodyLen int, log *logp.Logger) *LoggingRoundTripper {
return &LoggingRoundTripper{
transport: next,
maxBodyLen: maxBodyLen,
txLog: logger,
txBaseID: newID(),
txIDCounter: atomic.NewUint64(0),
log: log,
transport: next,
maxBodyLen: maxBodyLen,
txLog: logger,
txBaseID: newID(),
log: log,
}
}

// LoggingRoundTripper is an http.RoundTripper that logs requests and responses.
type LoggingRoundTripper struct {
transport http.RoundTripper
maxBodyLen int // The maximum length of a body. Longer bodies will be truncated.
txLog *zap.Logger // Destination logger.
txBaseID string // Random value to make transaction IDs unique.
txIDCounter *atomic.Uint64 // Transaction ID counter that is incremented for each request.
maxBodyLen int // The maximum length of a body. Longer bodies will be truncated.
txLog *zap.Logger // Destination logger.
txBaseID string // Random value to make transaction IDs unique.
txIDCounter atomic.Uint64 // Transaction ID counter that is incremented for each request.
log *logp.Logger
}

Expand Down Expand Up @@ -220,7 +219,7 @@ func (rt *LoggingRoundTripper) TxID() string {
// nextTxID returns the next transaction.id value. It increments the internal
// request counter.
func (rt *LoggingRoundTripper) nextTxID() string {
count := rt.txIDCounter.Inc()
count := rt.txIDCounter.Add(1)
return rt.formatTxID(count)
}

Expand Down
4 changes: 2 additions & 2 deletions x-pack/functionbeat/manager/aws/event_stack_poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ package aws
import (
"context"
"strconv"
"sync/atomic"
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"

"github.com/aws/aws-sdk-go-v2/service/cloudformation"
"github.com/stretchr/testify/assert"
"go.uber.org/atomic"

"github.com/elastic/elastic-agent-libs/logp"
)
Expand All @@ -29,7 +29,7 @@ func (m *mockEventHandler) sync(event types.StackEvent) bool {
if m.skipCount.Load() >= m.skipEvents {
return false
}
m.skipCount.Inc()
m.skipCount.Add(1)
return true
}

Expand Down

0 comments on commit 9d2b48d

Please sign in to comment.