Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into vits
Browse files Browse the repository at this point in the history
  • Loading branch information
darccio committed May 16, 2024
2 parents 86f23da + dfa02a3 commit 7ba4a8b
Show file tree
Hide file tree
Showing 41 changed files with 2,757 additions and 122 deletions.
4 changes: 0 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,5 @@
- [ ] Add an appropriate team label so this PR gets put in the right place for the release notes.
- [ ] Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

For Datadog employees:

- [ ] If this PR touches code that handles credentials of any kind, such as Datadog API keys, I've requested a review from `@DataDog/security-design-and-guidance`.
- [ ] This PR doesn't touch any of that.

Unsure? Have a question? Request a review!
3 changes: 3 additions & 0 deletions .github/workflows/multios-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ on:
required: true
type: string

env:
DD_APPSEC_WAF_TIMEOUT: 1m # Increase time WAF time budget to reduce CI flakiness

jobs:
test-multi-os:
runs-on: "${{ (inputs.go-version == '1.20' && inputs.runs-on == 'windows-latest') && 'windows-2019' || inputs.runs-on }}"
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
# Related to issue https://github.com/DataDog/dd-trace-go/issues/1607
name: 'go get -u smoke test'
runs-on: ubuntu-latest
if: github.repository_owner == 'DataDog' # only run on DataDog's repository, not in forks
env:
PACKAGES: ./internal/... ./ddtrace/... ./profiler/... ./appsec/...
steps:
Expand Down Expand Up @@ -65,6 +66,23 @@ jobs:
DD_APPSEC_WAF_TIMEOUT: 1h
run: go test $PACKAGES

go-mod-tidy:
# Run go mod tidy to ensure that all go.mod and go.sum files are up-to-date.
name: 'go mod tidy smoke test'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- uses: actions/setup-go@v3
with:
go-version: "stable"
cache: true
- name: go mod tidy
run: |-
find -name go.mod -execdir go mod tidy \;
git diff --exit-code
# TODO: macos setup requirements (xcode tools installation, etc.)
setup-requirements-linux:
# Build and deployment setup smoke test of linux containers built from the
Expand All @@ -75,6 +93,7 @@ jobs:
# must be considered breaking changes.
name: 'Build and deployment requirements smoke tests'
runs-on: ubuntu-latest
if: github.repository_owner == 'DataDog' # only run on DataDog's repository, not in forks
strategy:
fail-fast: false
matrix:
Expand Down
21 changes: 16 additions & 5 deletions .github/workflows/unit-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
required: true
type: string

env:
DD_APPSEC_WAF_TIMEOUT: 1m # Increase time WAF time budget to reduce CI flakiness

jobs:
copyright:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -163,7 +166,7 @@ jobs:
ports:
- 2181:2181
kafka:
image: wurstmeister/kafka:2.13-2.8.1
image: darccio/kafka:2.13-2.8.1
env:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
Expand Down Expand Up @@ -245,18 +248,26 @@ jobs:
- name: Testing outlier gRPC v1.2
run: |
# This hacky approach is necessary because running the tests regularly
# do not allow using [email protected] alongside [email protected]
# do not allow using [email protected] alongside [email protected].
# [email protected] is no longer possible to test because internal/datastreams/propagator.go
# expects sketches-go to have the package `github.com/DataDog/sketches-go/ddsketch/encoding` which
# is only present from v1.1.0 onwards.
go mod vendor
# Checkout [email protected]
cd vendor/google.golang.org && rm -rf grpc
git clone https://github.com/grpc/grpc-go grpc && cd grpc
git fetch origin && git checkout v1.2.0 && cd ../..
git fetch origin && git checkout v1.2.0 && cd ../../..
# Checkout sketches-go@v1.0.0
# Checkout sketches-go@v1.1.0
cd vendor/github.com/DataDog && rm -rf sketches-go
git clone https://github.com/DataDog/sketches-go && cd sketches-go
git fetch origin && git checkout v1.0.0 && cd ../..
git fetch origin && git checkout v1.1.0 && cd ../../../..
# Revert to old metadata functions as FromIncomingContext and NewOutgoingContext are not present in v1.2.0.
# These functions were updated to current versions to avoid compilation errors in the development environments.
sed -i 's/metadata\.FromIncomingContext/metadata.FromContext/g' ./contrib/google.golang.org/grpc.v12/*
sed -i 's/metadata\.NewOutgoingContext/metadata.NewContext/g' ./contrib/google.golang.org/grpc.v12/*
go test -mod=vendor -v ./contrib/google.golang.org/grpc.v12/...
Expand Down
6 changes: 3 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ stages:
- test-apps

variables:
# This base image is created here: https://gitlab.ddbuild.io/DataDog/apm-reliability/benchmarking-platform/-/pipelines/30087677
BASE_CI_IMAGE: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:dd-trace-go-30087677
# This base image is created here: https://gitlab.ddbuild.io/DataDog/apm-reliability/benchmarking-platform/-/pipelines/30723596
BASE_CI_IMAGE: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:dd-trace-go-30723596
INDEX_FILE: index.txt
KUBERNETES_SERVICE_ACCOUNT_OVERWRITE: dd-trace-go
FF_USE_LEGACY_KUBERNETES_EXECUTION_STRATEGY: "true"
BENCHMARK_TARGETS: "BenchmarkStartRequestSpan|BenchmarkHttpServeTrace|BenchmarkTracerAddSpans|BenchmarkStartSpan|BenchmarkSingleSpanRetention|BenchmarkOTelApiWithCustomTags|BenchmarkInjectW3C|BenchmarkExtractW3C|BenchmarkPartialFlushing|BenchmarkGraphQL"
BENCHMARK_TARGETS: "BenchmarkStartRequestSpan|BenchmarkHttpServeTrace|BenchmarkTracerAddSpans|BenchmarkStartSpan|BenchmarkSingleSpanRetention|BenchmarkOTelApiWithCustomTags|BenchmarkInjectW3C|BenchmarkExtractW3C|BenchmarkPartialFlushing|BenchmarkGraphQL|BenchmarkSampleWAFContext|BenchmarkCaptureStackTrace"

include:
- ".gitlab/benchmarks.yml"
Expand Down
4 changes: 2 additions & 2 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ go.mod
go.sum

# tracing
/contrib @DataDog/apm-go
/contrib @DataDog/apm-go @Datadog/apm-idm-go
/ddtrace @DataDog/apm-go

# profiling
Expand All @@ -30,4 +30,4 @@ go.sum

# Gitlab configuration
.gitlab-ci.yml @DataDog/dd-trace-go-guild @DataDog/apm-core-reliability-and-performance
/.gitlab-ci @DataDog/dd-trace-go-guild @DataDog/apm-core-reliability-and-performance
/.gitlab-ci @DataDog/dd-trace-go-guild @DataDog/apm-core-reliability-and-performance
6 changes: 4 additions & 2 deletions contrib/database/sql/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,16 @@ func Example_dbmPropagation() {
}

func Example_dbStats() {
sqltrace.Register("postgres", &pq.Driver{})
// Register the driver with the WithDBStats option to enable DBStats metric polling
sqltrace.Register("postgres", &pq.Driver{}, sqltrace.WithDBStats())
// Followed by a call to Open.
db, err := sqltrace.Open("postgres", "postgres://pqgotest:password@localhost/pqgotest?sslmode=disable")

if err != nil {
log.Fatal(err)
}

// Tracing is now enabled. Continue to use the database/sql package as usual
// Tracing and metric polling is now enabled. Metrics will be submitted to Datadog with the prefix `datadog.tracer.sql`
rows, err := db.Query("SELECT name FROM users WHERE age=?", 27)
if err != nil {
log.Fatal(err)
Expand Down
66 changes: 66 additions & 0 deletions contrib/database/sql/metrics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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.

package sql

import (
"testing"

"github.com/stretchr/testify/assert"
"gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig"
)

func (cfg *config) applyTags() {
cfg.serviceName = "my-svc"
cfg.tags = make(map[string]interface{})
cfg.tags["tag"] = "value"
}

func setGlobalCfgTags() {
globalconfig.SetStatsTags([]string{"globaltag:globalvalue"})
}

func resetGlobalConfig() {
globalconfig.SetStatsTags([]string{})
}

// Test that statsTags(*config) returns tags from the provided *config + whatever is on the globalconfig
func TestStatsTags(t *testing.T) {
t.Run("default none", func(t *testing.T) {
resetGlobalConfig()
cfg := new(config)
tags := statsTags(cfg)
assert.Len(t, tags, 0)
})
t.Run("cfg only", func(t *testing.T) {
resetGlobalConfig()
cfg := new(config)
cfg.applyTags()
tags := statsTags(cfg)
assert.Len(t, tags, 2)
assert.Contains(t, tags, "service:my-svc")
assert.Contains(t, tags, "tag:value")
})
t.Run("inherit globalconfig", func(t *testing.T) {
resetGlobalConfig()
cfg := new(config)
setGlobalCfgTags()
tags := statsTags(cfg)
assert.Len(t, tags, 1)
assert.Contains(t, tags, "globaltag:globalvalue")
})
t.Run("both", func(t *testing.T) {
resetGlobalConfig()
cfg := new(config)
cfg.applyTags()
setGlobalCfgTags()
tags := statsTags(cfg)
assert.Len(t, tags, 3)
assert.Contains(t, tags, "globaltag:globalvalue")
assert.Contains(t, tags, "service:my-svc")
assert.Contains(t, tags, "tag:value")
})
resetGlobalConfig()
}
9 changes: 9 additions & 0 deletions contrib/database/sql/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,12 @@ func WithSQLCommentInjection(mode tracer.SQLCommentInjectionMode) Option {
func WithDBMPropagation(mode tracer.DBMPropagationMode) Option {
return v2.WithDBMPropagation(v2tracer.DBMPropagationMode(mode))
}

// WithDBStats enables polling of DBStats metrics
// ref: https://pkg.go.dev/database/sql#DBStats
// These metrics are submitted to Datadog and are not billed as custom metrics
func WithDBStats() Option {
return func(cfg *config) {
cfg.dbStats = true
}
}
16 changes: 16 additions & 0 deletions contrib/dimfeld/httptreemux.v5/httptreemux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
package httptreemux // import "gopkg.in/DataDog/dd-trace-go.v1/contrib/dimfeld/httptreemux.v5"

import (
"net/http"

v2 "github.com/DataDog/dd-trace-go/v2/contrib/dimfeld/httptreemux.v5"
"github.com/dimfeld/httptreemux/v5"
)

// Router is a traced version of httptreemux.TreeMux.
Expand All @@ -27,3 +30,16 @@ type ContextRouter = v2.ContextRouter
func NewWithContext(opts ...RouterOption) *ContextRouter {
return v2.NewWithContext(opts...)
}

// isSupportedRedirectStatus checks if the given HTTP status code is a supported redirect status.
func isSupportedRedirectStatus(status int) bool {
return status == http.StatusMovedPermanently ||
status == http.StatusTemporaryRedirect ||
status == http.StatusPermanentRedirect
}

// routerRedirectEnabled checks if the redirection is enabled on the router.
func routerRedirectEnabled(router *httptreemux.TreeMux) bool {
return (router.RedirectCleanPath || router.RedirectTrailingSlash) &&
router.RedirectBehavior != httptreemux.UseHandler
}
Loading

0 comments on commit 7ba4a8b

Please sign in to comment.