1
1
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
2
2
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
3
+ import static datadog.trace.api.config.TraceInstrumentationConfig.CASSANDRA_KEYSPACE_STATEMENT_EXTRACTION_ENABLED
3
4
import static datadog.trace.api.config.TraceInstrumentationConfig.DB_CLIENT_HOST_SPLIT_BY_INSTANCE
4
5
5
6
import com.datastax.driver.core.Cluster
@@ -57,8 +58,11 @@ abstract class CassandraClientTest extends VersionedNamingTestBase {
57
58
def " test sync" () {
58
59
setup :
59
60
60
- Session session = cluster. connect(keyspace)
61
+ Session session = keyspace ? cluster. connect(keyspace) : cluster . connect( )
61
62
injectSysConfig(DB_CLIENT_HOST_SPLIT_BY_INSTANCE , " $renameService " )
63
+ if (extractFromStatement) {
64
+ injectSysConfig(CASSANDRA_KEYSPACE_STATEMENT_EXTRACTION_ENABLED , " true" )
65
+ }
62
66
63
67
when :
64
68
session. execute(statement)
@@ -71,27 +75,37 @@ abstract class CassandraClientTest extends VersionedNamingTestBase {
71
75
}
72
76
}
73
77
trace(1 ) {
74
- cassandraSpan(it, statement, keyspace , renameService)
78
+ cassandraSpan(it, statement, expectedKeySpace , renameService)
75
79
}
76
80
}
77
81
78
82
cleanup :
79
83
session. close()
80
84
81
85
where :
82
- statement | keyspace | renameService
83
- " DROP KEYSPACE IF EXISTS sync_test" | null | false
84
- " CREATE KEYSPACE sync_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | true
85
- " CREATE TABLE sync_test.users ( id UUID PRIMARY KEY, name text )" | " sync_test" | false
86
- " INSERT INTO sync_test.users (id, name) values (uuid(), 'alice')" | " sync_test" | false
87
- " SELECT * FROM users where name = 'alice' ALLOW FILTERING" | " sync_test" | true
86
+ statement | keyspace | expectedKeySpace | renameService | extractFromStatement
87
+ " DROP KEYSPACE IF EXISTS sync_test" | null | null | false | true
88
+ " DROP KEYSPACE IF EXISTS a_ks" | null | null | false | true
89
+ " CREATE KEYSPACE sync_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | null | true | true
90
+ " CREATE KEYSPACE a_ks WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | null | false | true
91
+ " CREATE TABLE sync_test.users ( id UUID PRIMARY KEY, name text )" | " sync_test" | " sync_test" | false | true
92
+ " INSERT INTO sync_test.users (id, name) values (uuid(), 'alice')" | " sync_test" | " sync_test" | false | true
93
+ " SELECT * FROM users where name = 'alice' ALLOW FILTERING" | " sync_test" | " sync_test" | true | true
94
+ " SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING" | " a_ks" | " sync_test" | false | true
95
+ " SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING" | " a_ks" | " sync_test" | true | true
96
+ " SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING" | null | " sync_test" | false | true
97
+ " SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING" | null | " sync_test" | true | true
98
+ " SELECT * FROM sync_test.users where name = 'alice' ALLOW FILTERING" | null | null | false | false
88
99
}
89
100
90
101
def " test async" () {
91
102
setup :
92
103
93
104
def callbackExecuted = new CountDownLatch (1 )
94
105
injectSysConfig(DB_CLIENT_HOST_SPLIT_BY_INSTANCE , " $renameService " )
106
+ if (extractFromStatement) {
107
+ injectSysConfig(CASSANDRA_KEYSPACE_STATEMENT_EXTRACTION_ENABLED , " true" )
108
+ }
95
109
96
110
when :
97
111
Session session = cluster. connect(keyspace)
@@ -117,7 +131,7 @@ abstract class CassandraClientTest extends VersionedNamingTestBase {
117
131
trace(3 ) {
118
132
sortSpansByStart()
119
133
basicSpan(it, " parent" )
120
- cassandraSpan(it, statement, keyspace , renameService, span(0 ))
134
+ cassandraSpan(it, statement, expectedKeySpace , renameService, span(0 ))
121
135
basicSpan(it, " callbackListener" , span(0 ))
122
136
}
123
137
}
@@ -126,12 +140,17 @@ abstract class CassandraClientTest extends VersionedNamingTestBase {
126
140
session. close()
127
141
128
142
where :
129
- statement | keyspace | renameService
130
- " DROP KEYSPACE IF EXISTS async_test" | null | false
131
- " CREATE KEYSPACE async_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | true
132
- " CREATE TABLE async_test.users ( id UUID PRIMARY KEY, name text )" | " async_test" | false
133
- " INSERT INTO async_test.users (id, name) values (uuid(), 'alice')" | " async_test" | false
134
- " SELECT * FROM users where name = 'alice' ALLOW FILTERING" | " async_test" | true
143
+ statement | keyspace | expectedKeySpace | renameService | extractFromStatement
144
+ " DROP KEYSPACE IF EXISTS async_test" | null | null | false | false
145
+ " DROP KEYSPACE IF EXISTS a_ks" | null | null | false | false
146
+ " CREATE KEYSPACE async_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | null | true | false
147
+ " CREATE KEYSPACE a_ks WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | null | true | false
148
+ " CREATE TABLE async_test.users ( id UUID PRIMARY KEY, name text )" | " async_test" | " async_test" | false | false
149
+ " INSERT INTO async_test.users (id, name) values (uuid(), 'alice')" | " async_test" | " async_test" | false | false
150
+ " SELECT * FROM users where name = 'alice' ALLOW FILTERING" | " async_test" | " async_test" | false | false
151
+ " SELECT * FROM async_test.users where name = 'alice' ALLOW FILTERING" | null | null | false | false
152
+ " SELECT * FROM async_test.users where name = 'alice' ALLOW FILTERING" | " a_ks" | " a_ks" | false | false
153
+ " SELECT * FROM async_test.users where name = 'alice' ALLOW FILTERING" | null | " async_test" | true | true
135
154
}
136
155
137
156
String normalize (String statement ){
0 commit comments