Skip to content

Commit

Permalink
Merge branch 'main' into check-response-handler-result-nil
Browse files Browse the repository at this point in the history
  • Loading branch information
darccio authored Aug 23, 2024
2 parents a5403b4 + 6f8d5e9 commit 7721574
Show file tree
Hide file tree
Showing 46 changed files with 1,251 additions and 1,151 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
run: govulncheck ./ddtrace/... ./appsec/... ./profiler/... ./internal/...
- name: Run govulncheck-contribs
run: |
# Excluding legacy contrib grpc.v12
go list -f '{{.Dir}}' ./contrib/... | grep -v -e grpc.v12 | while read dir ; do
go list -f '{{.Dir}}' ./contrib/... | while read dir ; do
govulncheck -C $dir .
done
2 changes: 1 addition & 1 deletion .github/workflows/multios-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: "Runner ${{ matrix.runner-index }}: Test Core and Contrib (No Integration Tests)"
shell: bash
run: |
go list ./... | grep -v -e grpc.v12 -e google.golang.org/api -e sarama -e confluent-kafka-go -e cmemprof | sort >packages.txt
go list ./... | grep -v -e google.golang.org/api -e sarama -e confluent-kafka-go -e cmemprof | sort >packages.txt
gotestsum --junitfile ${REPORT} -- $(cat packages.txt) -v -coverprofile=coverage.txt -covermode=atomic -timeout 15m
- name: Upload the results to Datadog CI App
if: always()
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/orchestrion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Orchestrion
on:
workflow_dispatch: # manually
pull_request:
merge_group:
push:
branches:
- release-v*

permissions: read-all

concurrency:
# Automatically cancel previous runs if a new one is triggered to conserve resources.
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: 'Run Tests'
uses: DataDog/orchestrion/.github/workflows/[email protected]/APPSEC-53773 # we don't want to pin our own action
with:
dd-trace-go-ref: ${{ github.sha }}
runs-on: ubuntu-latest-16-cores
31 changes: 4 additions & 27 deletions .github/workflows/unit-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ jobs:
image: cassandra:3.11
env:
JVM_OPTS: "-Xms750m -Xmx750m"
CASSANDRA_CLUSTER_NAME: "dd-trace-go-test-cluster"
CASSANDRA_DC: "dd-trace-go-test-datacenter"
CASSANDRA_ENDPOINT_SNITCH: "GossipingPropertyFileSnitch"
ports:
- 9042:9042
mysql:
Expand Down Expand Up @@ -194,7 +197,7 @@ jobs:
- name: Test Contrib
run: |
mkdir -p $TEST_RESULTS
PACKAGE_NAMES=$(go list ./contrib/... | grep -v -e grpc.v12 -e google.golang.org/api)
PACKAGE_NAMES=$(go list ./contrib/... | grep -v -e google.golang.org/api)
gotestsum --junitfile ${TEST_RESULTS}/gotestsum-report.xml -- $PACKAGE_NAMES -v -race -coverprofile=coverage.txt -covermode=atomic
- name: Upload the results to Datadog CI App
Expand Down Expand Up @@ -246,32 +249,6 @@ jobs:
go mod tidy # Go1.16 doesn't update the sum file correctly after the go get, this tidy fixes it
go test -v ./contrib/google.golang.org/api/...
- 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].
# [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 ../../..
# Checkout [email protected]
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.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/...
test-core:
runs-on:
group: "APM Larger Runners"
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ go.work*
dd-trace-go.iml
vendor

/contrib/google.golang.org/grpc.v12/vendor/
/contrib_coverage.txt
/core_coverage.txt
/gotestsum-report.xml
4 changes: 1 addition & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
run:
deadline: 10m
skip-dirs:
# This package is an exception and has its own test job (Testing outlier gRPC v1.2).
- contrib/google.golang.org/grpc.v12

linters:
disable-all: true
enable:
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ Before considering contributions to the project, please take a moment to read ou

### Testing

Tests can be run locally using the Go toolset. The grpc.v12 integration will fail (and this is normal), because it covers for deprecated methods. In the CI environment
we vendor this version of the library inside the integration. Under normal circumstances this is not something that we want to do, because users using this integration
might be running versions different from the vendored one, creating hard to debug conflicts.
Tests can be run locally using the Go toolset.

To run integration tests locally, you should set the `INTEGRATION` environment variable. The dependencies of the integration tests are best run via Docker. To get an
idea about the versions and the set-up take a look at our [docker-compose config](./docker-compose.yaml).
Expand Down
67 changes: 65 additions & 2 deletions contrib/gocql/gocql/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ package gocql_test

import (
"context"
"log"

"github.com/gocql/gocql"

gocqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gocql/gocql"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

func Example() {
func ExampleNewCluster() {
// Initialise a wrapped Cassandra session and create a query.
cluster := gocqltrace.NewCluster([]string{"127.0.0.1"}, gocqltrace.WithServiceName("ServiceName"))
cluster := gocqltrace.NewCluster([]string{"127.0.0.1:9043"}, gocqltrace.WithServiceName("ServiceName"))
session, _ := cluster.CreateSession()
query := session.Query("CREATE KEYSPACE if not exists trace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor': 1}")

Expand All @@ -34,3 +37,63 @@ func Example() {
// Execute your query as usual
query.Exec()
}

func ExampleCreateTracedSession() {
cluster := gocql.NewCluster("127.0.0.1:9042")
cluster.Keyspace = "my-keyspace"

// Create a new traced session using any number of options
session, err := gocqltrace.CreateTracedSession(cluster, gocqltrace.WithServiceName("ServiceName"))
if err != nil {
log.Fatal(err)
}
query := session.Query("CREATE KEYSPACE if not exists trace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor': 1}")

// Use context to pass information down the call chain
_, ctx := tracer.StartSpanFromContext(context.Background(), "parent.request",
tracer.SpanType(ext.SpanTypeCassandra),
tracer.ServiceName("web"),
tracer.ResourceName("/home"),
)
query.WithContext(ctx)

// If you don't want a concrete query to be traced, you can do query.Observer(nil)

// Finally, execute the query
if err := query.Exec(); err != nil {
log.Fatal(err)
}
}

func ExampleNewObserver() {
cluster := gocql.NewCluster("127.0.0.1:9042")
cluster.Keyspace = "my-keyspace"

// Create a new regular gocql session
session, err := cluster.CreateSession()
if err != nil {
log.Fatal(err)
}
// Create a new observer using same set of options as gocqltrace.CreateTracedSession.
obs := gocqltrace.NewObserver(cluster, gocqltrace.WithServiceName("ServiceName"))

// Attach the observer to queries / batches individually.
tracedQuery := session.Query("SELECT something FROM somewhere").Observer(obs)
untracedQuery := session.Query("SELECT something FROM somewhere")

// Use context to pass information down the call chain
_, ctx := tracer.StartSpanFromContext(context.Background(), "parent.request",
tracer.SpanType(ext.SpanTypeCassandra),
tracer.ServiceName("web"),
tracer.ResourceName("/home"),
)
tracedQuery.WithContext(ctx)

// Finally, execute the query
if err := tracedQuery.Exec(); err != nil {
log.Fatal(err)
}
if err := untracedQuery.Exec(); err != nil {
log.Fatal(err)
}
}
Loading

0 comments on commit 7721574

Please sign in to comment.