Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: upgrade minimum supported Go release to 1.22 #2850

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/appsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ]

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main-branch-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
Expand All @@ -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 ]
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/unit-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ jobs:
uses: actions/checkout@v3
with:
ref: ${{ inputs.ref || github.ref }}

- name: Setup go
uses: actions/setup-go@v5
nsrip-dd marked this conversation as resolved.
Show resolved Hide resolved
with:
go-version: stable
- name: Copyright
run: |
go run checkcopyright.go
Expand Down
4 changes: 2 additions & 2 deletions contrib/net/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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)
}()
}
Expand Down
59 changes: 4 additions & 55 deletions ddtrace/tracer/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
21 changes: 0 additions & 21 deletions ddtrace/tracer/rand_go1_22.go

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/apps/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/apps/go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/apps/setup-smoke-test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 7 additions & 13 deletions internal/appsec/config/rules_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package config
import (
"encoding/json"
"fmt"
"slices"

"gopkg.in/DataDog/dd-trace-go.v1/internal/log"

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/exectracetest/go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading