diff --git a/.github/workflows/appsec.yml b/.github/workflows/appsec.yml index f913f17fdf..3800203896 100644 --- a/.github/workflows/appsec.yml +++ b/.github/workflows/appsec.yml @@ -95,7 +95,7 @@ jobs: strategy: matrix: runs-on: [ macos-12, macos-14 ] # oldest and newest macos runners available - macos-14 mainly is here to cover the fact it is an ARM machine - go-version: [ "1.22", "1.21" ] + go-version: [ "1.23", "1.22" ] fail-fast: true # saving some CI time - macos runners too long to get steps: - uses: actions/checkout@v4 @@ -187,7 +187,7 @@ jobs: needs: go-mod-caching strategy: matrix: - go-version: [ "1.22", "1.21" ] + go-version: [ "1.23", "1.22" ] distribution: [ bookworm, bullseye, alpine ] platform: [ linux/amd64, linux/arm64 ] diff --git a/.github/workflows/main-branch-tests.yml b/.github/workflows/main-branch-tests.yml index 96e4c7ea25..7d738ccd9a 100644 --- a/.github/workflows/main-branch-tests.yml +++ b/.github/workflows/main-branch-tests.yml @@ -22,7 +22,7 @@ jobs: unit-integration-tests: strategy: matrix: - go-version: [ "1.21", "1.22" ] + go-version: [ "1.22", "1.23" ] fail-fast: false uses: ./.github/workflows/unit-integration-tests.yml with: @@ -33,7 +33,7 @@ jobs: strategy: matrix: runs-on: [ macos-latest, windows-latest, ubuntu-latest ] - go-version: [ "1.21", "1.22" ] + go-version: [ "1.22", "1.23" ] fail-fast: false uses: ./.github/workflows/multios-unit-tests.yml with: diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 128967216d..9513b2e328 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -18,6 +18,6 @@ jobs: name: PR Unit and Integration Tests uses: ./.github/workflows/unit-integration-tests.yml with: - go-version: "1.21" + go-version: "1.22" ref: ${{ github.ref }} secrets: inherit diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml index 69d6bce9ca..973db5f737 100644 --- a/.github/workflows/smoke-tests.yml +++ b/.github/workflows/smoke-tests.yml @@ -83,7 +83,7 @@ jobs: ref: ${{ inputs.ref || github.ref }} - uses: actions/setup-go@v3 with: - go-version: "1.21" + go-version: "1.22" cache: true - name: go mod tidy run: |- @@ -106,7 +106,7 @@ jobs: matrix: # TODO: cross-compilation from/to different hardware architectures once # github provides native ARM runners. - go: [ "1.21", "1.22", "1.23-rc" ] + go: [ "1.22", "1.23" ] build-env: [ alpine, bookworm, bullseye ] build-with-cgo: [ 0, 1 ] deployment-env: [ alpine, debian11, debian12, al2, al2023, busybox, scratch ] diff --git a/.github/workflows/unit-integration-tests.yml b/.github/workflows/unit-integration-tests.yml index 040fbb62f3..42a5a8a70f 100644 --- a/.github/workflows/unit-integration-tests.yml +++ b/.github/workflows/unit-integration-tests.yml @@ -28,7 +28,10 @@ jobs: uses: actions/checkout@v3 with: ref: ${{ inputs.ref || github.ref }} - + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version: stable - name: Copyright run: | go run checkcopyright.go diff --git a/contrib/net/http/http_test.go b/contrib/net/http/http_test.go index 47e0370e13..766046527f 100644 --- a/contrib/net/http/http_test.go +++ b/contrib/net/http/http_test.go @@ -334,7 +334,6 @@ func TestServeMuxGo122Patterns(t *testing.T) { func TestWrapHandlerWithResourceNameNoRace(_ *testing.T) { mt := mocktracer.Start() defer mt.Stop() - r := httptest.NewRequest("GET", "/", nil) resourceNamer := func(_ *http.Request) string { return "custom-resource-name" } @@ -346,8 +345,9 @@ func TestWrapHandlerWithResourceNameNoRace(_ *testing.T) { for i := 0; i < 10; i++ { wg.Add(1) go func() { - w := httptest.NewRecorder() defer wg.Done() + w := httptest.NewRecorder() + r := httptest.NewRequest("GET", "/", nil) mux.ServeHTTP(w, r) }() } diff --git a/ddtrace/tracer/rand.go b/ddtrace/tracer/rand.go index 8eb04c0fed..192a6725f9 100644 --- a/ddtrace/tracer/rand.go +++ b/ddtrace/tracer/rand.go @@ -3,68 +3,17 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016 Datadog, Inc. -//go:build !go1.22 - -// TODO(knusbaum): This file should be deleted once go1.21 falls out of support package tracer import ( - cryptorand "crypto/rand" "math" - "math/big" - "math/rand" - "sync" - "time" - - "gopkg.in/DataDog/dd-trace-go.v1/internal/log" + "math/rand/v2" ) -// random holds a thread-safe source of random numbers. -var random *rand.Rand - -func init() { - var seed int64 - n, err := cryptorand.Int(cryptorand.Reader, big.NewInt(math.MaxInt64)) - if err == nil { - seed = n.Int64() - } else { - log.Warn("cannot generate random seed: %v; using current time", err) - seed = time.Now().UnixNano() - } - random = rand.New(&safeSource{ - source: rand.NewSource(seed), - }) -} - -// safeSource holds a thread-safe implementation of rand.Source64. -type safeSource struct { - source rand.Source - sync.Mutex -} - -func (rs *safeSource) Int63() int64 { - rs.Lock() - n := rs.source.Int63() - rs.Unlock() - - return n -} - -func (rs *safeSource) Uint64() uint64 { return uint64(rs.Int63()) } - -func (rs *safeSource) Seed(seed int64) { - rs.Lock() - rs.source.Seed(seed) - rs.Unlock() +func randUint64() uint64 { + return rand.Uint64() } -// generateSpanID returns a random uint64 that has been XORd with the startTime. -// This is done to get around the 32-bit random seed limitation that may create collisions if there is a large number -// of go services all generating spans. func generateSpanID(startTime int64) uint64 { - return random.Uint64() ^ uint64(startTime) -} - -func randUint64() uint64 { - return random.Uint64() + return rand.Uint64() & math.MaxInt64 } diff --git a/ddtrace/tracer/rand_go1_22.go b/ddtrace/tracer/rand_go1_22.go deleted file mode 100644 index 9e7948e47e..0000000000 --- a/ddtrace/tracer/rand_go1_22.go +++ /dev/null @@ -1,21 +0,0 @@ -// Unless explicitly stated otherwise all files in this repository are licensed -// under the Apache License Version 2.0. -// This product includes software developed at Datadog (https://www.datadoghq.com/). -// Copyright 2016 Datadog, Inc. - -//go:build go1.22 - -package tracer - -import ( - "math" - "math/rand/v2" -) - -func randUint64() uint64 { - return rand.Uint64() -} - -func generateSpanID(startTime int64) uint64 { - return rand.Uint64() & math.MaxInt64 -} diff --git a/go.mod b/go.mod index 591bbd975e..b22d6624a0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module gopkg.in/DataDog/dd-trace-go.v1 -go 1.21 +go 1.22.0 require ( cloud.google.com/go/pubsub v1.33.0 diff --git a/internal/apps/Dockerfile b/internal/apps/Dockerfile index 2f32c31648..462dd2080e 100644 --- a/internal/apps/Dockerfile +++ b/internal/apps/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21 +FROM golang:1.22 COPY . /dd-trace-go WORKDIR /dd-trace-go/internal/apps # -t will download all dependencies, including test dependencies diff --git a/internal/apps/go.mod b/internal/apps/go.mod index 2aebc0aee2..b27c3303c3 100644 --- a/internal/apps/go.mod +++ b/internal/apps/go.mod @@ -1,6 +1,6 @@ module github.com/DataDog/dd-trace-go/internal/apps -go 1.21 +go 1.22.0 require ( golang.org/x/sync v0.5.0 diff --git a/internal/apps/setup-smoke-test/Dockerfile b/internal/apps/setup-smoke-test/Dockerfile index 7828ed071a..72b451e8bd 100644 --- a/internal/apps/setup-smoke-test/Dockerfile +++ b/internal/apps/setup-smoke-test/Dockerfile @@ -17,7 +17,7 @@ # select one by default, but also allows to provide a --build-arg option # too instead of relying on the --target option. This way, the CI matrix # can systematically use --build-arg for all of the parameters. -ARG go="1.21" # golang docker image parameter in `golang:{go}-{buildenv}` +ARG go="1.22" # golang docker image parameter in `golang:{go}-{buildenv}` ARG build_env="bookworm" # golang docker image parameter in `golang:{go}-{buildenv}` ARG build_with_cgo="0" # 0 or 1 ARG build_with_vendoring="" # y or empty diff --git a/internal/appsec/config/rules_manager.go b/internal/appsec/config/rules_manager.go index a61f68e804..f2eedb8cf9 100644 --- a/internal/appsec/config/rules_manager.go +++ b/internal/appsec/config/rules_manager.go @@ -8,6 +8,7 @@ package config import ( "encoding/json" "fmt" + "slices" "gopkg.in/DataDog/dd-trace-go.v1/internal/log" @@ -60,23 +61,16 @@ func DefaultRulesFragment() RulesFragment { func (f *RulesFragment) clone() (clone RulesFragment) { clone.Version = f.Version clone.Metadata = f.Metadata - clone.Overrides = cloneSlice(f.Overrides) - clone.Exclusions = cloneSlice(f.Exclusions) - clone.RulesData = cloneSlice(f.RulesData) - clone.CustomRules = cloneSlice(f.CustomRules) - clone.Processors = cloneSlice(f.Processors) - clone.Scanners = cloneSlice(f.Scanners) + clone.Overrides = slices.Clone(f.Overrides) + clone.Exclusions = slices.Clone(f.Exclusions) + clone.RulesData = slices.Clone(f.RulesData) + clone.CustomRules = slices.Clone(f.CustomRules) + clone.Processors = slices.Clone(f.Processors) + clone.Scanners = slices.Clone(f.Scanners) // TODO (Francois Mazeau): copy more fields once we handle them return } -func cloneSlice[T any](slice []T) []T { - // TODO: use slices.Clone once go1.21 is the min supported go runtime. - clone := make([]T, len(slice), cap(slice)) - copy(clone, slice) - return clone -} - // NewRulesManeger initializes and returns a new RulesManager using the provided rules. // If no rules are provided (nil), the default rules are used instead. // If the provided rules are invalid, an error is returned diff --git a/internal/exectracetest/go.mod b/internal/exectracetest/go.mod index a37c9b4d23..d67a01c142 100644 --- a/internal/exectracetest/go.mod +++ b/internal/exectracetest/go.mod @@ -1,6 +1,6 @@ module gopkg.in/DataDog/dd-trace-go.v1/internal/exectracetest -go 1.21 +go 1.22.0 require ( github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b