Skip to content

Commit 8e854bf

Browse files
authored
Merge branch 'master' into jpbempel/fix-var-hoisting-rewriting
2 parents 48e1f1e + 0dc9c08 commit 8e854bf

File tree

474 files changed

+2747
-1143
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

474 files changed

+2747
-1143
lines changed

communication/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies {
2525
}
2626

2727
ext {
28-
minimumBranchCoverage = 0.6
28+
minimumBranchCoverage = 0.5
2929
minimumInstructionCoverage = 0.8
3030
excludedClassesCoverage = [
3131
'datadog.communication.ddagent.ExternalAgentLauncher',

communication/gradle.lockfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ com.beust:jcommander:1.78=testRuntimeClasspath
99
com.datadoghq.okhttp3:okhttp:3.12.15=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1010
com.datadoghq.okio:okio:1.17.6=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1111
com.datadoghq:dd-javac-plugin-client:0.2.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
12-
com.datadoghq:java-dogstatsd-client:4.4.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
12+
com.datadoghq:java-dogstatsd-client:4.4.3=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1313
com.fasterxml.jackson.core:jackson-annotations:2.9.0=testCompileClasspath,testRuntimeClasspath
1414
com.fasterxml.jackson.core:jackson-core:2.9.9=testCompileClasspath,testRuntimeClasspath
1515
com.fasterxml.jackson.core:jackson-databind:2.9.9.3=testCompileClasspath,testRuntimeClasspath

communication/src/main/java/datadog/communication/ddagent/SharedCommunicationObjects.java

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import datadog.remoteconfig.DefaultConfigurationPoller;
1212
import datadog.trace.api.Config;
1313
import datadog.trace.util.AgentTaskScheduler;
14+
import java.util.ArrayList;
15+
import java.util.List;
1416
import java.util.concurrent.TimeUnit;
1517
import java.util.function.Supplier;
1618
import okhttp3.HttpUrl;
@@ -21,12 +23,23 @@
2123
public class SharedCommunicationObjects {
2224
private static final Logger log = LoggerFactory.getLogger(SharedCommunicationObjects.class);
2325

26+
private final List<Runnable> pausedComponents = new ArrayList<>();
27+
private volatile boolean paused;
28+
2429
public OkHttpClient okHttpClient;
2530
public HttpUrl agentUrl;
2631
public Monitoring monitoring;
2732
private DDAgentFeaturesDiscovery featuresDiscovery;
2833
private ConfigurationPoller configurationPoller;
2934

35+
public SharedCommunicationObjects() {
36+
this(false);
37+
}
38+
39+
public SharedCommunicationObjects(boolean paused) {
40+
this.paused = paused;
41+
}
42+
3043
public void createRemaining(Config config) {
3144
if (monitoring == null) {
3245
monitoring = Monitoring.DISABLED;
@@ -46,6 +59,32 @@ public void createRemaining(Config config) {
4659
}
4760
}
4861

62+
public void whenReady(Runnable callback) {
63+
if (paused) {
64+
synchronized (pausedComponents) {
65+
if (paused) {
66+
pausedComponents.add(callback);
67+
return;
68+
}
69+
}
70+
}
71+
callback.run(); // not paused, run immediately
72+
}
73+
74+
public void resume() {
75+
paused = false;
76+
synchronized (pausedComponents) {
77+
for (Runnable callback : pausedComponents) {
78+
try {
79+
callback.run();
80+
} catch (Throwable e) {
81+
log.warn("Problem resuming remote component {}", callback, e);
82+
}
83+
}
84+
pausedComponents.clear();
85+
}
86+
}
87+
4988
private static HttpUrl parseAgentUrl(Config config) {
5089
String agentUrl = config.getAgentUrl();
5190
if (agentUrl.startsWith("unix:")) {
@@ -100,11 +139,16 @@ public DDAgentFeaturesDiscovery featuresDiscovery(Config config) {
100139
agentUrl,
101140
config.isTraceAgentV05Enabled(),
102141
config.isTracerMetricsEnabled());
103-
if (AGENT_THREAD_GROUP.equals(Thread.currentThread().getThreadGroup())) {
104-
featuresDiscovery.discover(); // safe to run on same thread
142+
143+
if (paused) {
144+
// defer remote discovery until remote I/O is allowed
105145
} else {
106-
// avoid performing blocking I/O operation on application thread
107-
AgentTaskScheduler.INSTANCE.execute(featuresDiscovery::discover);
146+
if (AGENT_THREAD_GROUP.equals(Thread.currentThread().getThreadGroup())) {
147+
featuresDiscovery.discover(); // safe to run on same thread
148+
} else {
149+
// avoid performing blocking I/O operation on application thread
150+
AgentTaskScheduler.INSTANCE.execute(featuresDiscovery::discover);
151+
}
108152
}
109153
}
110154
return featuresDiscovery;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
id("me.champeau.jmh")
3+
}
4+
5+
apply(from = "$rootDir/gradle/java.gradle")
6+
7+
jmh {
8+
version = "1.28"
9+
}
10+
11+
val excludedClassesInstructionCoverage by extra {
12+
listOf("datadog.context.ContextProviders") // covered by forked test
13+
}

components/context/gradle.lockfile

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# This is a Gradle generated file for dependency locking.
2+
# Manual edits can break the build and are not advised.
3+
# This file is expected to be part of source control.
4+
ch.qos.logback:logback-classic:1.2.3=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
5+
ch.qos.logback:logback-core:1.2.3=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
6+
com.beust:jcommander:1.78=jmhRuntimeClasspath,testRuntimeClasspath
7+
com.github.javaparser:javaparser-core:3.25.1=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
8+
com.github.spotbugs:spotbugs-annotations:4.2.0=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
9+
com.github.spotbugs:spotbugs-annotations:4.7.3=spotbugs
10+
com.github.spotbugs:spotbugs:4.7.3=spotbugs
11+
com.google.code.findbugs:jsr305:3.0.2=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,spotbugs,testCompileClasspath,testRuntimeClasspath
12+
com.google.code.gson:gson:2.9.1=spotbugs
13+
com.thoughtworks.qdox:qdox:1.12.1=jmhRuntimeClasspath,testRuntimeClasspath
14+
commons-codec:commons-codec:1.15=spotbugs
15+
de.thetaphi:forbiddenapis:3.1=compileClasspath,jmhCompileClasspath
16+
info.picocli:picocli:4.6.3=jmhRuntimeClasspath,testRuntimeClasspath
17+
jaxen:jaxen:1.2.0=spotbugs
18+
jline:jline:2.14.6=jmhRuntimeClasspath,testRuntimeClasspath
19+
junit:junit:4.13.2=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
20+
net.jcip:jcip-annotations:1.0=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,spotbugs,testCompileClasspath,testRuntimeClasspath
21+
net.sf.jopt-simple:jopt-simple:5.0.4=jmh,jmhCompileClasspath,jmhRuntimeClasspath
22+
net.sf.saxon:Saxon-HE:11.4=spotbugs
23+
org.apache.ant:ant-antlr:1.10.12=jmhRuntimeClasspath,testRuntimeClasspath
24+
org.apache.ant:ant-antlr:1.9.15=codenarc
25+
org.apache.ant:ant-junit:1.10.12=jmhRuntimeClasspath,testRuntimeClasspath
26+
org.apache.ant:ant-junit:1.9.15=codenarc
27+
org.apache.ant:ant-launcher:1.10.12=jmhRuntimeClasspath,testRuntimeClasspath
28+
org.apache.ant:ant:1.10.12=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
29+
org.apache.bcel:bcel:6.5.0=spotbugs
30+
org.apache.commons:commons-lang3:3.12.0=pitest,spotbugs
31+
org.apache.commons:commons-math3:3.2=jmh,jmhCompileClasspath,jmhRuntimeClasspath
32+
org.apache.commons:commons-text:1.10.0=pitest,spotbugs
33+
org.apache.httpcomponents.client5:httpclient5:5.1.3=spotbugs
34+
org.apache.httpcomponents.core5:httpcore5-h2:5.1.3=spotbugs
35+
org.apache.httpcomponents.core5:httpcore5:5.1.3=spotbugs
36+
org.apache.logging.log4j:log4j-api:2.19.0=spotbugs
37+
org.apache.logging.log4j:log4j-core:2.19.0=spotbugs
38+
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath
39+
org.codehaus.groovy:groovy-all:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
40+
org.codehaus.groovy:groovy-ant:2.5.14=codenarc
41+
org.codehaus.groovy:groovy-ant:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
42+
org.codehaus.groovy:groovy-astbuilder:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
43+
org.codehaus.groovy:groovy-cli-picocli:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
44+
org.codehaus.groovy:groovy-console:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
45+
org.codehaus.groovy:groovy-datetime:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
46+
org.codehaus.groovy:groovy-docgenerator:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
47+
org.codehaus.groovy:groovy-groovydoc:2.5.14=codenarc
48+
org.codehaus.groovy:groovy-groovydoc:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
49+
org.codehaus.groovy:groovy-groovysh:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
50+
org.codehaus.groovy:groovy-jmx:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
51+
org.codehaus.groovy:groovy-json:2.5.14=codenarc
52+
org.codehaus.groovy:groovy-json:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
53+
org.codehaus.groovy:groovy-jsr223:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
54+
org.codehaus.groovy:groovy-macro:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
55+
org.codehaus.groovy:groovy-nio:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
56+
org.codehaus.groovy:groovy-servlet:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
57+
org.codehaus.groovy:groovy-sql:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
58+
org.codehaus.groovy:groovy-swing:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
59+
org.codehaus.groovy:groovy-templates:2.5.14=codenarc
60+
org.codehaus.groovy:groovy-templates:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
61+
org.codehaus.groovy:groovy-test-junit5:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
62+
org.codehaus.groovy:groovy-test:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
63+
org.codehaus.groovy:groovy-testng:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
64+
org.codehaus.groovy:groovy-xml:2.5.14=codenarc
65+
org.codehaus.groovy:groovy-xml:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
66+
org.codehaus.groovy:groovy:2.5.14=codenarc
67+
org.codehaus.groovy:groovy:3.0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
68+
org.codenarc:CodeNarc:2.2.0=codenarc
69+
org.dom4j:dom4j:2.1.3=spotbugs
70+
org.gmetrics:GMetrics:1.1=codenarc
71+
org.hamcrest:hamcrest-core:1.3=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
72+
org.hamcrest:hamcrest:2.2=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
73+
org.jacoco:org.jacoco.agent:0.8.5=jacocoAgent,jacocoAnt
74+
org.jacoco:org.jacoco.ant:0.8.5=jacocoAnt
75+
org.jacoco:org.jacoco.core:0.8.5=jacocoAnt
76+
org.jacoco:org.jacoco.report:0.8.5=jacocoAnt
77+
org.junit.jupiter:junit-jupiter-api:5.9.2=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
78+
org.junit.jupiter:junit-jupiter-engine:5.9.2=jmhRuntimeClasspath,testRuntimeClasspath
79+
org.junit.jupiter:junit-jupiter-params:5.9.2=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
80+
org.junit.jupiter:junit-jupiter:5.9.2=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
81+
org.junit.platform:junit-platform-commons:1.9.2=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
82+
org.junit.platform:junit-platform-engine:1.9.2=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
83+
org.junit.platform:junit-platform-launcher:1.9.2=jmhRuntimeClasspath,testRuntimeClasspath
84+
org.junit:junit-bom:5.9.1=spotbugs
85+
org.junit:junit-bom:5.9.2=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
86+
org.objenesis:objenesis:3.3=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
87+
org.openjdk.jmh:jmh-core:1.36=jmh,jmhCompileClasspath,jmhRuntimeClasspath
88+
org.openjdk.jmh:jmh-generator-asm:1.36=jmh,jmhCompileClasspath,jmhRuntimeClasspath
89+
org.openjdk.jmh:jmh-generator-bytecode:1.36=jmh,jmhCompileClasspath,jmhRuntimeClasspath
90+
org.openjdk.jmh:jmh-generator-reflection:1.36=jmh,jmhCompileClasspath,jmhRuntimeClasspath
91+
org.opentest4j:opentest4j:1.2.0=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
92+
org.ow2.asm:asm-analysis:7.2=jacocoAnt
93+
org.ow2.asm:asm-analysis:9.4=spotbugs
94+
org.ow2.asm:asm-commons:7.2=jacocoAnt
95+
org.ow2.asm:asm-commons:9.4=spotbugs
96+
org.ow2.asm:asm-tree:7.2=jacocoAnt
97+
org.ow2.asm:asm-tree:9.4=spotbugs
98+
org.ow2.asm:asm-util:9.4=spotbugs
99+
org.ow2.asm:asm:7.2=jacocoAnt
100+
org.ow2.asm:asm:9.0=jmh,jmhCompileClasspath,jmhRuntimeClasspath
101+
org.ow2.asm:asm:9.4=spotbugs
102+
org.pitest:pitest-command-line:1.9.11=pitest
103+
org.pitest:pitest-entry:1.9.11=pitest
104+
org.pitest:pitest:1.9.11=pitest
105+
org.slf4j:jcl-over-slf4j:1.7.30=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
106+
org.slf4j:jul-to-slf4j:1.7.30=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
107+
org.slf4j:log4j-over-slf4j:1.7.30=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
108+
org.slf4j:slf4j-api:1.7.30=testCompileClasspath
109+
org.slf4j:slf4j-api:1.7.32=jmhRuntimeClasspath,testRuntimeClasspath
110+
org.slf4j:slf4j-api:2.0.0=spotbugs,spotbugsSlf4j
111+
org.slf4j:slf4j-simple:2.0.0=spotbugsSlf4j
112+
org.spockframework:spock-core:2.2-groovy-3.0=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
113+
org.spockframework:spock-junit4:2.2-groovy-3.0=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
114+
org.testng:testng:7.5=jmhRuntimeClasspath,testRuntimeClasspath
115+
org.webjars:jquery:3.5.1=jmhRuntimeClasspath,testRuntimeClasspath
116+
org.xmlresolver:xmlresolver:4.4.3=spotbugs
117+
xml-apis:xml-apis:1.4.01=spotbugs
118+
empty=annotationProcessor,jmhAnnotationProcessor,runtimeClasspath,spotbugsPlugins,testAnnotationProcessor
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package datadog.context;
2+
3+
import static datadog.context.ContextProviders.binder;
4+
import static datadog.context.ContextProviders.manager;
5+
6+
import javax.annotation.Nullable;
7+
import javax.annotation.ParametersAreNonnullByDefault;
8+
9+
/**
10+
* Immutable context scoped to an execution unit or carrier object.
11+
*
12+
* <p>There are three ways to get a Context instance:
13+
*
14+
* <ul>
15+
* <li>The first one is to retrieve the one from the current execution unit using {@link
16+
* #current()}. A Context instance can be marked as current using {@link #attach()} within the
17+
* execution unit.
18+
* <li>The second one is to retrieve one from a carrier object using {@link #from(Object
19+
* carrier)}. A Context instance would need to be attached to the carrier first using {@link
20+
* #attachTo(Object carrier)} attached.
21+
* <li>Finally, the third option is to get the default root Context instance calling {@link
22+
* #root()}.
23+
* </ul>
24+
*
25+
* <p>When there is no context attached to the current execution unit, {@link #current()} will
26+
* return the root context. Similarly, {@link #from(Object carrier)} will return the root context
27+
* when there is no context attached to the carrier.
28+
*
29+
* <p>From a {@link Context} instance, each value is stored and retrieved by its {@link ContextKey},
30+
* using {@link #with(ContextKey key, Object value)} to store a value (creating a new immutable
31+
* {@link Context} instance), and {@link #get(ContextKey)} to retrieve it. {@link ContextKey}s
32+
* represent product of functional areas, and should be created sparingly.
33+
*
34+
* <p>{@link Context} instances are thread safe as they are immutable (including their {@link
35+
* ContextKey}) but the value they hold may themselves be mutable.
36+
*
37+
* @see ContextKey
38+
*/
39+
@ParametersAreNonnullByDefault
40+
public interface Context {
41+
/**
42+
* Returns the root context.
43+
*
44+
* @return the initial local context that all contexts extend.
45+
*/
46+
static Context root() {
47+
return manager().root();
48+
}
49+
50+
/**
51+
* Returns the context attached to the current execution unit.
52+
*
53+
* @return the attached context; {@link #root()} if there is none.
54+
*/
55+
static Context current() {
56+
return manager().current();
57+
}
58+
59+
/**
60+
* Attaches this context to the current execution unit.
61+
*
62+
* @return a scope to be closed when the context is invalid.
63+
*/
64+
default ContextScope attach() {
65+
return manager().attach(this);
66+
}
67+
68+
/**
69+
* Swaps this context with the one attached to current execution unit.
70+
*
71+
* @return the previously attached context; {@link #root()} if there was none.
72+
*/
73+
default Context swap() {
74+
return manager().swap(this);
75+
}
76+
77+
/**
78+
* Returns the context attached to the given carrier object.
79+
*
80+
* @param carrier the carrier object to get the context from.
81+
* @return the attached context; {@link #root()} if there is none.
82+
*/
83+
static Context from(Object carrier) {
84+
return binder().from(carrier);
85+
}
86+
87+
/**
88+
* Attaches this context to the given carrier object.
89+
*
90+
* @param carrier the object to carry the context.
91+
*/
92+
default void attachTo(Object carrier) {
93+
binder().attachTo(carrier, this);
94+
}
95+
96+
/**
97+
* Detaches the context attached to the given carrier object, leaving it context-less.
98+
*
99+
* @param carrier the carrier object to detach its context from.
100+
* @return the previously attached context; {@link #root()} if there was none.
101+
*/
102+
static Context detachFrom(Object carrier) {
103+
return binder().detachFrom(carrier);
104+
}
105+
106+
/**
107+
* Gets the value stored in this context under the given key.
108+
*
109+
* @param <T> the type of the value.
110+
* @param key the key used to store the value.
111+
* @return the value stored under the key; {@code null} if there is none.
112+
*/
113+
@Nullable
114+
<T> T get(ContextKey<T> key);
115+
116+
/**
117+
* Creates a copy of this context with the given key-value set.
118+
*
119+
* <p>Existing value with the given key will be replaced, and mapping to a {@code null} value will
120+
* remove the key-value from the context copy.
121+
*
122+
* @param <T> the type of the value.
123+
* @param key the key to store the value.
124+
* @param value the value to store.
125+
* @return a new context with the key-value set.
126+
*/
127+
<T> Context with(ContextKey<T> key, @Nullable T value);
128+
129+
/**
130+
* Creates a copy of this context with the implicit key is mapped to the value.
131+
*
132+
* @param value the value to store.
133+
* @return a new context with the implicitly keyed value set.
134+
* @see #with(ContextKey, Object)
135+
*/
136+
default Context with(@Nullable ImplicitContextKeyed value) {
137+
if (value == null) {
138+
return root();
139+
}
140+
return value.storeInto(this);
141+
}
142+
}

0 commit comments

Comments
 (0)