From b498bd9cb0f000cce3cbd2fc3cc91e0aad36956f Mon Sep 17 00:00:00 2001 From: wconti27 Date: Fri, 8 Sep 2023 14:01:44 -0400 Subject: [PATCH] Revert "Conti/implement test agent interface client integrations (#2110)" This reverts commit b417ae359c28d581f4c973f040083dbfa20c1b72. --- .../contrib/database/sql/integration.go | 77 -------- .../contrib/garyburd/redigo/integration.go | 84 --------- .../contrib/globalsign/mgo/integration.go | 74 -------- .../contrib/go-pg/pg.v10/integration.go | 77 -------- .../contrib/go-redis/redis.v7/integration.go | 72 -------- .../contrib/go-redis/redis.v8/integration.go | 70 ------- .../contrib/go-redis/redis/integration.go | 72 -------- .../mongo-driver/mongo/integration.go | 82 --------- .../contrib/gocql/gocql/integration.go | 84 --------- .../contrib/gomodule/redigo/integration.go | 77 -------- .../gopkg.in/jinzhu/gorm.v1/integration.go | 75 -------- .../contrib/gorm.io/gorm.v1/integration.go | 80 -------- .../contrib/jinzhu/gorm/integration.go | 75 -------- .../contrib/jmoiron/sqlx/integration.go | 79 -------- .../contrib/redis/go-redis.v9/integration.go | 70 ------- .../contrib/shared/gorm/integration.go | 83 --------- .../contrib/shared/sql/integration.go | 173 ------------------ .../syndtr/goleveldb/leveldb/integration.go | 84 --------- .../contrib/tidwall/buntdb/integration.go | 107 ----------- .../validationtest/validation_test.go | 34 ---- 20 files changed, 1629 deletions(-) delete mode 100644 contrib/internal/validationtest/contrib/database/sql/integration.go delete mode 100644 contrib/internal/validationtest/contrib/garyburd/redigo/integration.go delete mode 100644 contrib/internal/validationtest/contrib/globalsign/mgo/integration.go delete mode 100644 contrib/internal/validationtest/contrib/go-pg/pg.v10/integration.go delete mode 100644 contrib/internal/validationtest/contrib/go-redis/redis.v7/integration.go delete mode 100644 contrib/internal/validationtest/contrib/go-redis/redis.v8/integration.go delete mode 100644 contrib/internal/validationtest/contrib/go-redis/redis/integration.go delete mode 100644 contrib/internal/validationtest/contrib/go.mongodb.org/mongo-driver/mongo/integration.go delete mode 100644 contrib/internal/validationtest/contrib/gocql/gocql/integration.go delete mode 100644 contrib/internal/validationtest/contrib/gomodule/redigo/integration.go delete mode 100644 contrib/internal/validationtest/contrib/gopkg.in/jinzhu/gorm.v1/integration.go delete mode 100644 contrib/internal/validationtest/contrib/gorm.io/gorm.v1/integration.go delete mode 100644 contrib/internal/validationtest/contrib/jinzhu/gorm/integration.go delete mode 100644 contrib/internal/validationtest/contrib/jmoiron/sqlx/integration.go delete mode 100644 contrib/internal/validationtest/contrib/redis/go-redis.v9/integration.go delete mode 100644 contrib/internal/validationtest/contrib/shared/gorm/integration.go delete mode 100644 contrib/internal/validationtest/contrib/shared/sql/integration.go delete mode 100644 contrib/internal/validationtest/contrib/syndtr/goleveldb/leveldb/integration.go delete mode 100644 contrib/internal/validationtest/contrib/tidwall/buntdb/integration.go diff --git a/contrib/internal/validationtest/contrib/database/sql/integration.go b/contrib/internal/validationtest/contrib/database/sql/integration.go deleted file mode 100644 index 15dc80ccc9..0000000000 --- a/contrib/internal/validationtest/contrib/database/sql/integration.go +++ /dev/null @@ -1,77 +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 2023 Datadog, Inc. - -package sql - -import ( - "database/sql" - "database/sql/driver" - "testing" - - sqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql" - gormtest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/shared/gorm" - sqltest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/shared/sql" - - _ "github.com/lib/pq" // need pg package for sql tests - "github.com/stretchr/testify/require" - "gorm.io/gorm" -) - -type Integration struct { - numSpans int - opts []sqltrace.Option -} - -func New() *Integration { - return &Integration{ - opts: make([]sqltrace.Option, 0), - } -} - -func (i *Integration) Name() string { - return "database/sql" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - opts = i.opts - closeFunc := sqltest.Prepare(t, gormtest.TableName) - t.Cleanup(func() { - closeFunc() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - operationToNumSpans := map[string]int{ - "Connect": 2, - "Ping": 2, - "Query": 2, - "Statement": 7, - "BeginRollback": 3, - "Exec": 5, - } - i.numSpans += gormtest.RunAll(t, operationToNumSpans, registerFunc, getDB) -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, sqltrace.WithServiceName(name)) -} - -var opts []sqltrace.Option - -func registerFunc(driverName string, driver driver.Driver) { - sqltrace.Register(driverName, driver, opts...) -} - -func getDB(t *testing.T, driverName string, connString string, _ func(*sql.DB) gorm.Dialector) *sql.DB { - db, err := sqltrace.Open(driverName, connString, opts...) - require.NoError(t, err) - return db -} diff --git a/contrib/internal/validationtest/contrib/garyburd/redigo/integration.go b/contrib/internal/validationtest/contrib/garyburd/redigo/integration.go deleted file mode 100644 index 18b03647d3..0000000000 --- a/contrib/internal/validationtest/contrib/garyburd/redigo/integration.go +++ /dev/null @@ -1,84 +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 2023 Datadog, Inc. - -package redigo - -import ( - "context" - "testing" - - redigotrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/garyburd/redigo" - - "github.com/garyburd/redigo/redis" - "github.com/stretchr/testify/require" -) - -type Integration struct { - client redis.Conn - numSpans int - opts []redigotrace.DialOption -} - -func New() *Integration { - return &Integration{ - opts: make([]redigotrace.DialOption, 0), - } -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, redigotrace.WithServiceName(name)) -} - -func (i *Integration) Name() string { - return "garyburd/redigo" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - var opt redigotrace.DialOption - if len(i.opts) > 0 { - opt = i.opts[0] - } - client, err := redigotrace.Dial("tcp", "127.0.0.1:6379", opt) - i.client = client - require.NoError(t, err) - - t.Cleanup(func() { - i.client.Close() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - t.Helper() - - i.client.Do("SET", 1, "truck") - i.numSpans++ - - _, err := i.client.Do("NOT_A_COMMAND", context.Background()) - require.Error(t, err) - i.numSpans++ - var opt redigotrace.DialOption - if len(i.opts) > 0 { - opt = i.opts[0] - } - pool := &redis.Pool{ - MaxIdle: 2, - MaxActive: 3, - IdleTimeout: 23, - Wait: true, - Dial: func() (redis.Conn, error) { - return redigotrace.Dial("tcp", "127.0.0.1:6379", opt) - }, - } - - pc := pool.Get() - pc.Do("SET", " whiskey", " glass", context.Background()) - i.numSpans++ -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} diff --git a/contrib/internal/validationtest/contrib/globalsign/mgo/integration.go b/contrib/internal/validationtest/contrib/globalsign/mgo/integration.go deleted file mode 100644 index 55d1727b5d..0000000000 --- a/contrib/internal/validationtest/contrib/globalsign/mgo/integration.go +++ /dev/null @@ -1,74 +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 2023 Datadog, Inc. - -package mgo - -import ( - "testing" - - mgotrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/globalsign/mgo" - - "github.com/globalsign/mgo/bson" - "github.com/stretchr/testify/require" -) - -type Integration struct { - collection *mgotrace.Collection - numSpans int - opts []mgotrace.DialOption -} - -func New() *Integration { - return &Integration{ - opts: make([]mgotrace.DialOption, 0), - } -} - -func (i *Integration) Name() string { - return "globalsign/mgo" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - // connect to MongoDB - session, err := mgotrace.Dial("localhost:27017", i.opts...) - require.NoError(t, err) - - db := session.DB("my_db") - i.collection = db.C("MyCollection") - - t.Cleanup(func() { - session.Close() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - t.Helper() - - i.collection.Insert(entity) - i.numSpans++ - - i.collection.Update(entity, entity) - i.numSpans++ - - i.collection.Remove(entity) - i.numSpans++ -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, mgotrace.WithServiceName(name)) -} - -var entity = bson.D{ - bson.DocElem{ - Name: "entity_new", - Value: bson.DocElem{ - Name: "index", - Value: 0}}} diff --git a/contrib/internal/validationtest/contrib/go-pg/pg.v10/integration.go b/contrib/internal/validationtest/contrib/go-pg/pg.v10/integration.go deleted file mode 100644 index c05ba580ca..0000000000 --- a/contrib/internal/validationtest/contrib/go-pg/pg.v10/integration.go +++ /dev/null @@ -1,77 +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 2023 Datadog, Inc. - -package pg - -import ( - "testing" - - pgtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-pg/pg.v10" - - "github.com/go-pg/pg/v10" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -type Integration struct { - conn *pg.DB - numSpans int - opts []pgtrace.Option -} - -func New() *Integration { - return &Integration{ - opts: make([]pgtrace.Option, 0), - } -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, pgtrace.WithServiceName(name)) -} - -func (i *Integration) Name() string { - return "go-pg/pg.v10" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - i.conn = pg.Connect(&pg.Options{ - User: "postgres", - Password: "postgres", - Database: "postgres", - }) - - // Wrap the connection with the APM hook. - pgtrace.Wrap(i.conn, i.opts...) - var n int - _, err := i.conn.QueryOne(pg.Scan(&n), "SELECT 1") - require.NoError(t, err) - i.numSpans++ - - t.Cleanup(func() { - i.conn.Close() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - t.Helper() - - var n int - res, err := i.conn.QueryOne(pg.Scan(&n), "SELECT 1") - require.NoError(t, err) - assert.Equal(t, 1, res.RowsAffected()) - i.numSpans++ - - var x int - _, err = i.conn.QueryOne(pg.Scan(&x), "SELECT 2") - require.NoError(t, err) - assert.Equal(t, 1, res.RowsAffected()) - i.numSpans++ -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} diff --git a/contrib/internal/validationtest/contrib/go-redis/redis.v7/integration.go b/contrib/internal/validationtest/contrib/go-redis/redis.v7/integration.go deleted file mode 100644 index ff1e33856c..0000000000 --- a/contrib/internal/validationtest/contrib/go-redis/redis.v7/integration.go +++ /dev/null @@ -1,72 +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 2023 Datadog, Inc. - -package redis - -import ( - "context" - "testing" - "time" - - redistrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-redis/redis.v7" - - "github.com/go-redis/redis/v7" -) - -type Integration struct { - client *redis.Client - numSpans int - opts []redistrace.ClientOption -} - -func New() *Integration { - return &Integration{ - opts: make([]redistrace.ClientOption, 0), - } -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, redistrace.WithServiceName(name)) -} - -func (i *Integration) Name() string { - return "go-redis/redis.v7" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - opts := &redis.Options{Addr: "127.0.0.1:6379"} - - i.client = redistrace.NewClient(opts, i.opts...) - - i.client.Set("test_key", "test_value", 0) - i.numSpans++ - - t.Cleanup(func() { - i.client.Close() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - t.Helper() - - i.client.Set("test_key", "test_value", 0) - i.client.Get("test_key") - i.client.Incr("int_key") - i.client.ClientList() - i.numSpans += 4 - - pipeline := i.client.Pipeline() - pipeline.Expire("pipeline_counter", time.Hour) - - // Exec with context test - pipeline.ExecContext(context.Background()) - i.numSpans++ -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} diff --git a/contrib/internal/validationtest/contrib/go-redis/redis.v8/integration.go b/contrib/internal/validationtest/contrib/go-redis/redis.v8/integration.go deleted file mode 100644 index 98aaadad76..0000000000 --- a/contrib/internal/validationtest/contrib/go-redis/redis.v8/integration.go +++ /dev/null @@ -1,70 +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 2023 Datadog, Inc. - -package redis - -import ( - "context" - "testing" - "time" - - redistrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-redis/redis.v8" - - "github.com/go-redis/redis/v8" -) - -type Integration struct { - client redis.UniversalClient - numSpans int - opts []redistrace.ClientOption -} - -func New() *Integration { - return &Integration{ - opts: make([]redistrace.ClientOption, 0), - } -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, redistrace.WithServiceName(name)) -} - -func (i *Integration) Name() string { - return "go-redis/redis.v8" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - opts := &redis.Options{Addr: "127.0.0.1:6379"} - - i.client = redistrace.NewClient(opts, i.opts...) - - t.Cleanup(func() { - i.client.Close() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - t.Helper() - ctx := context.Background() - - i.client.Set(ctx, "test_key", "test_value", 0) - i.client.Get(ctx, "test_key") - i.client.Incr(ctx, "int_key") - i.client.ClientList(ctx) - i.numSpans += 4 - - pipeline := i.client.Pipeline() - pipeline.Expire(ctx, "pipeline_counter", time.Hour) - - // Exec with context test - pipeline.Exec(ctx) - i.numSpans++ -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} diff --git a/contrib/internal/validationtest/contrib/go-redis/redis/integration.go b/contrib/internal/validationtest/contrib/go-redis/redis/integration.go deleted file mode 100644 index 8aeacf5023..0000000000 --- a/contrib/internal/validationtest/contrib/go-redis/redis/integration.go +++ /dev/null @@ -1,72 +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 2023 Datadog, Inc. - -package redis - -import ( - "context" - "testing" - "time" - - redistrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-redis/redis" - - "github.com/go-redis/redis" -) - -type Integration struct { - client *redistrace.Client - numSpans int - opts []redistrace.ClientOption -} - -func New() *Integration { - return &Integration{ - opts: make([]redistrace.ClientOption, 0), - } -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, redistrace.WithServiceName(name)) -} - -func (i *Integration) Name() string { - return "go-redis/redis" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - opts := &redis.Options{Addr: "127.0.0.1:6379"} - - i.client = redistrace.NewClient(opts, i.opts...) - i.client.Set("test_key", "test_value", 0) - i.numSpans++ - - t.Cleanup(func() { - i.client.Close() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - t.Helper() - - i.client.Set("test_key", "test_value", 0) - i.client.Get("test_key") - i.client.Incr("int_key") - i.client.ClientList() - i.numSpans += 4 - - pipeline := i.client.Pipeline() - pipeline.Expire("pipeline_counter", time.Hour) - - // Exec with context test - pipeline.(*redistrace.Pipeliner).ExecWithContext(context.Background()) - i.numSpans++ - -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} diff --git a/contrib/internal/validationtest/contrib/go.mongodb.org/mongo-driver/mongo/integration.go b/contrib/internal/validationtest/contrib/go.mongodb.org/mongo-driver/mongo/integration.go deleted file mode 100644 index 31d7521ad8..0000000000 --- a/contrib/internal/validationtest/contrib/go.mongodb.org/mongo-driver/mongo/integration.go +++ /dev/null @@ -1,82 +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 2023 Datadog, Inc. - -package mongo - -import ( - "context" - "testing" - - mongotrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go.mongodb.org/mongo-driver/mongo" - - "github.com/stretchr/testify/require" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" -) - -type Integration struct { - client *mongo.Client - numSpans int - opts []mongotrace.Option -} - -func New() *Integration { - return &Integration{ - opts: make([]mongotrace.Option, 0), - } -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, mongotrace.WithServiceName(name)) -} - -func (i *Integration) Name() string { - return "go.mongodb.org/mongo-driver/mongo" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - // connect to MongoDB - opts := options.Client() - opts.Monitor = mongotrace.NewMonitor(i.opts...) - opts.ApplyURI("mongodb://localhost:27017") - var err error - i.client, err = mongo.Connect(context.Background(), opts) - require.NoError(t, err) - db := i.client.Database("example") - inventory := db.Collection("inventory") - - inventory.InsertOne(context.Background(), bson.D{ - {Key: "item", Value: "canvas"}, - {Key: "qty", Value: 100}, - {Key: "tags", Value: bson.A{"cotton"}}, - {Key: "size", Value: bson.D{ - {Key: "h", Value: 28}, - {Key: "w", Value: 35.5}, - {Key: "uom", Value: "cm"}, - }}, - }) - i.numSpans++ - - t.Cleanup(func() { - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - t.Helper() - _, err := i.client. - Database("test-database"). - Collection("test-collection"). - InsertOne(context.Background(), bson.D{{Key: "test-item", Value: "test-value"}}) - - require.NoError(t, err) - i.numSpans++ -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} diff --git a/contrib/internal/validationtest/contrib/gocql/gocql/integration.go b/contrib/internal/validationtest/contrib/gocql/gocql/integration.go deleted file mode 100644 index 2f764bb735..0000000000 --- a/contrib/internal/validationtest/contrib/gocql/gocql/integration.go +++ /dev/null @@ -1,84 +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 2023 Datadog, Inc. - -package gocql - -import ( - "testing" - "time" - - gocqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gocql/gocql" - - "github.com/gocql/gocql" - "github.com/stretchr/testify/require" -) - -type Integration struct { - cluster *gocql.ClusterConfig - session *gocql.Session - numSpans int - opts []gocqltrace.WrapOption -} - -func New() *Integration { - return &Integration{ - opts: make([]gocqltrace.WrapOption, 0), - } -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, gocqltrace.WithServiceName(name)) -} - -func (i *Integration) Name() string { - return "gocql/gocql" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - // connect to cluster - i.cluster = gocql.NewCluster("127.0.0.1:9042") - i.cluster.DisableInitialHostLookup = true - // the default timeouts (600ms) are sometimes too short in CI and cause - // PRs being tested to flake due to this integration. - i.cluster.ConnectTimeout = 2 * time.Second - i.cluster.Timeout = 2 * time.Second - var err error - i.session, err = i.cluster.CreateSession() - require.NoError(t, err) - - i.session.Query("CREATE KEYSPACE if not exists trace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor': 1}").Exec() - i.session.Query("CREATE TABLE if not exists trace.person (name text PRIMARY KEY, age int, description text)").Exec() - i.session.Query("INSERT INTO trace.person (name, age, description) VALUES ('Cassandra', 100, 'A cruel mistress')").Exec() - - t.Cleanup(func() { - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - t.Helper() - q := i.session.Query("SELECT * from trace.person") - gocqltrace.WrapQuery(q, i.opts...).Exec() - q2 := i.session.Query("SELECT * from trace.person") - gocqltrace.WrapQuery(q2, i.opts...).Exec() - q3 := i.session.Query("SELECT * from trace.person") - gocqltrace.WrapQuery(q3, i.opts...).Exec() - i.numSpans += 3 - - b := i.session.NewBatch(gocql.UnloggedBatch) - tb := gocqltrace.WrapBatch(b, i.opts...) - - stmt := "INSERT INTO trace.person (name, age, description) VALUES (?, ?, ?)" - tb.Query(stmt, "Kate", 80, "Cassandra's sister running in kubernetes") - tb.Query(stmt, "Lucas", 60, "Another person") - err := tb.WithTimestamp(time.Now().Unix() * 1e3).ExecuteBatch(i.session) - require.NoError(t, err) - i.numSpans++ -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} diff --git a/contrib/internal/validationtest/contrib/gomodule/redigo/integration.go b/contrib/internal/validationtest/contrib/gomodule/redigo/integration.go deleted file mode 100644 index 749b10da79..0000000000 --- a/contrib/internal/validationtest/contrib/gomodule/redigo/integration.go +++ /dev/null @@ -1,77 +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 2023 Datadog, Inc. - -package redigo - -import ( - "context" - "testing" - - redigotrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gomodule/redigo" - - "github.com/gomodule/redigo/redis" - "github.com/stretchr/testify/require" -) - -type Integration struct { - client redis.Conn - numSpans int - opts []redigotrace.DialOption -} - -func New() *Integration { - return &Integration{ - opts: make([]redigotrace.DialOption, 0), - } -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, redigotrace.WithServiceName(name)) -} - -func (i *Integration) Name() string { - return "garyburd/redigo" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - client, err := redigotrace.Dial("tcp", "127.0.0.1:6379", i.opts) - i.client = client - require.NoError(t, err) - - t.Cleanup(func() { - i.client.Close() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - t.Helper() - - i.client.Do("SET", 1, "truck") - i.numSpans++ - - _, err := i.client.Do("NOT_A_COMMAND", context.Background()) - require.Error(t, err) - i.numSpans++ - - pool := &redis.Pool{ - MaxIdle: 2, - MaxActive: 3, - IdleTimeout: 23, - Wait: true, - Dial: func() (redis.Conn, error) { - return redigotrace.Dial("tcp", "127.0.0.1:6379") - }, - } - - pc := pool.Get() - pc.Do("SET", " whiskey", " glass", context.Background()) - i.numSpans++ -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} diff --git a/contrib/internal/validationtest/contrib/gopkg.in/jinzhu/gorm.v1/integration.go b/contrib/internal/validationtest/contrib/gopkg.in/jinzhu/gorm.v1/integration.go deleted file mode 100644 index 4bab4575a1..0000000000 --- a/contrib/internal/validationtest/contrib/gopkg.in/jinzhu/gorm.v1/integration.go +++ /dev/null @@ -1,75 +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 2023 Datadog, Inc. - -package gorm - -import ( - "database/sql" - "database/sql/driver" - "testing" - - sqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql" - gormtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gopkg.in/jinzhu/gorm.v1" - gormtest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/shared/gorm" - sqltest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/shared/sql" - - _ "github.com/lib/pq" // need pg package for sql tests - "github.com/stretchr/testify/require" - "gorm.io/gorm" -) - -type Integration struct { - numSpans int - opts []gormtrace.Option -} - -func New() *Integration { - return &Integration{ - opts: make([]gormtrace.Option, 0), - } -} - -func (i *Integration) Name() string { - return "gopkg.in/jinzhu/gorm.v1" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - closeFunc := sqltest.Prepare(t, gormtest.TableName) - t.Cleanup(func() { - closeFunc() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - operationToNumSpans := map[string]int{ - "Connect": 4, - "Ping": 2, - "Query": 2, - "Statement": 7, - "BeginRollback": 3, - "Exec": 5, - } - i.numSpans += gormtest.RunAll(t, operationToNumSpans, registerFunc, getDB) -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} - -func registerFunc(driverName string, driver driver.Driver) { - sqltrace.Register(driverName, driver) -} - -func getDB(t *testing.T, driverName string, connString string, _ func(*sql.DB) gorm.Dialector) *sql.DB { - db, err := gormtrace.Open(driverName, connString) - require.NoError(t, err) - return db.DB() -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, gormtrace.WithServiceName(name)) -} diff --git a/contrib/internal/validationtest/contrib/gorm.io/gorm.v1/integration.go b/contrib/internal/validationtest/contrib/gorm.io/gorm.v1/integration.go deleted file mode 100644 index 5090e187cb..0000000000 --- a/contrib/internal/validationtest/contrib/gorm.io/gorm.v1/integration.go +++ /dev/null @@ -1,80 +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 2023 Datadog, Inc. - -package gorm - -import ( - "database/sql" - "database/sql/driver" - "testing" - - sqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql" - gormtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gorm.io/gorm.v1" - gormtest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/shared/gorm" - sqltest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/shared/sql" - - _ "github.com/lib/pq" // need pg package for sql tests - "github.com/stretchr/testify/require" - "gorm.io/gorm" -) - -type Integration struct { - numSpans int - opts []gormtrace.Option -} - -func New() *Integration { - return &Integration{ - opts: make([]gormtrace.Option, 0), - } -} - -func (i *Integration) Name() string { - return "gopkg.in/jinzhu/gorm.v1" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - closeFunc := sqltest.Prepare(t, gormtest.TableName) - t.Cleanup(func() { - closeFunc() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - operationToNumSpans := map[string]int{ - "Connect": 5, - "Ping": 2, - "Query": 2, - "Statement": 7, - "BeginRollback": 3, - "Exec": 5, - } - i.numSpans += gormtest.RunAll(t, operationToNumSpans, registerFunc, getDB) -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} - -func registerFunc(driverName string, driver driver.Driver) { - sqltrace.Register(driverName, driver) -} - -func getDB(t *testing.T, driverName string, connString string, dialectorFunc func(*sql.DB) gorm.Dialector) *sql.DB { - sqlDb, err := sqltrace.Open(driverName, connString) - require.NoError(t, err) - db, err := gormtrace.Open(dialectorFunc(sqlDb), &gorm.Config{}) - require.NoError(t, err) - - internalDB, err := db.DB() - require.NoError(t, err) - return internalDB -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, gormtrace.WithServiceName(name)) -} diff --git a/contrib/internal/validationtest/contrib/jinzhu/gorm/integration.go b/contrib/internal/validationtest/contrib/jinzhu/gorm/integration.go deleted file mode 100644 index 0c7f877473..0000000000 --- a/contrib/internal/validationtest/contrib/jinzhu/gorm/integration.go +++ /dev/null @@ -1,75 +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 2023 Datadog, Inc. - -package gorm - -import ( - "database/sql" - "database/sql/driver" - "testing" - - sqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql" - gormtest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/shared/gorm" - sqltest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/shared/sql" - gormtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/jinzhu/gorm" - - _ "github.com/lib/pq" // need pg package for sql tests - "github.com/stretchr/testify/require" - "gorm.io/gorm" -) - -type Integration struct { - numSpans int - opts []gormtrace.Option -} - -func New() *Integration { - return &Integration{ - opts: make([]gormtrace.Option, 0), - } -} - -func (i *Integration) Name() string { - return "jinzhu/gorm" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - closeFunc := sqltest.Prepare(t, gormtest.TableName) - t.Cleanup(func() { - closeFunc() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - operationToNumSpans := map[string]int{ - "Connect": 4, - "Ping": 2, - "Query": 2, - "Statement": 7, - "BeginRollback": 3, - "Exec": 5, - } - i.numSpans += gormtest.RunAll(t, operationToNumSpans, registerFunc, getDB) -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} - -func registerFunc(driverName string, driver driver.Driver) { - sqltrace.Register(driverName, driver) -} - -func getDB(t *testing.T, driverName string, connString string, _ func(*sql.DB) gorm.Dialector) *sql.DB { - db, err := gormtrace.Open(driverName, connString) - require.NoError(t, err) - return db.DB() -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, gormtrace.WithServiceName(name)) -} diff --git a/contrib/internal/validationtest/contrib/jmoiron/sqlx/integration.go b/contrib/internal/validationtest/contrib/jmoiron/sqlx/integration.go deleted file mode 100644 index bb040490c6..0000000000 --- a/contrib/internal/validationtest/contrib/jmoiron/sqlx/integration.go +++ /dev/null @@ -1,79 +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 2023 Datadog, Inc. - -package gorm - -import ( - "database/sql" - "database/sql/driver" - "testing" - - sqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql" - gormtest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/shared/gorm" - sqltest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/shared/sql" - sqlxtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/jmoiron/sqlx" - - _ "github.com/lib/pq" // need pg package for sql tests - "github.com/stretchr/testify/require" - "gorm.io/gorm" -) - -type Integration struct { - numSpans int - opts []sqltrace.Option -} - -func New() *Integration { - return &Integration{ - opts: make([]sqltrace.Option, 0), - } -} - -func (i *Integration) Name() string { - return "jmoiron/sqlx" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - opts = i.opts - - closeFunc := sqltest.Prepare(t, gormtest.TableName) - t.Cleanup(func() { - closeFunc() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - operationToNumSpans := map[string]int{ - "Connect": 2, - "Ping": 2, - "Query": 2, - "Statement": 7, - "BeginRollback": 3, - "Exec": 5, - } - i.numSpans += gormtest.RunAll(t, operationToNumSpans, registerFunc, getDB) -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, sqltrace.WithServiceName(name)) -} - -var opts []sqltrace.Option - -func registerFunc(driverName string, driver driver.Driver) { - sqltrace.Register(driverName, driver, opts...) -} - -func getDB(t *testing.T, driverName string, connString string, _ func(*sql.DB) gorm.Dialector) *sql.DB { - db, err := sqlxtrace.Open(driverName, connString, opts...) - require.NoError(t, err) - return db.DB -} diff --git a/contrib/internal/validationtest/contrib/redis/go-redis.v9/integration.go b/contrib/internal/validationtest/contrib/redis/go-redis.v9/integration.go deleted file mode 100644 index 4e39954895..0000000000 --- a/contrib/internal/validationtest/contrib/redis/go-redis.v9/integration.go +++ /dev/null @@ -1,70 +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 2023 Datadog, Inc. - -package redis - -import ( - "context" - "testing" - "time" - - redistrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/redis/go-redis.v9" - - "github.com/redis/go-redis/v9" -) - -type Integration struct { - client redis.UniversalClient - numSpans int - opts []redistrace.ClientOption -} - -func New() *Integration { - return &Integration{ - opts: make([]redistrace.ClientOption, 0), - } -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, redistrace.WithServiceName(name)) -} - -func (i *Integration) Name() string { - return "redis/go-redis.v9" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - - i.client = redistrace.NewClient(&redis.Options{Addr: "127.0.0.1:6379"}, i.opts...) - i.numSpans++ - - t.Cleanup(func() { - i.client.Close() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - t.Helper() - ctx := context.Background() - - i.client.Set(ctx, "test_key", "test_value", 0) - i.client.Get(ctx, "test_key") - i.client.Incr(ctx, "int_key") - i.client.ClientList(ctx) - i.numSpans += 4 - - pipeline := i.client.Pipeline() - pipeline.Expire(ctx, "pipeline_counter", time.Hour) - - // Exec with context test - pipeline.Exec(ctx) - i.numSpans++ -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} diff --git a/contrib/internal/validationtest/contrib/shared/gorm/integration.go b/contrib/internal/validationtest/contrib/shared/gorm/integration.go deleted file mode 100644 index 699fc73044..0000000000 --- a/contrib/internal/validationtest/contrib/shared/gorm/integration.go +++ /dev/null @@ -1,83 +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 2023 Datadog, Inc. - -package gorm - -import ( - "database/sql" - "database/sql/driver" - "testing" - - sqltest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/shared/sql" - - "github.com/jackc/pgx/v5/stdlib" - mysqlgorm "gorm.io/driver/mysql" - "gorm.io/gorm" -) - -// tableName holds the SQL table that these tests will be run against. It must be unique cross-repo. -const ( - TableName = "testgorm" - pgConnString = "postgres://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable" - sqlServerConnString = "sqlserver://sa:myPassw0rd@127.0.0.1:1433?database=master" - mysqlConnString = "test:test@tcp(127.0.0.1:3306)/test" -) - -func RunAll(t *testing.T, operationToNumSpans map[string]int, registerFunc func(string, driver.Driver), getDB func(*testing.T, string, string, func(*sql.DB) gorm.Dialector) *sql.DB) int { - t.Helper() - var numSpans = 0 - - testCases := []struct { - name string - connString string - driverName string - driver driver.Driver - dialectorFunc func(*sql.DB) gorm.Dialector - }{ - { - name: "Postgres", - connString: pgConnString, - driverName: "pgx", - driver: &stdlib.Driver{}, - dialectorFunc: func(sqlDB *sql.DB) gorm.Dialector { return mysqlgorm.New(mysqlgorm.Config{Conn: sqlDB}) }, - }, - // { - // name: "SQLServer", - // connString: sqlServerConnString, - // driverName: "sqlserver", - // driver: &mssql.Driver{}, - // dialectorFunc: func(sqlDB *sql.DB) gorm.Dialector { return sqlserver.New(sqlserver.Config{Conn: sqlDB}) }, - // }, - // { - // name: "MySQL", - // connString: mysqlConnString, - // driverName: "mysql", - // driver: &mysql.MySQLDriver{}, - // dialectorFunc: func(sqlDB *sql.DB) gorm.Dialector { return postgres.New(postgres.Config{Conn: sqlDB}) }, - // }, - } - - for _, testCase := range testCases { - t.Run(testCase.name, func(t *testing.T) { - registerFunc(testCase.driverName, testCase.driver) - - internalDB := getDB(t, testCase.driverName, testCase.connString, testCase.dialectorFunc) - - operationToNumSpansCopy := make(map[string]int) - for k, v := range operationToNumSpans { - operationToNumSpansCopy[k] = v - } - - testConfig := &sqltest.Config{ - DB: internalDB, - OperationToNumSpans: operationToNumSpansCopy, - DriverName: testCase.driverName, - TableName: TableName, - } - numSpans += sqltest.RunAll(t, testConfig) - }) - } - return numSpans -} diff --git a/contrib/internal/validationtest/contrib/shared/sql/integration.go b/contrib/internal/validationtest/contrib/shared/sql/integration.go deleted file mode 100644 index cd13dd400f..0000000000 --- a/contrib/internal/validationtest/contrib/shared/sql/integration.go +++ /dev/null @@ -1,173 +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 2023 Datadog, Inc. - -package sqltest // import "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/sqltest" - -import ( - "context" - "database/sql" - "fmt" - "testing" - - "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" - - "github.com/stretchr/testify/require" -) - -type Integration struct { - NumSpans int -} - -// Prepare sets up a table with the given name in both the MySQL and Postgres databases and returns -// a teardown function which will drop it. -func Prepare(t *testing.T, tableName string) func() { - queryDrop := fmt.Sprintf("DROP TABLE IF EXISTS %s", tableName) - queryCreate := fmt.Sprintf("CREATE TABLE %s (id integer NOT NULL DEFAULT '0', name text)", tableName) - - mysql, err := sql.Open("mysql", "test:test@tcp(127.0.0.1:3306)/test") - require.NoError(t, err) - mysql.Exec(queryDrop) - mysql.Exec(queryCreate) - - postgres, err := sql.Open("postgres", "postgres://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable") - require.NoError(t, err) - postgres.Exec(queryDrop) - postgres.Exec(queryCreate) - - // mssql, err := sql.Open("sqlserver", "sqlserver://sa:myPassw0rd@localhost:1433?database=master") - // require.NoError(t, err) - // mssql.Exec(queryDrop) - // mssql.Exec(queryCreate) - - return func() { - mysql.Exec(queryDrop) - postgres.Exec(queryDrop) - //mssql.Exec(queryDrop) - mysql.Close() - postgres.Close() - // mssql.Close() - } -} - -// RunAll applies a sequence of unit tests to check the correct tracing of sql features. -func RunAll(t *testing.T, cfg *Config) int { - - cfg.DB.SetMaxIdleConns(0) - - for name, test := range map[string]func(*Config) func(*testing.T){ - "Connect": testConnect, - "Ping": testPing, - "Query": testQuery, - "Statement": testStatement, - "BeginRollback": testBeginRollback, - "Exec": testExec, - } { - t.Run(name, test(cfg)) - } - var sum int - for _, val := range cfg.OperationToNumSpans { - sum += val - } - return sum -} - -func testConnect(cfg *Config) func(*testing.T) { - return func(t *testing.T) { - err := cfg.DB.Ping() - require.NoError(t, err) - } -} - -func testPing(cfg *Config) func(*testing.T) { - return func(t *testing.T) { - err := cfg.DB.Ping() - require.NoError(t, err) - } -} - -func testQuery(cfg *Config) func(*testing.T) { - var query string - switch cfg.DriverName { - case "postgres", "pgx", "mysql": - query = fmt.Sprintf("SELECT id, name FROM %s LIMIT 5", cfg.TableName) - case "sqlserver": - query = fmt.Sprintf("SELECT TOP 5 id, name FROM %s", cfg.TableName) - } - return func(t *testing.T) { - rows, err := cfg.DB.Query(query) - defer rows.Close() - require.NoError(t, err) - - if cfg.DriverName == "sqlserver" { - //The mssql driver doesn't support non-prepared queries so there are 3 spans - //connect, prepare, and query - cfg.OperationToNumSpans["Query"] += 3 - } - } -} - -func testStatement(cfg *Config) func(*testing.T) { - query := "INSERT INTO %s(name) VALUES(%s)" - switch cfg.DriverName { - case "postgres", "pgx": - query = fmt.Sprintf(query, cfg.TableName, "$1") - case "mysql": - query = fmt.Sprintf(query, cfg.TableName, "?") - case "sqlserver": - query = fmt.Sprintf(query, cfg.TableName, "@p1") - } - return func(t *testing.T) { - stmt, err := cfg.DB.Prepare(query) - require.NoError(t, err) - - _, err2 := stmt.Exec("New York") - require.NoError(t, err2) - } -} - -func testBeginRollback(cfg *Config) func(*testing.T) { - return func(t *testing.T) { - tx, err := cfg.DB.Begin() - require.NoError(t, err) - - err = tx.Rollback() - require.NoError(t, err) - } -} - -func testExec(cfg *Config) func(*testing.T) { - return func(t *testing.T) { - query := fmt.Sprintf("INSERT INTO %s(name) VALUES('New York')", cfg.TableName) - - parent, ctx := tracer.StartSpanFromContext(context.Background(), "test.parent", - tracer.ServiceName("test"), - tracer.ResourceName("parent"), - ) - - tx, err := cfg.DB.BeginTx(ctx, nil) - require.NoError(t, err) - - _, err = tx.ExecContext(ctx, query) - require.NoError(t, err) - err = tx.Commit() - require.NoError(t, err) - - parent.Finish() // flush children - - if cfg.DriverName == "sqlserver" { - //The mssql driver doesn't support non-prepared exec so there are 2 extra spans for the exec: - //prepare, exec, and then a close - cfg.OperationToNumSpans["Exec"] += 2 - } - } -} - -// Config holds the test configuration. -type Config struct { - *sql.DB - OperationToNumSpans map[string]int - DriverName string - TableName string -} diff --git a/contrib/internal/validationtest/contrib/syndtr/goleveldb/leveldb/integration.go b/contrib/internal/validationtest/contrib/syndtr/goleveldb/leveldb/integration.go deleted file mode 100644 index 51f9535af6..0000000000 --- a/contrib/internal/validationtest/contrib/syndtr/goleveldb/leveldb/integration.go +++ /dev/null @@ -1,84 +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 2023 Datadog, Inc. - -package leveldb - -import ( - "testing" - - leveldbtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/syndtr/goleveldb/leveldb" - - "github.com/stretchr/testify/require" - "github.com/syndtr/goleveldb/leveldb" - "github.com/syndtr/goleveldb/leveldb/opt" - "github.com/syndtr/goleveldb/leveldb/storage" - "github.com/syndtr/goleveldb/leveldb/util" -) - -type Integration struct { - db *leveldbtrace.DB - numSpans int - opts []leveldbtrace.Option -} - -func New() *Integration { - return &Integration{ - opts: make([]leveldbtrace.Option, 0), - } -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, leveldbtrace.WithServiceName(name)) -} - -func (i *Integration) Name() string { - return "syndtr/goleveldb/leveldb" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - var err error - i.db, err = leveldbtrace.Open(storage.NewMemStorage(), &opt.Options{}, i.opts...) - require.NoError(t, err) - - t.Cleanup(func() { - i.db.Close() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - t.Helper() - - i.db.CompactRange(util.Range{}) - i.db.Delete([]byte("hello"), nil) - i.db.Has([]byte("hello"), nil) - i.db.Get([]byte("hello"), nil) - var batch leveldb.Batch - batch.Put([]byte("hello"), []byte("world")) - i.db.Write(&batch, nil) - i.numSpans += 5 - - snapshot, err := i.db.GetSnapshot() - require.NoError(t, err) - defer snapshot.Release() - snapshot.Get([]byte("hello"), nil) - i.numSpans++ - - transaction, err := i.db.OpenTransaction() - require.NoError(t, err) - transaction.Commit() - i.numSpans++ - - transaction, err = i.db.OpenTransaction() - require.NoError(t, err) - defer transaction.Discard() - transaction.Get([]byte("hello"), nil) - i.numSpans++ -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} diff --git a/contrib/internal/validationtest/contrib/tidwall/buntdb/integration.go b/contrib/internal/validationtest/contrib/tidwall/buntdb/integration.go deleted file mode 100644 index aa1b5d73ef..0000000000 --- a/contrib/internal/validationtest/contrib/tidwall/buntdb/integration.go +++ /dev/null @@ -1,107 +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 2023 Datadog, Inc. - -package buntdb - -import ( - "testing" - - buntdbtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/tidwall/buntdb" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/tidwall/buntdb" -) - -type Integration struct { - db *buntdbtrace.DB - numSpans int - opts []buntdbtrace.Option -} - -func New() *Integration { - return &Integration{ - opts: make([]buntdbtrace.Option, 0), - } -} - -func (i *Integration) WithServiceName(name string) { - i.opts = append(i.opts, buntdbtrace.WithServiceName(name)) -} - -func (i *Integration) Name() string { - return "tidwall/buntdb" -} - -func (i *Integration) Init(t *testing.T) { - t.Helper() - i.db = getDatabase(t, i) - - t.Cleanup(func() { - i.db.Close() - i.numSpans = 0 - }) -} - -func (i *Integration) GenSpans(t *testing.T) { - t.Helper() - - i.db.View(func(tx *buntdbtrace.Tx) error { - val, err := tx.Get("regular:a") - assert.NoError(t, err) - assert.Equal(t, "1", val) - return nil - }) - i.numSpans++ - - i.db.View(func(tx *buntdbtrace.Tx) error { - var arr []string - err := tx.Descend("test-index", func(key, value string) bool { - arr = append(arr, key, value) - return true - }) - assert.NoError(t, err) - return nil - }) - i.numSpans++ - - i.db.View(func(tx *buntdbtrace.Tx) error { - indexes, err := tx.Indexes() - assert.NoError(t, err) - assert.Equal(t, []string{"test-index", "test-spatial-index"}, indexes) - return nil - }) - i.numSpans++ -} - -func (i *Integration) NumSpans() int { - return i.numSpans -} - -func getDatabase(t *testing.T, i *Integration) *buntdbtrace.DB { - bdb, err := buntdb.Open(":memory:") - require.NoError(t, err) - - err = bdb.CreateIndex("test-index", "regular:*", buntdb.IndexBinary) - require.NoError(t, err) - - err = bdb.CreateSpatialIndex("test-spatial-index", "spatial:*", buntdb.IndexRect) - require.NoError(t, err) - - err = bdb.Update(func(tx *buntdb.Tx) error { - tx.Set("regular:a", "1", nil) - tx.Set("regular:b", "2", nil) - tx.Set("regular:c", "3", nil) - - tx.Set("spatial:a", "[1 1]", nil) - tx.Set("spatial:b", "[2 2]", nil) - tx.Set("spatial:c", "[3 3]", nil) - - return nil - }) - require.NoError(t, err) - - return buntdbtrace.WrapDB(bdb, i.opts...) -} diff --git a/contrib/internal/validationtest/validation_test.go b/contrib/internal/validationtest/validation_test.go index e00f73db1d..3f79f0b4e9 100644 --- a/contrib/internal/validationtest/validation_test.go +++ b/contrib/internal/validationtest/validation_test.go @@ -17,24 +17,7 @@ import ( "time" memcachetest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/bradfitz/gomemcache/memcache" - sqltest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/database/sql" - //redigotest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/garyburd/redigo" - mgotest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/globalsign/mgo" - pgtest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/go-pg/pg.v10" - redistest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/go-redis/redis" - redisV7test "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/go-redis/redis.v7" - redisV8test "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/go-redis/redis.v8" - mongotest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/go.mongodb.org/mongo-driver/mongo" - gocqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/gocql/gocql" - gomodule_redigotest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/gomodule/redigo" - gopkgJinzhuGormv1test "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/gopkg.in/jinzhu/gorm.v1" - gormv1test "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/gorm.io/gorm.v1" - jinzhuGormv1test "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/jinzhu/gorm" - sqlxtest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/jmoiron/sqlx" dnstest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/miekg/dns" - redisV9test "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/redis/go-redis.v9" - leveldbtest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/syndtr/goleveldb/leveldb" - buntdbtest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/tidwall/buntdb" "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" "github.com/stretchr/testify/assert" @@ -113,25 +96,8 @@ func TestIntegrations(t *testing.T) { // t.Skip("to enable integration test, set the INTEGRATION environment variable") // } integrations := []Integration{ - sqltest.New(), - gopkgJinzhuGormv1test.New(), - jinzhuGormv1test.New(), - gormv1test.New(), - mgotest.New(), - sqlxtest.New(), memcachetest.New(), dnstest.New(), - //redigotest.New(), - pgtest.New(), - redistest.New(), - redisV7test.New(), - redisV8test.New(), - mongotest.New(), - gocqltrace.New(), - gomodule_redigotest.New(), - redisV9test.New(), - leveldbtest.New(), - buntdbtest.New(), } testCases := []struct {