Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into aws-streamname-fix
Browse files Browse the repository at this point in the history
webdestroya authored Sep 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 6f01e1f + 4b164f8 commit dcd3e6a
Showing 14 changed files with 32 additions and 120 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/appsec.yml
Original file line number Diff line number Diff line change
@@ -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 ]

4 changes: 2 additions & 2 deletions .github/workflows/main-branch-tests.yml
Original file line number Diff line number Diff line change
@@ -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:
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -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
@@ -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 ]
5 changes: 4 additions & 1 deletion .github/workflows/unit-integration-tests.yml
Original file line number Diff line number Diff line change
@@ -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
23 changes: 5 additions & 18 deletions contrib/net/http/http_test.go
Original file line number Diff line number Diff line change
@@ -313,28 +313,14 @@ func TestServeMuxGo122Patterns(t *testing.T) {

// Check the /foo span
fooSpan := spans[1]
if fooW.Code == http.StatusOK {
assert.Equal("/foo", fooSpan.Tag(ext.HTTPRoute))
assert.Equal("GET /foo", fooSpan.Tag(ext.ResourceName))
} else {
// Until our go.mod version is go1.22 or greater, the mux will not
// understand the "GET /foo" pattern, causing the request to be handled
// by the 404 handler. Let's assert what we can, and mark the test as
// skipped to highlight the issue.
assert.Equal(http.StatusNotFound, fooW.Code)
assert.Equal(nil, fooSpan.Tag(ext.HTTPRoute))
// Using "GET " as a resource name doesn't seem ideal, but that's how
// the mux instrumentation deals with 404s right now.
assert.Equal("GET ", fooSpan.Tag(ext.ResourceName))
t.Skip("run `go mod edit -go=1.22` to run the full test")
}

assert.Equal(http.StatusOK, fooW.Code)
assert.Equal("/foo", fooSpan.Tag(ext.HTTPRoute))
assert.Equal("GET /foo", fooSpan.Tag(ext.ResourceName))
}

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 +332,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)
}()
}
59 changes: 4 additions & 55 deletions ddtrace/tracer/rand.go
Original file line number Diff line number Diff line change
@@ -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
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
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
2 changes: 1 addition & 1 deletion internal/apps/setup-smoke-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
20 changes: 7 additions & 13 deletions internal/appsec/config/rules_manager.go
Original file line number Diff line number Diff line change
@@ -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
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

0 comments on commit dcd3e6a

Please sign in to comment.