Skip to content

Commit 2e51afc

Browse files
authored
Merge pull request #2 from DataDog/master
merge from original
2 parents 833e811 + 13b794c commit 2e51afc

File tree

29 files changed

+805
-75
lines changed

29 files changed

+805
-75
lines changed

dd-java-agent/agent-jmxfetch/agent-jmxfetch.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
apply from: "${rootDir}/gradle/java.gradle"
55

66
dependencies {
7-
compile('com.datadoghq:jmxfetch:0.29.0'){
7+
compile('com.datadoghq:jmxfetch:0.30.0'){
88
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
99
exclude group: 'log4j', module: 'log4j'
1010
}

dd-java-agent/agent-jmxfetch/src/main/java/datadog/trace/agent/jmxfetch/JMXFetch.java

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ private static void run(final Config config) {
7474
final AppConfig.AppConfigBuilder configBuilder =
7575
AppConfig.builder()
7676
.action(ImmutableList.of(ACTION_COLLECT))
77+
// App should be run as daemon otherwise CLI apps would not exit once main method exits.
78+
.daemon(true)
7779
.confdDirectory(jmxFetchConfigDir)
7880
.yamlFileList(jmxFetchConfigs)
7981
.targetDirectInstances(true)

dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/ClassLoaderMatcher.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private boolean shouldSkipInstance(final ClassLoader loader) {
9595

9696
/**
9797
* TODO: this turns out to be useless with OSGi: {@code
98-
* }org.eclipse.osgi.internal.loader.BundleLoader#isRequestFromVM} returns {@code true} when
98+
* org.eclipse.osgi.internal.loader.BundleLoader#isRequestFromVM} returns {@code true} when
9999
* class loading is issued from this check and {@code false} for 'real' class loads. We should
100100
* come up with some sort of hack to avoid this problem.
101101
*/

dd-java-agent/instrumentation/couchbase-2.0/src/test/groovy/util/AbstractCouchbaseTest.groovy

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import com.couchbase.mock.CouchbaseMock
1616
import com.couchbase.mock.http.query.QueryServer
1717
import datadog.trace.agent.test.AgentTestRunner
1818
import datadog.trace.agent.test.utils.PortUtils
19+
import datadog.trace.api.Config
1920
import spock.lang.Shared
2021

2122
import java.util.concurrent.RejectedExecutionException
@@ -87,6 +88,9 @@ abstract class AbstractCouchbaseTest extends AgentTestRunner {
8788
// Cache buckets:
8889
couchbaseCluster.openBucket(bucketCouchbase.name(), bucketCouchbase.password())
8990
memcacheCluster.openBucket(bucketMemcache.name(), bucketMemcache.password())
91+
92+
// This setting should have no effect since decorator returns null for the instance.
93+
System.setProperty(Config.PREFIX + Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE, "true")
9094
}
9195

9296
private static BucketConfiguration convert(BucketSettings bucketSettings) {
@@ -112,6 +116,8 @@ abstract class AbstractCouchbaseTest extends AgentTestRunner {
112116
}
113117

114118
mock?.stop()
119+
120+
System.clearProperty(Config.PREFIX + Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE)
115121
}
116122

117123
private DefaultCouchbaseEnvironment.Builder envBuilder(BucketSettings bucketSettings) {

dd-java-agent/instrumentation/datastax-cassandra-3/src/test/groovy/CassandraClientTest.groovy

+26-20
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import com.datastax.driver.core.Session
33
import datadog.opentracing.DDSpan
44
import datadog.trace.agent.test.AgentTestRunner
55
import datadog.trace.agent.test.asserts.TraceAssert
6+
import datadog.trace.api.Config
67
import datadog.trace.api.DDSpanTypes
78
import io.opentracing.tag.Tags
89
import org.cassandraunit.utils.EmbeddedCassandraServerHelper
910
import spock.lang.Shared
1011

12+
import static datadog.trace.agent.test.utils.ConfigUtils.withConfigOverride
1113
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
1214
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
1315

@@ -44,68 +46,72 @@ class CassandraClientTest extends AgentTestRunner {
4446
setup:
4547
Session session = cluster.connect(keyspace)
4648

47-
session.execute(statement)
49+
withConfigOverride(Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE, "$renameService") {
50+
session.execute(statement)
51+
}
4852

4953
expect:
5054
assertTraces(keyspace ? 2 : 1) {
5155
if (keyspace) {
5256
trace(0, 1) {
53-
cassandraSpan(it, 0, "USE $keyspace", null)
57+
cassandraSpan(it, 0, "USE $keyspace", null, false)
5458
}
5559
}
5660
trace(keyspace ? 1 : 0, 1) {
57-
cassandraSpan(it, 0, statement, keyspace)
61+
cassandraSpan(it, 0, statement, keyspace, renameService)
5862
}
5963
}
6064

6165
cleanup:
6266
session.close()
6367

6468
where:
65-
statement | keyspace
66-
"DROP KEYSPACE IF EXISTS sync_test" | null
67-
"CREATE KEYSPACE sync_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null
68-
"CREATE TABLE sync_test.users ( id UUID PRIMARY KEY, name text )" | "sync_test"
69-
"INSERT INTO sync_test.users (id, name) values (uuid(), 'alice')" | "sync_test"
70-
"SELECT * FROM users where name = 'alice' ALLOW FILTERING" | "sync_test"
69+
statement | keyspace | renameService
70+
"DROP KEYSPACE IF EXISTS sync_test" | null | false
71+
"CREATE KEYSPACE sync_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | true
72+
"CREATE TABLE sync_test.users ( id UUID PRIMARY KEY, name text )" | "sync_test" | false
73+
"INSERT INTO sync_test.users (id, name) values (uuid(), 'alice')" | "sync_test" | false
74+
"SELECT * FROM users where name = 'alice' ALLOW FILTERING" | "sync_test" | true
7175
}
7276

7377
def "test async"() {
7478
setup:
7579
Session session = cluster.connect(keyspace)
7680
runUnderTrace("parent") {
77-
session.executeAsync(statement)
81+
withConfigOverride(Config.DB_CLIENT_HOST_SPLIT_BY_INSTANCE, "$renameService") {
82+
session.executeAsync(statement)
83+
}
7884
blockUntilChildSpansFinished(1)
7985
}
8086

8187
expect:
8288
assertTraces(keyspace ? 2 : 1) {
8389
if (keyspace) {
8490
trace(0, 1) {
85-
cassandraSpan(it, 0, "USE $keyspace", null)
91+
cassandraSpan(it, 0, "USE $keyspace", null, false)
8692
}
8793
}
8894
trace(keyspace ? 1 : 0, 2) {
8995
basicSpan(it, 0, "parent")
90-
cassandraSpan(it, 1, statement, keyspace, span(0))
96+
cassandraSpan(it, 1, statement, keyspace, renameService, span(0))
9197
}
9298
}
9399

94100
cleanup:
95101
session.close()
96102

97103
where:
98-
statement | keyspace
99-
"DROP KEYSPACE IF EXISTS async_test" | null
100-
"CREATE KEYSPACE async_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null
101-
"CREATE TABLE async_test.users ( id UUID PRIMARY KEY, name text )" | "async_test"
102-
"INSERT INTO async_test.users (id, name) values (uuid(), 'alice')" | "async_test"
103-
"SELECT * FROM users where name = 'alice' ALLOW FILTERING" | "async_test"
104+
statement | keyspace | renameService
105+
"DROP KEYSPACE IF EXISTS async_test" | null | false
106+
"CREATE KEYSPACE async_test WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3}" | null | true
107+
"CREATE TABLE async_test.users ( id UUID PRIMARY KEY, name text )" | "async_test" | false
108+
"INSERT INTO async_test.users (id, name) values (uuid(), 'alice')" | "async_test" | false
109+
"SELECT * FROM users where name = 'alice' ALLOW FILTERING" | "async_test" | true
104110
}
105111

106-
def cassandraSpan(TraceAssert trace, int index, String statement, String keyspace, Object parentSpan = null, Throwable exception = null) {
112+
def cassandraSpan(TraceAssert trace, int index, String statement, String keyspace, boolean renameService, Object parentSpan = null, Throwable exception = null) {
107113
trace.span(index) {
108-
serviceName "cassandra"
114+
serviceName renameService && keyspace ? keyspace : "cassandra"
109115
operationName "cassandra.query"
110116
resourceName statement
111117
spanType DDSpanTypes.CASSANDRA
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
muzzle {
2+
pass {
3+
group = "com.google.http-client"
4+
module = "google-http-client"
5+
6+
// 1.19.0 is the first release. The versions before are betas and RCs
7+
versions = "[1.19.0,)"
8+
}
9+
}
10+
11+
apply from: "${rootDir}/gradle/java.gradle"
12+
apply plugin: 'org.unbroken-dome.test-sets'
13+
14+
testSets {
15+
latestDepTest {
16+
dirName = 'test'
17+
}
18+
}
19+
20+
dependencies {
21+
compileOnly group: 'com.google.http-client', name: 'google-http-client', version: '1.19.0'
22+
23+
compile project(':dd-java-agent:agent-tooling')
24+
25+
compile deps.bytebuddy
26+
compile deps.opentracing
27+
annotationProcessor deps.autoservice
28+
implementation deps.autoservice
29+
30+
testCompile project(':dd-java-agent:testing')
31+
testCompile group: 'com.google.http-client', name: 'google-http-client', version: '1.19.0'
32+
33+
latestDepTestCompile group: 'com.google.http-client', name: 'google-http-client', version: '+'
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package datadog.trace.instrumentation.googlehttpclient;
2+
3+
import com.google.api.client.http.HttpRequest;
4+
import com.google.api.client.http.HttpResponse;
5+
import datadog.trace.agent.decorator.HttpClientDecorator;
6+
import java.net.URI;
7+
import java.net.URISyntaxException;
8+
9+
public class GoogleHttpClientDecorator extends HttpClientDecorator<HttpRequest, HttpResponse> {
10+
public static final GoogleHttpClientDecorator DECORATE = new GoogleHttpClientDecorator();
11+
12+
@Override
13+
protected String method(final HttpRequest httpRequest) {
14+
return httpRequest.getRequestMethod();
15+
}
16+
17+
@Override
18+
protected URI url(final HttpRequest httpRequest) throws URISyntaxException {
19+
// Google uses %20 (space) instead of "+" for spaces in the fragment
20+
// Add "+" back for consistency with the other http client instrumentations
21+
final String url = httpRequest.getUrl().build();
22+
final String fixedUrl = url.replaceAll("%20", "+");
23+
return new URI(fixedUrl);
24+
}
25+
26+
@Override
27+
protected String hostname(final HttpRequest httpRequest) {
28+
return httpRequest.getUrl().getHost();
29+
}
30+
31+
@Override
32+
protected Integer port(final HttpRequest httpRequest) {
33+
return httpRequest.getUrl().getPort();
34+
}
35+
36+
@Override
37+
protected Integer status(final HttpResponse httpResponse) {
38+
return httpResponse.getStatusCode();
39+
}
40+
41+
@Override
42+
protected String[] instrumentationNames() {
43+
return new String[] {"google-http-client"};
44+
}
45+
46+
@Override
47+
protected String component() {
48+
return "google-http-client";
49+
}
50+
}

0 commit comments

Comments
 (0)