From 74a00c7dd0c42347e2ab66925e5a06c69df9ad9c Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Tue, 11 Jun 2024 01:42:58 +0200 Subject: [PATCH 1/4] 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. --- NOTICE.txt | 58 +++++++++---------- go.mod | 2 +- .../filebeat/input/http_endpoint/handler.go | 4 +- x-pack/filebeat/input/http_endpoint/input.go | 4 +- .../input/internal/httplog/roundtripper.go | 6 +- .../manager/aws/event_stack_poller_test.go | 4 +- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index f6881a796c0..c476eea8226 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -24852,35 +24852,6 @@ Contents of probable licence file $GOMODCACHE/go.mongodb.org/mongo-driver@v1.5.1 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/atomic@v1.11.0/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 @@ -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/atomic@v1.11.0/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 diff --git a/go.mod b/go.mod index d7709734067..d74739dbd71 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/x-pack/filebeat/input/http_endpoint/handler.go b/x-pack/filebeat/input/http_endpoint/handler.go index b799248a935..102b31eec6f 100644 --- a/x-pack/filebeat/input/http_endpoint/handler.go +++ b/x-pack/filebeat/input/http_endpoint/handler.go @@ -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" @@ -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) } diff --git a/x-pack/filebeat/input/http_endpoint/input.go b/x-pack/filebeat/input/http_endpoint/input.go index 6737a9b9aa0..c673db9027b 100644 --- a/x-pack/filebeat/input/http_endpoint/input.go +++ b/x-pack/filebeat/input/http_endpoint/input.go @@ -20,11 +20,11 @@ import ( "reflect" "strings" "sync" + "sync/atomic" "time" "github.com/rcrowley/go-metrics" "go.elastic.co/ecszap" - "go.uber.org/atomic" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -330,7 +330,7 @@ func newHandler(ctx context.Context, c config, prg *program, pub func(beat.Event ctx: ctx, log: log, txBaseID: newID(), - txIDCounter: atomic.NewUint64(0), + txIDCounter: &atomic.Uint64{}, publish: pub, metrics: metrics, diff --git a/x-pack/filebeat/input/internal/httplog/roundtripper.go b/x-pack/filebeat/input/internal/httplog/roundtripper.go index ce68147a2a7..982c18824db 100644 --- a/x-pack/filebeat/input/internal/httplog/roundtripper.go +++ b/x-pack/filebeat/input/internal/httplog/roundtripper.go @@ -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" @@ -40,7 +40,7 @@ func NewLoggingRoundTripper(next http.RoundTripper, logger *zap.Logger, maxBodyL maxBodyLen: maxBodyLen, txLog: logger, txBaseID: newID(), - txIDCounter: atomic.NewUint64(0), + txIDCounter: &atomic.Uint64{}, log: log, } } @@ -220,7 +220,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) } diff --git a/x-pack/functionbeat/manager/aws/event_stack_poller_test.go b/x-pack/functionbeat/manager/aws/event_stack_poller_test.go index fe7473d0f3d..3679f07fb54 100644 --- a/x-pack/functionbeat/manager/aws/event_stack_poller_test.go +++ b/x-pack/functionbeat/manager/aws/event_stack_poller_test.go @@ -7,6 +7,7 @@ package aws import ( "context" "strconv" + "sync/atomic" "testing" "time" @@ -14,7 +15,6 @@ import ( "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" ) @@ -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 } From 8c9cb27dce98643d2c1fd1a2ab5057ab954e8661 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Tue, 11 Jun 2024 03:00:52 +0200 Subject: [PATCH 2/4] refactor: store concrete type instead of pointer --- .../filebeat/input/http_endpoint/handler.go | 4 ++-- x-pack/filebeat/input/http_endpoint/input.go | 1 - .../input/internal/httplog/roundtripper.go | 19 +++++++++---------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/x-pack/filebeat/input/http_endpoint/handler.go b/x-pack/filebeat/input/http_endpoint/handler.go index 102b31eec6f..4f3fdd550aa 100644 --- a/x-pack/filebeat/input/http_endpoint/handler.go +++ b/x-pack/filebeat/input/http_endpoint/handler.go @@ -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 diff --git a/x-pack/filebeat/input/http_endpoint/input.go b/x-pack/filebeat/input/http_endpoint/input.go index c673db9027b..e86caf08146 100644 --- a/x-pack/filebeat/input/http_endpoint/input.go +++ b/x-pack/filebeat/input/http_endpoint/input.go @@ -330,7 +330,6 @@ func newHandler(ctx context.Context, c config, prg *program, pub func(beat.Event ctx: ctx, log: log, txBaseID: newID(), - txIDCounter: &atomic.Uint64{}, publish: pub, metrics: metrics, diff --git a/x-pack/filebeat/input/internal/httplog/roundtripper.go b/x-pack/filebeat/input/internal/httplog/roundtripper.go index 982c18824db..9e60cb60942 100644 --- a/x-pack/filebeat/input/internal/httplog/roundtripper.go +++ b/x-pack/filebeat/input/internal/httplog/roundtripper.go @@ -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.Uint64{}, - 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 } From 135b9b3c0c71a19c711f90c87010a9af7ecbef67 Mon Sep 17 00:00:00 2001 From: kruskall <99559985+kruskall@users.noreply.github.com> Date: Tue, 11 Jun 2024 12:03:50 +0200 Subject: [PATCH 3/4] Update input.go --- x-pack/filebeat/input/http_endpoint/input.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/filebeat/input/http_endpoint/input.go b/x-pack/filebeat/input/http_endpoint/input.go index e86caf08146..f267e7b2cb3 100644 --- a/x-pack/filebeat/input/http_endpoint/input.go +++ b/x-pack/filebeat/input/http_endpoint/input.go @@ -20,7 +20,6 @@ import ( "reflect" "strings" "sync" - "sync/atomic" "time" "github.com/rcrowley/go-metrics" From 575aadb0ed389bf4ac2fedacb38b8b6bd5d1be9b Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:03:07 +0200 Subject: [PATCH 4/4] lint: fix linting errors --- x-pack/filebeat/input/http_endpoint/input.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/filebeat/input/http_endpoint/input.go b/x-pack/filebeat/input/http_endpoint/input.go index f267e7b2cb3..7f0440deb60 100644 --- a/x-pack/filebeat/input/http_endpoint/input.go +++ b/x-pack/filebeat/input/http_endpoint/input.go @@ -326,9 +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(), + ctx: ctx, + log: log, + txBaseID: newID(), publish: pub, metrics: metrics,