diff --git a/.tekton/ci-build/pipeline.yaml b/.tekton/ci-build/pipeline.yaml index 909ec0b15..179185e44 100644 --- a/.tekton/ci-build/pipeline.yaml +++ b/.tekton/ci-build/pipeline.yaml @@ -122,10 +122,6 @@ spec: - name: integration-test-couchbase runAfter: - integration-test-common - when: - - input: "$(params.go-version)" - operator: in - values: ["1.23"] params: - name: imageTag value: $(params.go-version) diff --git a/.tekton/ci-build/task.yaml b/.tekton/ci-build/task.yaml index 895f0b540..c827ce1ed 100644 --- a/.tekton/ci-build/task.yaml +++ b/.tekton/ci-build/task.yaml @@ -249,12 +249,21 @@ metadata: spec: sidecars: - name: couchbase - image: couchbase/server-sandbox:7.2.4 + image: couchbase/server:7.1.4 readinessProbe: httpGet: path: /ui/index.html port: 8091 initialDelaySeconds: 60 + - name: couchbase-setup + image: curlimages/curl + script: | + #!/bin/sh + sleep 30 && \ + curl -v -X POST http://127.0.0.1:8091/pools/default -d memoryQuota=2024 -d indexMemoryQuota=512 && \ + curl -v http://127.0.0.1:8091/node/controller/setupServices -d services=kv%2Ceventing%2Cindex%2Cn1ql%2Ccbas%2Cfts && \ + curl -v http://127.0.0.1:8091/settings/web -d port=8091 -d username=Administrator -d password=password && \ + curl -i -u Administrator:password -X POST http://127.0.0.1:8091/settings/indexes -d 'storageMode=memory_optimized' params: - name: imageTag type: string diff --git a/docker-compose-integration.yaml b/docker-compose-integration.yaml index b958d1a74..f075b21b1 100644 --- a/docker-compose-integration.yaml +++ b/docker-compose-integration.yaml @@ -2,8 +2,25 @@ version: '3' services: - couchbase-server-sandbox: - image: couchbase/server-sandbox:7.1.1 + couchbase: + image: couchbase/server:7.1.4 + hostname: couchbase ports: - - 8091-8094:8091-8094 - - 11210:11210 + - '8091-8096:8091-8096' + - '11210:11210' + + couchbase-setup: + image: amd64/centos:7 + platform: linux/amd64 + depends_on: + - couchbase + restart: "no" + entrypoint: + - "bash" + - "-ecx" + - | + sleep 30 && \ + curl -v -X POST http://couchbase:8091/pools/default -d memoryQuota=2024 -d indexMemoryQuota=512 && \ + curl -v http://couchbase:8091/node/controller/setupServices -d services=kv%2Ceventing%2Cindex%2Cn1ql%2Ccbas%2Cfts && \ + curl -v http://couchbase:8091/settings/web -d port=8091 -d username=Administrator -d password=password && \ + curl -i -u Administrator:password -X POST http://couchbase:8091/settings/indexes -d 'storageMode=memory_optimized' diff --git a/docker-compose.yaml b/docker-compose.yaml index 1c8ec2b09..4d157e396 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -19,11 +19,28 @@ services: - 5671:5671 - 5672:5672 - couchbase-server-sandbox: - image: couchbase/server-sandbox:7.1.1 + couchbase: + image: couchbase/server:7.1.4 + hostname: couchbase ports: - - 8091-8094:8091-8094 - - 11210:11210 + - '8091-8096:8091-8096' + - '11210:11210' + + couchbase-setup: + image: amd64/centos:7 + platform: linux/amd64 + depends_on: + - couchbase + restart: "no" + entrypoint: + - "bash" + - "-ecx" + - | + sleep 30 && \ + curl -v -X POST http://couchbase:8091/pools/default -d memoryQuota=2048 -d indexMemoryQuota=1024 && \ + curl -v http://couchbase:8091/node/controller/setupServices -d services=kv%2Ceventing%2Cindex%2Cn1ql%2Ccbas%2Cfts && \ + curl -v http://couchbase:8091/settings/web -d port=8091 -d username=Administrator -d password=password && \ + curl -i -u Administrator:password -X POST http://couchbase:8091/settings/indexes -d 'storageMode=memory_optimized' redis: image: redis diff --git a/instrumentation/instagocb/bucket_manager_test.go b/instrumentation/instagocb/bucket_manager_test.go index 132846f5a..f1cc9801a 100644 --- a/instrumentation/instagocb/bucket_manager_test.go +++ b/instrumentation/instagocb/bucket_manager_test.go @@ -16,6 +16,7 @@ import ( func TestBucketManager(t *testing.T) { defer instana.ShutdownSensor() recorder, ctx, cluster, a := prepare(t) + defer cluster.Close(&gocb.ClusterCloseOptions{}) bucketMgr := cluster.Buckets() diff --git a/instrumentation/instagocb/cluster.go b/instrumentation/instagocb/cluster.go index 6240c47e0..753904fe2 100644 --- a/instrumentation/instagocb/cluster.go +++ b/instrumentation/instagocb/cluster.go @@ -128,6 +128,10 @@ func (ic *instaCluster) WrapTransactionAttemptContext(tac *gocb.TransactionAttem return createTransactionAttemptContext(ic.iTracer, tac, parentSpan) } +func (ic *instaCluster) Close(opts *gocb.ClusterCloseOptions) error { + return ic.Cluster.Close(opts) +} + // Helper functions // createCluster will wrap *gocb.Cluster in to instaCluster and will return it as Cluster interface diff --git a/instrumentation/instagocb/cluster_test.go b/instrumentation/instagocb/cluster_test.go index 5d790e93a..a2d592c65 100644 --- a/instrumentation/instagocb/cluster_test.go +++ b/instrumentation/instagocb/cluster_test.go @@ -17,10 +17,12 @@ import ( func TestCluster(t *testing.T) { defer instana.ShutdownSensor() - recorder, ctx, cluster, a, _ := prepareWithATestDocumentInCollection(t, "cluster") + + recorder, ctx, cluster, a := prepare(t) + defer cluster.Close(&gocb.ClusterCloseOptions{}) // Query - q := "SELECT count(*) FROM `" + testBucketName + "`." + testScope + "." + testCollection + ";" + q := "SELECT count(*) FROM `" + cbTestBucket + "`." + cbTestScope + "." + cbTestCollection + ";" _, err := cluster.Query(q, &gocb.QueryOptions{ParentSpan: instagocb.GetParentSpanFromContext(ctx)}) a.NoError(err) @@ -41,8 +43,8 @@ func TestCluster(t *testing.T) { err = cluster.SearchIndexes().UpsertIndex( gocb.SearchIndex{ Type: "fulltext-index", - Name: "sample-index", - SourceName: testBucketName, + Name: "sample-index" + testID, + SourceName: cbTestBucket, SourceType: "couchbase", PlanParams: map[string]interface{}{ "maxPartitionsPerPIndex": 171, @@ -79,7 +81,7 @@ func TestCluster(t *testing.T) { time.Sleep(4 * time.Second) matchResult, err := cluster.SearchQuery( - "sample-index", + "sample-index"+testID, search.NewMatchQuery("test"), &gocb.SearchOptions{ Limit: 10, @@ -106,7 +108,7 @@ func TestCluster(t *testing.T) { Bucket: "", Host: "localhost", Type: "", - SQL: "SEARCH sample-index", + SQL: "SEARCH sample-index" + testID, Error: "", }, data.Tags) diff --git a/instrumentation/instagocb/collection_ds_list_test.go b/instrumentation/instagocb/collection_ds_list_test.go index 4d6cade3e..d33380806 100644 --- a/instrumentation/instagocb/collection_ds_list_test.go +++ b/instrumentation/instagocb/collection_ds_list_test.go @@ -19,12 +19,14 @@ func TestCollection_DS_List(t *testing.T) { defer unsetAllowRootExitSpanEnv() defer instana.ShutdownSensor() - recorder, _, cluster, a, _ := prepareWithATestDocumentInCollection(t, "ds_list") - collection := cluster.Bucket(testBucketName).Scope(testScope).Collection(testCollection) + recorder, _, cluster, a := prepare(t) + defer cluster.Close(&gocb.ClusterCloseOptions{}) + + collection := cluster.Bucket(cbTestBucket).Scope(cbTestScope).Collection(cbTestCollection) // List - l := collection.List(testDocumentID) + l := collection.List(dsListTestDocumentID) // Iterator _, err := l.Iterator() @@ -36,7 +38,7 @@ func TestCollection_DS_List(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data := span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "LIST_ITERATOR", @@ -54,7 +56,7 @@ func TestCollection_DS_List(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "LIST_AT", @@ -71,7 +73,7 @@ func TestCollection_DS_List(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "LIST_APPEND", @@ -88,7 +90,7 @@ func TestCollection_DS_List(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "LIST_PREPEND", @@ -106,7 +108,7 @@ func TestCollection_DS_List(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "LIST_INDEX_OF", @@ -124,7 +126,7 @@ func TestCollection_DS_List(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "LIST_SIZE", @@ -141,7 +143,7 @@ func TestCollection_DS_List(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "LIST_REMOVE_AT", @@ -158,7 +160,7 @@ func TestCollection_DS_List(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "LIST_CLEAR", diff --git a/instrumentation/instagocb/collection_ds_map_test.go b/instrumentation/instagocb/collection_ds_map_test.go index b02cbb588..687c17c21 100644 --- a/instrumentation/instagocb/collection_ds_map_test.go +++ b/instrumentation/instagocb/collection_ds_map_test.go @@ -19,12 +19,14 @@ func TestCollection_DS_Map(t *testing.T) { defer unsetAllowRootExitSpanEnv() defer instana.ShutdownSensor() - recorder, _, cluster, a, _ := prepareWithATestDocumentInCollection(t, "ds_map") - collection := cluster.Bucket(testBucketName).Scope(testScope).Collection(testCollection) + recorder, _, cluster, a := prepare(t) + defer cluster.Close(&gocb.ClusterCloseOptions{}) + + collection := cluster.Bucket(cbTestBucket).Scope(cbTestScope).Collection(cbTestCollection) // Map - m := collection.Map(testDocumentID) + m := collection.Map(dsMapTestDocumentID) // Iterator _, err := m.Iterator() @@ -36,7 +38,7 @@ func TestCollection_DS_Map(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data := span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "MAP_ITERATOR", @@ -54,7 +56,7 @@ func TestCollection_DS_Map(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "MAP_AT", @@ -71,7 +73,7 @@ func TestCollection_DS_Map(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "MAP_ADD", @@ -88,7 +90,7 @@ func TestCollection_DS_Map(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "MAP_REMOVE", @@ -106,7 +108,7 @@ func TestCollection_DS_Map(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "MAP_EXISTS", @@ -124,7 +126,7 @@ func TestCollection_DS_Map(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "MAP_SIZE", @@ -142,7 +144,7 @@ func TestCollection_DS_Map(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "MAP_KEYS", @@ -160,7 +162,7 @@ func TestCollection_DS_Map(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "MAP_VALUES", @@ -177,7 +179,7 @@ func TestCollection_DS_Map(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "MAP_CLEAR", diff --git a/instrumentation/instagocb/collection_ds_queue_test.go b/instrumentation/instagocb/collection_ds_queue_test.go index e8d83ff02..0adb78375 100644 --- a/instrumentation/instagocb/collection_ds_queue_test.go +++ b/instrumentation/instagocb/collection_ds_queue_test.go @@ -19,12 +19,14 @@ func TestCollection_DS_Queue(t *testing.T) { defer unsetAllowRootExitSpanEnv() defer instana.ShutdownSensor() - recorder, _, cluster, a, _ := prepareWithATestDocumentInCollection(t, "ds_queue") - collection := cluster.Bucket(testBucketName).Scope(testScope).Collection(testCollection) + recorder, _, cluster, a := prepare(t) + defer cluster.Close(&gocb.ClusterCloseOptions{}) + + collection := cluster.Bucket(cbTestBucket).Scope(cbTestScope).Collection(cbTestCollection) // Queue - q := collection.Queue(testDocumentID) + q := collection.Queue(dsQueueTestDocumentID) // Iterator _, err := q.Iterator() @@ -36,7 +38,7 @@ func TestCollection_DS_Queue(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data := span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "QUEUE_ITERATOR", @@ -53,7 +55,7 @@ func TestCollection_DS_Queue(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "QUEUE_PUSH", @@ -72,7 +74,7 @@ func TestCollection_DS_Queue(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "QUEUE_POP", @@ -90,7 +92,7 @@ func TestCollection_DS_Queue(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "QUEUE_SIZE", @@ -108,7 +110,7 @@ func TestCollection_DS_Queue(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "QUEUE_CLEAR", diff --git a/instrumentation/instagocb/collection_ds_set_test.go b/instrumentation/instagocb/collection_ds_set_test.go index bcca9bdbf..ba57c0fd9 100644 --- a/instrumentation/instagocb/collection_ds_set_test.go +++ b/instrumentation/instagocb/collection_ds_set_test.go @@ -19,12 +19,14 @@ func TestCollection_DS_Set(t *testing.T) { defer unsetAllowRootExitSpanEnv() defer instana.ShutdownSensor() - recorder, _, cluster, a, _ := prepareWithATestDocumentInCollection(t, "ds_set") - collection := cluster.Bucket(testBucketName).Scope(testScope).Collection(testCollection) + recorder, _, cluster, a := prepare(t) + defer cluster.Close(&gocb.ClusterCloseOptions{}) + + collection := cluster.Bucket(cbTestBucket).Scope(cbTestScope).Collection(cbTestCollection) // Set - s := collection.Set(testDocumentID) + s := collection.Set(dsSetTestDocumentID) // Iterator _, err := s.Iterator() @@ -36,7 +38,7 @@ func TestCollection_DS_Set(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data := span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "SET_ITERATOR", @@ -53,7 +55,7 @@ func TestCollection_DS_Set(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "SET_ADD", @@ -70,7 +72,7 @@ func TestCollection_DS_Set(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "SET_REMOVE", @@ -88,7 +90,7 @@ func TestCollection_DS_Set(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "SET_CONTAINS", @@ -106,7 +108,7 @@ func TestCollection_DS_Set(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "SET_VALUES", @@ -124,7 +126,7 @@ func TestCollection_DS_Set(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "SET_SIZE", @@ -141,7 +143,7 @@ func TestCollection_DS_Set(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data = span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: "SET_CLEAR", diff --git a/instrumentation/instagocb/collection_manager_test.go b/instrumentation/instagocb/collection_manager_test.go index b8619b760..5f429987c 100644 --- a/instrumentation/instagocb/collection_manager_test.go +++ b/instrumentation/instagocb/collection_manager_test.go @@ -15,7 +15,9 @@ import ( func TestCollectionManager(t *testing.T) { defer instana.ShutdownSensor() - recorder, ctx, cluster, a := prepareWithBucket(t) + + recorder, ctx, cluster, a := prepareWithBucket(t, testBucketName) + defer cluster.Close(&gocb.ClusterCloseOptions{}) bucket := cluster.Bucket(testBucketName) cm := bucket.Collections() diff --git a/instrumentation/instagocb/collection_test.go b/instrumentation/instagocb/collection_test.go index bd00cb4ca..732f6a337 100644 --- a/instrumentation/instagocb/collection_test.go +++ b/instrumentation/instagocb/collection_test.go @@ -26,7 +26,9 @@ func unsetAllowRootExitSpanEnv() { func TestCollection_CRUD(t *testing.T) { testDocumentValue := getTestDocumentValue() defer instana.ShutdownSensor() - recorder, ctx, cluster, a := prepareWithCollection(t) + + recorder, ctx, cluster, a := prepareWithCollection(t, testBucketName, testScope, testCollection) + defer cluster.Close(&gocb.ClusterCloseOptions{}) collection := cluster.Bucket(testBucketName).Scope(testScope).Collection(testCollection) diff --git a/instrumentation/instagocb/instagocb_test.go b/instrumentation/instagocb/instagocb_test.go index 35ae5d8cc..2cf52bd30 100644 --- a/instrumentation/instagocb/instagocb_test.go +++ b/instrumentation/instagocb/instagocb_test.go @@ -7,6 +7,8 @@ package instagocb_test import ( "context" + "math/rand" + "os" "testing" "github.com/couchbase/gocb/v2" @@ -17,13 +19,32 @@ import ( "github.com/stretchr/testify/assert" ) +var testID = genUniqueTestID() var connStr = "couchbase://localhost" var username = "Administrator" var password = "password" -var testBucketName = "test-bucket" -var testScope = "test_scope" -var testCollection = "test_collection" -var testDocumentID string = "test-doc-id" + +// cb resource names +var ( + cbTestBucket = "cb-test-bucket_" + testID + cbTestScope = "cb_test_scope_" + testID + cbTestCollection = "cb_test_collection_" + testID + testBucketName = "test-bucket_" + testID + testScope = "test_scope_" + testID + testCollection = "test_collection_" + testID +) + +// test document IDs +var ( + testDocumentID = "test-doc-id" + clusterTestDocumentID = "cluster-test-doc-id" + dsListTestDocumentID = "ds-list-test-doc-id" + dsMapTestDocumentID = "ds-map-test-doc-id" + dsQueueTestDocumentID = "ds-queue-test-doc-id" + dsSetTestDocumentID = "ds-set-test-doc-id" + scopeTestDocumentID = "scope-test-doc-id" +) + var rec *instana.Recorder // Test Document to insert @@ -43,7 +64,7 @@ func (alwaysReadyClient) Flush(context.Context) error { re func TestUnwrapForAll(t *testing.T) { defer instana.ShutdownSensor() - _, _, cluster, a, _ := prepareWithATestDocumentInCollection(t, "ds_list") + _, _, cluster, a := prepare(t) // Cluster c := cluster.Unwrap() @@ -150,14 +171,14 @@ func prepare(t *testing.T) (*instana.Recorder, context.Context, instagocb.Cluste } -func prepareWithBucket(t *testing.T) (*instana.Recorder, context.Context, instagocb.Cluster, *assert.Assertions) { +func prepareWithBucket(t *testing.T, bucketName string) (*instana.Recorder, context.Context, instagocb.Cluster, *assert.Assertions) { recorder, ctx, cluster, a := prepare(t) bs := gocb.BucketSettings{ - Name: testBucketName, + Name: bucketName, FlushEnabled: true, ReplicaIndexDisabled: true, - RAMQuotaMB: 150, + RAMQuotaMB: 100, NumReplicas: 0, BucketType: gocb.CouchbaseBucketType, } @@ -173,58 +194,88 @@ func prepareWithBucket(t *testing.T) (*instana.Recorder, context.Context, instag return recorder, ctx, cluster, a } -func prepareWithScope(t *testing.T) (*instana.Recorder, context.Context, instagocb.Cluster, *assert.Assertions) { - recorder, ctx, cluster, a := prepareWithBucket(t) - b := cluster.Bucket(testBucketName) +func prepareWithScope(t *testing.T, bucketName, scope string) (*instana.Recorder, context.Context, instagocb.Cluster, *assert.Assertions) { + recorder, ctx, cluster, a := prepareWithBucket(t, bucketName) + b := cluster.Bucket(bucketName) collections := b.Collections() - err := collections.CreateScope(testScope, &gocb.CreateScopeOptions{}) + err := collections.CreateScope(scope, &gocb.CreateScopeOptions{}) a.NoError(err) return recorder, ctx, cluster, a } -func prepareWithCollection(t *testing.T) (*instana.Recorder, context.Context, instagocb.Cluster, *assert.Assertions) { - recorder, ctx, cluster, a := prepareWithScope(t) - b := cluster.Bucket(testBucketName) +func prepareWithCollection(t *testing.T, bucketName, scope, collection string) (*instana.Recorder, context.Context, instagocb.Cluster, *assert.Assertions) { + recorder, ctx, cluster, a := prepareWithScope(t, bucketName, scope) + b := cluster.Bucket(bucketName) collections := b.Collections() err := collections.CreateCollection(gocb.CollectionSpec{ - Name: testCollection, - ScopeName: testScope, + Name: collection, + ScopeName: scope, }, &gocb.CreateCollectionOptions{}) a.NoError(err) return recorder, ctx, cluster, a } -func prepareWithATestDocumentInCollection(t *testing.T, operation string) (*instana.Recorder, context.Context, instagocb.Cluster, *assert.Assertions, interface{}) { - recorder, ctx, cluster, a := prepareWithCollection(t) - b := cluster.Bucket(testBucketName) - collection := b.Scope(testScope).Collection(testCollection) - var err error - var value interface{} - - switch operation { - case "ds_list", "ds_set", "ds_queue": - value = []interface{}{getTestStringValue()} - case "ds_map": - value = map[string]interface{}{ +func setup() error { + + t := &testing.T{} + + _, _, cluster, a := prepareWithCollection(t, cbTestBucket, cbTestScope, cbTestCollection) + b := cluster.Bucket(cbTestBucket) + collection := b.Scope(cbTestScope).Collection(cbTestCollection) + + docs := map[string]interface{}{ + dsListTestDocumentID: []interface{}{getTestStringValue()}, + dsSetTestDocumentID: []interface{}{getTestStringValue()}, + dsQueueTestDocumentID: []interface{}{getTestStringValue()}, + dsMapTestDocumentID: map[string]interface{}{ "test-key": getTestStringValue(), - } - case "scope", "cluster": - value = getTestDocumentValue() - default: - value = getTestDocumentValue() + }, + scopeTestDocumentID: getTestDocumentValue(), + clusterTestDocumentID: getTestDocumentValue(), + } + // Create an Array of BulkOps for Insert + var items []gocb.BulkOp + + // Add docs to the array that will be performed as a bulk operation + for key, val := range docs { + items = append(items, &gocb.InsertOp{ID: key, Value: val}) } - _, err = collection.Insert(testDocumentID, value, &gocb.InsertOptions{}) + + // Perform the bulk operation + err := collection.Do(items, &gocb.BulkOpOptions{}) a.NoError(err) - if operation == "cluster" { - _, err = b.DefaultCollection().Insert(testDocumentID, value, &gocb.InsertOptions{}) - a.NoError(err) + _, err = b.DefaultCollection().Insert(testDocumentID, getTestDocumentValue(), &gocb.InsertOptions{}) + a.NoError(err) + + return err +} + +func TestMain(m *testing.M) { + if err := setup(); err != nil { + os.Exit(1) } - return recorder, ctx, cluster, a, value + exitCode := m.Run() + + clear() + os.Exit(exitCode) + +} + +func clear() { + + _, _, cluster, _ := prepare(&testing.T{}) + bucketMgr := cluster.Buckets() + + // drop testBucket + bucketMgr.DropBucket(testBucketName, &gocb.DropBucketOptions{}) + + // drop cbTestBucket + bucketMgr.DropBucket(cbTestBucket, &gocb.DropBucketOptions{}) } func getLatestSpan(recorder *instana.Recorder) instana.Span { @@ -244,3 +295,15 @@ func getTestDocumentValue() myDoc { func getTestStringValue() string { return "test-value-string" } + +func genUniqueTestID() string { + + letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") + + b := make([]rune, 10) + for i := range b { + b[i] = letters[rand.Intn(len(letters))] + } + + return string(b) +} diff --git a/instrumentation/instagocb/scope_test.go b/instrumentation/instagocb/scope_test.go index 88c6d6063..31eee42c9 100644 --- a/instrumentation/instagocb/scope_test.go +++ b/instrumentation/instagocb/scope_test.go @@ -15,12 +15,14 @@ import ( func TestScope(t *testing.T) { defer instana.ShutdownSensor() - recorder, ctx, cluster, a, _ := prepareWithATestDocumentInCollection(t, "scope") - scope := cluster.Bucket(testBucketName).Scope(testScope) + recorder, ctx, cluster, a := prepare(t) + defer cluster.Close(&gocb.ClusterCloseOptions{}) + + scope := cluster.Bucket(cbTestBucket).Scope(cbTestScope) // Query - q := "SELECT count(*) FROM `" + testBucketName + "`." + testScope + "." + testCollection + ";" + q := "SELECT count(*) FROM `" + cbTestBucket + "`." + cbTestScope + "." + cbTestCollection + ";" _, err := scope.Query(q, &gocb.QueryOptions{ParentSpan: instagocb.GetParentSpanFromContext(ctx)}) a.NoError(err) @@ -30,7 +32,7 @@ func TestScope(t *testing.T) { a.IsType(instana.CouchbaseSpanData{}, span.Data) data := span.Data.(instana.CouchbaseSpanData) a.Equal(instana.CouchbaseSpanTags{ - Bucket: testBucketName, + Bucket: cbTestBucket, Host: "localhost", Type: string(gocb.CouchbaseBucketType), SQL: q, diff --git a/instrumentation/instagocb/transactions_test.go b/instrumentation/instagocb/transactions_test.go index ca83baac4..4b7e6e7f2 100644 --- a/instrumentation/instagocb/transactions_test.go +++ b/instrumentation/instagocb/transactions_test.go @@ -16,7 +16,7 @@ import ( func TestTransactions(t *testing.T) { testDocumentValue := getTestDocumentValue() defer instana.ShutdownSensor() - recorder, ctx, cluster, a := prepareWithCollection(t) + recorder, ctx, cluster, a := prepareWithCollection(t, testBucketName, testScope, testCollection) scope := cluster.Bucket(testBucketName).Scope(testScope) @@ -117,16 +117,18 @@ func TestTransactions(t *testing.T) { } } - recorder, ctx, cluster, a, _ = prepareWithATestDocumentInCollection(t, "scope") - scope = cluster.Bucket(testBucketName).Scope(testScope) - collection = scope.Collection(testCollection) - transaction = cluster.Transactions() + cluster.Close(&gocb.ClusterCloseOptions{}) - q := "SELECT count(*) FROM `" + testBucketName + "`." + testScope + "." + testCollection + ";" + recorder, ctx, conn, a := prepare(t) + scope = conn.Bucket(cbTestBucket).Scope(cbTestScope) + collection = scope.Collection(cbTestCollection) + transaction = conn.Transactions() + + q := "SELECT count(*) FROM `" + cbTestBucket + "`." + cbTestScope + "." + cbTestCollection + ";" _, err = transaction.Run( func(tac *gocb.TransactionAttemptContext) error { // Query - c := cluster.WrapTransactionAttemptContext(tac, instagocb.GetParentSpanFromContext(ctx)) + c := conn.WrapTransactionAttemptContext(tac, instagocb.GetParentSpanFromContext(ctx)) _, err := c.Query(q, &gocb.TransactionQueryOptions{}) a.NoError(err) @@ -151,4 +153,6 @@ func TestTransactions(t *testing.T) { Error: "", }, data.Tags) + conn.Close(&gocb.ClusterCloseOptions{}) + }