Merge pull request #885 from DataDog/tyler/instance-name-testing
Additional testing for split-by-instance config
This commit is contained in:
commit
ec931463a4
|
@ -16,6 +16,7 @@ import com.couchbase.mock.CouchbaseMock
|
|||
import com.couchbase.mock.http.query.QueryServer
|
||||
import datadog.trace.agent.test.AgentTestRunner
|
||||
import datadog.trace.agent.test.utils.PortUtils
|
||||
import datadog.trace.api.Config
|
||||
import spock.lang.Shared
|
||||
|
||||
import java.util.concurrent.RejectedExecutionException
|
||||
|
@ -87,6 +88,9 @@ abstract class AbstractCouchbaseTest extends AgentTestRunner {
|
|||
// Cache buckets:
|
||||
couchbaseCluster.openBucket(bucketCouchbase.name(), bucketCouchbase.password())
|
||||
memcacheCluster.openBucket(bucketMemcache.name(), bucketMemcache.password())
|
||||
|
||||
// This setting should have no effect since decorator returns null for the instance.
|
||||
System.setProperty(Config.PREFIX + Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE, "true")
|
||||
}
|
||||
|
||||
private static BucketConfiguration convert(BucketSettings bucketSettings) {
|
||||
|
@ -112,6 +116,8 @@ abstract class AbstractCouchbaseTest extends AgentTestRunner {
|
|||
}
|
||||
|
||||
mock?.stop()
|
||||
|
||||
System.clearProperty(Config.PREFIX + Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE)
|
||||
}
|
||||
|
||||
private DefaultCouchbaseEnvironment.Builder envBuilder(BucketSettings bucketSettings) {
|
||||
|
|
|
@ -3,11 +3,13 @@ import com.datastax.driver.core.Session
|
|||
import datadog.opentracing.DDSpan
|
||||
import datadog.trace.agent.test.AgentTestRunner
|
||||
import datadog.trace.agent.test.asserts.TraceAssert
|
||||
import datadog.trace.api.Config
|
||||
import datadog.trace.api.DDSpanTypes
|
||||
import io.opentracing.tag.Tags
|
||||
import org.cassandraunit.utils.EmbeddedCassandraServerHelper
|
||||
import spock.lang.Shared
|
||||
|
||||
import static datadog.trace.agent.test.utils.ConfigUtils.withConfigOverride
|
||||
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
|
||||
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
|
||||
|
||||
|
@ -44,17 +46,19 @@ class CassandraClientTest extends AgentTestRunner {
|
|||
setup:
|
||||
Session session = cluster.connect(keyspace)
|
||||
|
||||
session.execute(statement)
|
||||
withConfigOverride(Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE, "$renameService") {
|
||||
session.execute(statement)
|
||||
}
|
||||
|
||||
expect:
|
||||
assertTraces(keyspace ? 2 : 1) {
|
||||
if (keyspace) {
|
||||
trace(0, 1) {
|
||||
cassandraSpan(it, 0, "USE $keyspace", null)
|
||||
cassandraSpan(it, 0, "USE $keyspace", null, false)
|
||||
}
|
||||
}
|
||||
trace(keyspace ? 1 : 0, 1) {
|
||||
cassandraSpan(it, 0, statement, keyspace)
|
||||
cassandraSpan(it, 0, statement, keyspace, renameService)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,19 +66,21 @@ class CassandraClientTest extends AgentTestRunner {
|
|||
session.close()
|
||||
|
||||
where:
|
||||
statement | keyspace
|
||||
"DROP KEYSPACE IF EXISTS sync_test" | null
|
||||
"CREATE KEYSPACE sync_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null
|
||||
"CREATE TABLE sync_test.users ( id UUID PRIMARY KEY, name text )" | "sync_test"
|
||||
"INSERT INTO sync_test.users (id, name) values (uuid(), 'alice')" | "sync_test"
|
||||
"SELECT * FROM users where name = 'alice' ALLOW FILTERING" | "sync_test"
|
||||
statement | keyspace | renameService
|
||||
"DROP KEYSPACE IF EXISTS sync_test" | null | false
|
||||
"CREATE KEYSPACE sync_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | true
|
||||
"CREATE TABLE sync_test.users ( id UUID PRIMARY KEY, name text )" | "sync_test" | false
|
||||
"INSERT INTO sync_test.users (id, name) values (uuid(), 'alice')" | "sync_test" | false
|
||||
"SELECT * FROM users where name = 'alice' ALLOW FILTERING" | "sync_test" | true
|
||||
}
|
||||
|
||||
def "test async"() {
|
||||
setup:
|
||||
Session session = cluster.connect(keyspace)
|
||||
runUnderTrace("parent") {
|
||||
session.executeAsync(statement)
|
||||
withConfigOverride(Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE, "$renameService") {
|
||||
session.executeAsync(statement)
|
||||
}
|
||||
blockUntilChildSpansFinished(1)
|
||||
}
|
||||
|
||||
|
@ -82,12 +88,12 @@ class CassandraClientTest extends AgentTestRunner {
|
|||
assertTraces(keyspace ? 2 : 1) {
|
||||
if (keyspace) {
|
||||
trace(0, 1) {
|
||||
cassandraSpan(it, 0, "USE $keyspace", null)
|
||||
cassandraSpan(it, 0, "USE $keyspace", null, false)
|
||||
}
|
||||
}
|
||||
trace(keyspace ? 1 : 0, 2) {
|
||||
basicSpan(it, 0, "parent")
|
||||
cassandraSpan(it, 1, statement, keyspace, span(0))
|
||||
cassandraSpan(it, 1, statement, keyspace, renameService, span(0))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,17 +101,17 @@ class CassandraClientTest extends AgentTestRunner {
|
|||
session.close()
|
||||
|
||||
where:
|
||||
statement | keyspace
|
||||
"DROP KEYSPACE IF EXISTS async_test" | null
|
||||
"CREATE KEYSPACE async_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null
|
||||
"CREATE TABLE async_test.users ( id UUID PRIMARY KEY, name text )" | "async_test"
|
||||
"INSERT INTO async_test.users (id, name) values (uuid(), 'alice')" | "async_test"
|
||||
"SELECT * FROM users where name = 'alice' ALLOW FILTERING" | "async_test"
|
||||
statement | keyspace | renameService
|
||||
"DROP KEYSPACE IF EXISTS async_test" | null | false
|
||||
"CREATE KEYSPACE async_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | true
|
||||
"CREATE TABLE async_test.users ( id UUID PRIMARY KEY, name text )" | "async_test" | false
|
||||
"INSERT INTO async_test.users (id, name) values (uuid(), 'alice')" | "async_test" | false
|
||||
"SELECT * FROM users where name = 'alice' ALLOW FILTERING" | "async_test" | true
|
||||
}
|
||||
|
||||
def cassandraSpan(TraceAssert trace, int index, String statement, String keyspace, Object parentSpan = null, Throwable exception = null) {
|
||||
def cassandraSpan(TraceAssert trace, int index, String statement, String keyspace, boolean renameService, Object parentSpan = null, Throwable exception = null) {
|
||||
trace.span(index) {
|
||||
serviceName "cassandra"
|
||||
serviceName renameService && keyspace ? keyspace : "cassandra"
|
||||
operationName "cassandra.query"
|
||||
resourceName statement
|
||||
spanType DDSpanTypes.CASSANDRA
|
||||
|
|
|
@ -2,6 +2,7 @@ import com.mchange.v2.c3p0.ComboPooledDataSource
|
|||
import com.zaxxer.hikari.HikariConfig
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import datadog.trace.agent.test.AgentTestRunner
|
||||
import datadog.trace.api.Config
|
||||
import datadog.trace.api.DDSpanTypes
|
||||
import io.opentracing.tag.Tags
|
||||
import javax.sql.DataSource
|
||||
|
@ -17,6 +18,7 @@ import java.sql.PreparedStatement
|
|||
import java.sql.ResultSet
|
||||
import java.sql.Statement
|
||||
|
||||
import static datadog.trace.agent.test.utils.ConfigUtils.withConfigOverride
|
||||
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
|
||||
|
||||
class JDBCInstrumentationTest extends AgentTestRunner {
|
||||
|
@ -154,7 +156,9 @@ class JDBCInstrumentationTest extends AgentTestRunner {
|
|||
setup:
|
||||
Statement statement = connection.createStatement()
|
||||
ResultSet resultSet = runUnderTrace("parent") {
|
||||
return statement.executeQuery(query)
|
||||
withConfigOverride(Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE, "$renameService") {
|
||||
return statement.executeQuery(query)
|
||||
}
|
||||
}
|
||||
|
||||
expect:
|
||||
|
@ -167,8 +171,8 @@ class JDBCInstrumentationTest extends AgentTestRunner {
|
|||
parent()
|
||||
}
|
||||
span(1) {
|
||||
serviceName renameService ? dbName.toLowerCase() : driver
|
||||
operationName "${driver}.query"
|
||||
serviceName driver
|
||||
resourceName query
|
||||
spanType DDSpanTypes.SQL
|
||||
childOf span(0)
|
||||
|
@ -193,22 +197,22 @@ class JDBCInstrumentationTest extends AgentTestRunner {
|
|||
connection.close()
|
||||
|
||||
where:
|
||||
driver | connection | username | query
|
||||
"h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | "SELECT 3"
|
||||
"derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
|
||||
"hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null) | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||
"h2" | new Driver().connect(jdbcUrls.get("h2"), connectionProps) | null | "SELECT 3"
|
||||
"derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), connectionProps) | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
|
||||
"hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), connectionProps) | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||
"h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | "SELECT 3"
|
||||
"derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
|
||||
"hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||
"h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | "SELECT 3"
|
||||
"derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
|
||||
"hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||
"h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | "SELECT 3"
|
||||
"derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
|
||||
"hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||
driver | connection | username | renameService | query
|
||||
"h2" | new Driver().connect(jdbcUrls.get("h2"), null) | null | false | "SELECT 3"
|
||||
"derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), null) | "APP" | false | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
|
||||
"hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), null) | "SA" | false | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||
"h2" | new Driver().connect(jdbcUrls.get("h2"), connectionProps) | null | true | "SELECT 3"
|
||||
"derby" | new EmbeddedDriver().connect(jdbcUrls.get("derby"), connectionProps) | "APP" | true | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
|
||||
"hsqldb" | new JDBCDriver().connect(jdbcUrls.get("hsqldb"), connectionProps) | "SA" | true | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||
"h2" | cpDatasources.get("tomcat").get("h2").getConnection() | null | false | "SELECT 3"
|
||||
"derby" | cpDatasources.get("tomcat").get("derby").getConnection() | "APP" | false | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
|
||||
"hsqldb" | cpDatasources.get("tomcat").get("hsqldb").getConnection() | "SA" | true | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||
"h2" | cpDatasources.get("hikari").get("h2").getConnection() | null | false | "SELECT 3"
|
||||
"derby" | cpDatasources.get("hikari").get("derby").getConnection() | "APP" | true | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
|
||||
"hsqldb" | cpDatasources.get("hikari").get("hsqldb").getConnection() | "SA" | false | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||
"h2" | cpDatasources.get("c3p0").get("h2").getConnection() | null | true | "SELECT 3"
|
||||
"derby" | cpDatasources.get("c3p0").get("derby").getConnection() | "APP" | false | "SELECT 3 FROM SYSIBM.SYSDUMMY1"
|
||||
"hsqldb" | cpDatasources.get("c3p0").get("hsqldb").getConnection() | "SA" | false | "SELECT 3 FROM INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||
}
|
||||
|
||||
@Unroll
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import datadog.trace.agent.test.AgentTestRunner
|
||||
import datadog.trace.api.Config
|
||||
import datadog.trace.api.DDSpanTypes
|
||||
import io.opentracing.tag.Tags
|
||||
import redis.clients.jedis.Jedis
|
||||
|
@ -22,11 +23,16 @@ class JedisClientTest extends AgentTestRunner {
|
|||
def setupSpec() {
|
||||
println "Using redis: $redisServer.args"
|
||||
redisServer.start()
|
||||
|
||||
// This setting should have no effect since decorator returns null for the instance.
|
||||
System.setProperty(Config.PREFIX + Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE, "true")
|
||||
}
|
||||
|
||||
def cleanupSpec() {
|
||||
redisServer.stop()
|
||||
// jedis.close() // not available in the early version we're using.
|
||||
|
||||
System.clearProperty(Config.PREFIX + Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE)
|
||||
}
|
||||
|
||||
def setup() {
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.mongodb.client.MongoCollection
|
|||
import com.mongodb.client.MongoDatabase
|
||||
import datadog.opentracing.DDSpan
|
||||
import datadog.trace.agent.test.asserts.TraceAssert
|
||||
import datadog.trace.api.Config
|
||||
import datadog.trace.api.DDSpanTypes
|
||||
import io.opentracing.tag.Tags
|
||||
import org.bson.BsonDocument
|
||||
|
@ -13,6 +14,7 @@ import org.bson.BsonString
|
|||
import org.bson.Document
|
||||
import spock.lang.Shared
|
||||
|
||||
import static datadog.trace.agent.test.utils.ConfigUtils.withConfigOverride
|
||||
import static datadog.trace.agent.test.utils.PortUtils.UNUSABLE_PORT
|
||||
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
|
||||
|
||||
|
@ -38,18 +40,21 @@ class MongoClientTest extends MongoBaseTest {
|
|||
MongoDatabase db = client.getDatabase(dbName)
|
||||
|
||||
when:
|
||||
db.createCollection(collectionName)
|
||||
withConfigOverride(Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE, "$renameService") {
|
||||
db.createCollection(collectionName)
|
||||
}
|
||||
|
||||
then:
|
||||
assertTraces(1) {
|
||||
trace(0, 1) {
|
||||
mongoSpan(it, 0, "{\"create\":\"$collectionName\",\"capped\":\"?\"}")
|
||||
mongoSpan(it, 0, "{\"create\":\"$collectionName\",\"capped\":\"?\"}", renameService)
|
||||
}
|
||||
}
|
||||
|
||||
where:
|
||||
dbName = "test_db"
|
||||
collectionName = "testCollection"
|
||||
renameService << [false, true]
|
||||
}
|
||||
|
||||
def "test create collection no description"() {
|
||||
|
@ -62,7 +67,7 @@ class MongoClientTest extends MongoBaseTest {
|
|||
then:
|
||||
assertTraces(1) {
|
||||
trace(0, 1) {
|
||||
mongoSpan(it, 0, "{\"create\":\"$collectionName\",\"capped\":\"?\"}", dbName)
|
||||
mongoSpan(it, 0, "{\"create\":\"$collectionName\",\"capped\":\"?\"}", false, dbName)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,9 +233,9 @@ class MongoClientTest extends MongoBaseTest {
|
|||
collectionName = "testCollection"
|
||||
}
|
||||
|
||||
def mongoSpan(TraceAssert trace, int index, String statement, String instance = "some-description", Object parentSpan = null, Throwable exception = null) {
|
||||
def mongoSpan(TraceAssert trace, int index, String statement, boolean renameService = false, String instance = "some-description", Object parentSpan = null, Throwable exception = null) {
|
||||
trace.span(index) {
|
||||
serviceName "mongo"
|
||||
serviceName renameService ? instance : "mongo"
|
||||
operationName "mongo.query"
|
||||
resourceName {
|
||||
assert it.replace(" ", "") == statement
|
||||
|
|
|
@ -3,6 +3,7 @@ package datadog.trace.instrumentation.spymemcached
|
|||
import com.google.common.util.concurrent.MoreExecutors
|
||||
import datadog.trace.agent.test.AgentTestRunner
|
||||
import datadog.trace.agent.test.asserts.TraceAssert
|
||||
import datadog.trace.api.Config
|
||||
import datadog.trace.api.DDSpanTypes
|
||||
import io.opentracing.tag.Tags
|
||||
import net.spy.memcached.CASResponse
|
||||
|
@ -71,12 +72,17 @@ class SpymemcachedTest extends AgentTestRunner {
|
|||
memcachedContainer.getMappedPort(defaultMemcachedPort)
|
||||
)
|
||||
}
|
||||
|
||||
// This setting should have no effect since decorator returns null for the instance.
|
||||
System.setProperty(Config.PREFIX + Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE, "true")
|
||||
}
|
||||
|
||||
def cleanupSpec() {
|
||||
if (memcachedContainer) {
|
||||
memcachedContainer.stop()
|
||||
}
|
||||
|
||||
System.clearProperty(Config.PREFIX + Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE)
|
||||
}
|
||||
|
||||
ReentrantLock queueLock
|
||||
|
|
Loading…
Reference in New Issue