Skip to content

Commit 671b018

Browse files
code cleanup
1 parent 6e3a157 commit 671b018

File tree

3 files changed

+88
-2
lines changed

3 files changed

+88
-2
lines changed

Diff for: instrumentation/instagocb/cluster.go

+19
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,25 @@ func (ic *instaCluster) SearchQuery(indexName string, query cbsearch.Query, opts
9898
return res, err
9999
}
100100

101+
// AnalyticsQuery executes the analytics query statement on the server.
102+
func (ic *instaCluster) AnalyticsQuery(statement string, opts *gocb.AnalyticsOptions) (*gocb.AnalyticsResult, error) {
103+
var tracectx gocb.RequestSpanContext
104+
if opts.ParentSpan != nil {
105+
tracectx = opts.ParentSpan.Context()
106+
}
107+
108+
span := ic.iTracer.RequestSpan(tracectx, "ANALYTICS_QUERY")
109+
span.SetAttribute(operationSpanTag, statement)
110+
111+
res, err := ic.Cluster.AnalyticsQuery(statement, opts)
112+
113+
span.(*Span).err = err
114+
115+
defer span.End()
116+
117+
return res, err
118+
}
119+
101120
// Unwrap returns the original *gocb.Cluster instance.
102121
// Note: It is not advisable to use this directly, as Instana tracing will not be enabled if you directly utilize this instance.
103122
func (ic *instaCluster) Unwrap() *gocb.Cluster {

Diff for: instrumentation/instagocb/instagocb_test.go

+67-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var testScope = "test_scope"
2525
var testCollection = "test_collection"
2626
var testDocumentID string = "test-doc-id"
2727

28-
// Insert Document
28+
// Test Document to insert
2929
type myDoc struct {
3030
Foo string `json:"foo"`
3131
Bar string `json:"bar"`
@@ -40,6 +40,71 @@ func (alwaysReadyClient) SendSpans(spans []instana.Span) error { re
4040
func (alwaysReadyClient) SendProfiles(profiles []autoprofile.Profile) error { return nil }
4141
func (alwaysReadyClient) Flush(context.Context) error { return nil }
4242

43+
func TestUnwrapForAll(t *testing.T) {
44+
defer instana.ShutdownSensor()
45+
_, _, cluster, a, _ := prepareWithATestDocumentInCollection(t, "ds_list")
46+
47+
// Cluster
48+
c := cluster.Unwrap()
49+
a.IsType(&gocb.Cluster{}, c)
50+
a.NotNil(c)
51+
52+
// Bucket Manager
53+
bm := cluster.Buckets().Unwrap()
54+
a.IsType(&gocb.BucketManager{}, bm)
55+
a.NotNil(bm)
56+
57+
// Bucket
58+
b := cluster.Bucket(testBucketName).Unwrap()
59+
a.IsType(&gocb.Bucket{}, b)
60+
a.NotNil(b)
61+
62+
//Scope
63+
s := cluster.Bucket(testBucketName).Scope(testScope)
64+
su := s.Unwrap()
65+
a.IsType(&gocb.Scope{}, su)
66+
a.NotNil(su)
67+
68+
// Collection
69+
coll := s.Collection(testCollection)
70+
collU := coll.Unwrap()
71+
a.IsType(&gocb.Collection{}, collU)
72+
a.NotNil(collU)
73+
74+
// Collection Manager
75+
cm := cluster.Bucket(testBucketName).Collections().Unwrap()
76+
a.IsType(&gocb.CollectionManager{}, cm)
77+
a.NotNil(cm)
78+
79+
// Collection Map
80+
m := coll.Map("id").Unwrap()
81+
a.IsType(&gocb.CouchbaseMap{}, m)
82+
a.NotNil(m)
83+
84+
// Collection List
85+
l := coll.List("id").Unwrap()
86+
a.IsType(&gocb.CouchbaseList{}, l)
87+
a.NotNil(l)
88+
89+
// Collection Queue
90+
q := coll.Queue("id").Unwrap()
91+
a.IsType(&gocb.CouchbaseQueue{}, q)
92+
a.NotNil(q)
93+
94+
// Collection Set
95+
st := coll.Set("id").Unwrap()
96+
a.IsType(&gocb.CouchbaseSet{}, st)
97+
a.NotNil(st)
98+
99+
// Collection Binary
100+
cb := coll.Binary().Unwrap()
101+
a.IsType(&gocb.BinaryCollection{}, cb)
102+
a.NotNil(cb)
103+
104+
}
105+
106+
// helper functions
107+
43108
func prepare(t *testing.T) (*instana.Recorder, context.Context, instagocb.Cluster, *assert.Assertions) {
44109
a := assert.New(t)
45110
recorder := instana.NewTestRecorder()
@@ -127,7 +192,7 @@ func prepareWithATestDocumentInCollection(t *testing.T, operation string) (*inst
127192
case "scope", "cluster":
128193
value = getTestDocumentValue()
129194
default:
130-
value = getTestStringValue()
195+
value = getTestDocumentValue()
131196

132197
}
133198
_, err = collection.Insert(testDocumentID, value, &gocb.InsertOptions{})

Diff for: instrumentation/instagocb/scope.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ type Scope interface {
1414

1515
// analytic query
1616
AnalyticsQuery(statement string, opts *gocb.AnalyticsOptions) (*gocb.AnalyticsResult, error)
17+
18+
Unwrap() *gocb.Scope
1719
}
1820

1921
type instaScope struct {

0 commit comments

Comments
 (0)