Skip to content

Commit c9ef01a

Browse files
authored
Merge branch 'master' into mario.vidal/taint_tracking_string_builder_append
2 parents 4eb61ee + 7c67b63 commit c9ef01a

File tree

603 files changed

+5058
-2306
lines changed

Some content is hidden

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

603 files changed

+5058
-2306
lines changed

.circleci/collect_results.sh

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,30 @@ set -e
77
#Enable '**' support
88
shopt -s globstar
99

10-
TEST_RESULTS_DIR=./results
11-
mkdir -p $TEST_RESULTS_DIR >/dev/null 2>&1
12-
10+
TEST_RESULTS_DIR=results
11+
WORKSPACE_DIR=workspace
1312
mkdir -p $TEST_RESULTS_DIR
13+
mkdir -p $WORKSPACE_DIR
1414

15-
mkdir -p workspace
16-
mapfile -t test_result_dirs < <(find workspace -name test-results -type d)
15+
mapfile -t TEST_RESULT_DIRS < <(find $WORKSPACE_DIR -name test-results -type d)
1716

18-
if [[ ${#test_result_dirs[@]} -eq 0 ]]; then
17+
if [[ ${#TEST_RESULT_DIRS[@]} -eq 0 ]]; then
1918
echo "No test results found"
2019
exit 0
2120
fi
2221

23-
echo "saving test results"
24-
find "${test_result_dirs[@]}" -name \*.xml -exec sh -c '
25-
file=$(echo "$0" | rev | cut -d "/" -f 1,2,5 | rev | tr "/" "_")
26-
cp "$0" "$1/$file"' {} $TEST_RESULTS_DIR \;
22+
echo "Saving test results:"
23+
while IFS= read -r -d '' RESULT_XML_FILE
24+
do
25+
echo -n "- $RESULT_XML_FILE"
26+
AGGREGATED_FILE_NAME=$(echo "$RESULT_XML_FILE" | rev | cut -d "/" -f 1,2,5 | rev | tr "/" "_")
27+
echo -n " as $AGGREGATED_FILE_NAME"
28+
cp "$RESULT_XML_FILE" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
29+
# Replace Java Object hashCode by marker in testcase XML nodes to get stable test names
30+
sed -i '/<testcase/ s/@[0-9a-f]\{5,\}/@HASHCODE/g' "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
31+
if cmp -s "$RESULT_XML_FILE" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"; then
32+
echo ""
33+
else
34+
echo " (hashCode replaced)"
35+
fi
36+
done < <(find "${TEST_RESULT_DIRS[@]}" -name \*.xml -print0)

buildSrc/call-site-instrumentation-plugin/src/main/java/datadog/trace/plugin/csi/impl/AdviceGeneratorImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,10 @@ private static void writeAdviceMethodCall(
344344
final MethodCallExpr invokeStatic =
345345
new MethodCallExpr()
346346
.setScope(new NameExpr("handler"))
347-
.setName("method")
348-
.addArgument(opCode("INVOKESTATIC"))
347+
.setName("advice")
349348
.addArgument(new StringLiteralExpr(method.getOwner().getInternalName()))
350349
.addArgument(new StringLiteralExpr(method.getMethodName()))
351-
.addArgument(new StringLiteralExpr(method.getMethodType().getDescriptor()))
352-
.addArgument(new BooleanLiteralExpr(false));
350+
.addArgument(new StringLiteralExpr(method.getMethodType().getDescriptor()));
353351
body.addStatement(invokeStatic);
354352
}
355353
if (requiresCast(advice)) {

buildSrc/call-site-instrumentation-plugin/src/test/groovy/datadog/trace/plugin/csi/impl/AdviceGeneratorTest.groovy

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ final class AdviceGeneratorTest extends BaseCsiPluginTest {
4747
pointcut('java/security/MessageDigest', 'getInstance', '(Ljava/lang/String;)Ljava/security/MessageDigest;')
4848
statements(
4949
'handler.dupParameters(descriptor, StackDupMode.COPY);',
50-
'handler.method(Opcodes.INVOKESTATIC, "datadog/trace/plugin/csi/impl/AdviceGeneratorTest$BeforeAdvice", "before", "(Ljava/lang/String;)V", false);',
50+
'handler.advice("datadog/trace/plugin/csi/impl/AdviceGeneratorTest$BeforeAdvice", "before", "(Ljava/lang/String;)V");',
5151
'handler.method(opcode, owner, name, descriptor, isInterface);'
5252
)
5353
}
@@ -78,7 +78,7 @@ final class AdviceGeneratorTest extends BaseCsiPluginTest {
7878
advices(0) {
7979
pointcut('java/lang/String', 'replaceAll', '(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;')
8080
statements(
81-
'handler.method(Opcodes.INVOKESTATIC, "datadog/trace/plugin/csi/impl/AdviceGeneratorTest$AroundAdvice", "around", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);'
81+
'handler.advice("datadog/trace/plugin/csi/impl/AdviceGeneratorTest$AroundAdvice", "around", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");'
8282
)
8383
}
8484
}
@@ -110,7 +110,7 @@ final class AdviceGeneratorTest extends BaseCsiPluginTest {
110110
statements(
111111
'handler.dupInvoke(owner, descriptor, StackDupMode.COPY);',
112112
'handler.method(opcode, owner, name, descriptor, isInterface);',
113-
'handler.method(Opcodes.INVOKESTATIC, "datadog/trace/plugin/csi/impl/AdviceGeneratorTest$AfterAdvice", "after", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);',
113+
'handler.advice("datadog/trace/plugin/csi/impl/AdviceGeneratorTest$AfterAdvice", "after", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");',
114114
)
115115
}
116116
}
@@ -142,7 +142,7 @@ final class AdviceGeneratorTest extends BaseCsiPluginTest {
142142
statements(
143143
'handler.dupParameters(descriptor, StackDupMode.PREPEND_ARRAY_CTOR);',
144144
'handler.method(opcode, owner, name, descriptor, isInterface);',
145-
'handler.method(Opcodes.INVOKESTATIC, "datadog/trace/plugin/csi/impl/AdviceGeneratorTest$AfterAdviceCtor", "after", "([Ljava/lang/Object;Ljava/net/URL;)Ljava/net/URL;", false);',
145+
'handler.advice("datadog/trace/plugin/csi/impl/AdviceGeneratorTest$AfterAdviceCtor", "after", "([Ljava/lang/Object;Ljava/net/URL;)Ljava/net/URL;");',
146146
)
147147
}
148148
}
@@ -208,7 +208,7 @@ final class AdviceGeneratorTest extends BaseCsiPluginTest {
208208
statements(
209209
'handler.dupParameters(descriptor, StackDupMode.PREPEND_ARRAY);',
210210
'handler.invokeDynamic(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);',
211-
'handler.method(Opcodes.INVOKESTATIC, "datadog/trace/plugin/csi/impl/AdviceGeneratorTest$InvokeDynamicAfterAdvice", "after", "([Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;", false);'
211+
'handler.advice("datadog/trace/plugin/csi/impl/AdviceGeneratorTest$InvokeDynamicAfterAdvice", "after", "([Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;");'
212212
)
213213
}
214214
}
@@ -297,7 +297,7 @@ final class AdviceGeneratorTest extends BaseCsiPluginTest {
297297
'handler.dupParameters(descriptor, StackDupMode.PREPEND_ARRAY);',
298298
'handler.invokeDynamic(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);',
299299
'handler.loadConstantArray(bootstrapMethodArguments);',
300-
'handler.method(Opcodes.INVOKESTATIC, "datadog/trace/plugin/csi/impl/AdviceGeneratorTest$InvokeDynamicWithConstantsAdvice", "after", "([Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", false);'
300+
'handler.advice("datadog/trace/plugin/csi/impl/AdviceGeneratorTest$InvokeDynamicWithConstantsAdvice", "after", "([Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");'
301301
)
302302
}
303303
}
@@ -393,7 +393,7 @@ final class AdviceGeneratorTest extends BaseCsiPluginTest {
393393
statements(
394394
'int[] parameterIndices = new int[] { 0 };',
395395
'handler.dupParameters(descriptor, parameterIndices, owner);',
396-
'handler.method(Opcodes.INVOKESTATIC, "datadog/trace/plugin/csi/impl/AdviceGeneratorTest$PartialArgumentsBeforeAdvice", "before", "(Ljava/lang/String;)V", false);',
396+
'handler.advice("datadog/trace/plugin/csi/impl/AdviceGeneratorTest$PartialArgumentsBeforeAdvice", "before", "(Ljava/lang/String;)V");',
397397
'handler.method(opcode, owner, name, descriptor, isInterface);',
398398
)
399399
}
@@ -402,7 +402,7 @@ final class AdviceGeneratorTest extends BaseCsiPluginTest {
402402
statements(
403403
'int[] parameterIndices = new int[] { 1 };',
404404
'handler.dupParameters(descriptor, parameterIndices, null);',
405-
'handler.method(Opcodes.INVOKESTATIC, "datadog/trace/plugin/csi/impl/AdviceGeneratorTest$PartialArgumentsBeforeAdvice", "before", "([Ljava/lang/Object;)V", false);',
405+
'handler.advice("datadog/trace/plugin/csi/impl/AdviceGeneratorTest$PartialArgumentsBeforeAdvice", "before", "([Ljava/lang/Object;)V");',
406406
'handler.method(opcode, owner, name, descriptor, isInterface);',
407407
)
408408
}
@@ -411,7 +411,7 @@ final class AdviceGeneratorTest extends BaseCsiPluginTest {
411411
statements(
412412
'int[] parameterIndices = new int[] { 0 };',
413413
'handler.dupInvoke(owner, descriptor, parameterIndices);',
414-
'handler.method(Opcodes.INVOKESTATIC, "datadog/trace/plugin/csi/impl/AdviceGeneratorTest$PartialArgumentsBeforeAdvice", "before", "(Ljava/lang/String;I)V", false);',
414+
'handler.advice("datadog/trace/plugin/csi/impl/AdviceGeneratorTest$PartialArgumentsBeforeAdvice", "before", "(Ljava/lang/String;I)V");',
415415
'handler.method(opcode, owner, name, descriptor, isInterface);',
416416
)
417417
}
@@ -443,7 +443,7 @@ final class AdviceGeneratorTest extends BaseCsiPluginTest {
443443
statements(
444444
'handler.dupParameters(descriptor, StackDupMode.PREPEND_ARRAY_CTOR);',
445445
'handler.method(opcode, owner, name, descriptor, isInterface);',
446-
'handler.method(Opcodes.INVOKESTATIC, "datadog/trace/plugin/csi/impl/AdviceGeneratorTest$SuperTypeReturnAdvice", "after", "([Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", false);',
446+
'handler.advice("datadog/trace/plugin/csi/impl/AdviceGeneratorTest$SuperTypeReturnAdvice", "after", "([Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");',
447447
'handler.instruction(Opcodes.CHECKCAST, "java/lang/StringBuilder");'
448448
)
449449
}

buildSrc/src/main/groovy/InstrumentPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class InstrumentPlugin implements Plugin<Project> {
3535
InstrumentExtension extension = project.extensions.create('instrument', InstrumentExtension)
3636

3737
project.tasks.matching {
38-
it.name in ['compileJava', 'compileScala', 'compileKotlin'] ||
38+
it.name in ['compileJava', 'compileScala', 'compileKotlin', 'compileGroovy'] ||
3939
it.name =~ /compileMain_.+Java/
4040
}.all {
4141
AbstractCompile compileTask = it as AbstractCompile

communication/gradle.lockfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ch.qos.logback:logback-core:1.2.3=testCompileClasspath,testRuntimeClasspath
88
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
11-
com.datadoghq:dd-javac-plugin-client:0.1.7=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
11+
com.datadoghq:dd-javac-plugin-client:0.2.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1212
com.datadoghq:java-dogstatsd-client:4.4.0=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

dd-java-agent/agent-bootstrap/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies {
2121
api project(':internal-api')
2222
api project(':internal-api:internal-api-9')
2323
api project(':dd-java-agent:agent-logging')
24+
api project(':dd-java-agent:agent-debugger:debugger-bootstrap')
2425
api libs.slf4j
2526
// ^ Generally a bad idea for libraries, but we're shadowing.
2627

dd-java-agent/agent-bootstrap/gradle.lockfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ com.beust:jcommander:1.78=jmhRuntimeClasspath,testRuntimeClasspath
99
com.blogspot.mydailyjava:weak-lock-free:0.17=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
1010
com.datadoghq.okhttp3:okhttp:3.12.15=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
1111
com.datadoghq.okio:okio:1.17.6=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
12-
com.datadoghq:dd-javac-plugin-client:0.1.7=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,main_java11CompileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
12+
com.datadoghq:dd-javac-plugin-client:0.2.2=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,main_java11CompileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1313
com.datadoghq:java-dogstatsd-client:4.4.0=jmhRuntimeClasspath,testRuntimeClasspath
1414
com.datadoghq:sketches-java:0.8.3=jmhRuntimeClasspath,testRuntimeClasspath
1515
com.github.javaparser:javaparser-core:3.25.1=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
@@ -39,7 +39,7 @@ commons-fileupload:commons-fileupload:1.5=jmhRuntimeClasspath,testCompileClasspa
3939
commons-io:commons-io:2.11.0=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
4040
de.thetaphi:forbiddenapis:3.1=compileClasspath,jmhCompileClasspath
4141
info.picocli:picocli:4.6.3=jmhRuntimeClasspath,testRuntimeClasspath
42-
io.sqreen:libsqreen:11.1.0=jmhRuntimeClasspath,testRuntimeClasspath
42+
io.sqreen:libsqreen:11.2.0=jmhRuntimeClasspath,testRuntimeClasspath
4343
javax.servlet:javax.servlet-api:3.1.0=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
4444
jaxen:jaxen:1.2.0=spotbugs
4545
jline:jline:2.14.6=jmhRuntimeClasspath,testRuntimeClasspath
Lines changed: 9 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,27 @@
11
package datadog.trace.bootstrap.instrumentation.decorator;
22

3-
import static java.util.Collections.singletonList;
4-
53
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
6-
import java.util.concurrent.CompletableFuture;
7-
import java.util.concurrent.CompletionException;
8-
import java.util.concurrent.CompletionStage;
9-
import java.util.concurrent.CopyOnWriteArrayList;
10-
import java.util.concurrent.ExecutionException;
11-
import java.util.function.BiConsumer;
4+
import datadog.trace.bootstrap.instrumentation.java.concurrent.AsyncResultExtension;
5+
import datadog.trace.bootstrap.instrumentation.java.concurrent.AsyncResultExtensions;
126

137
/**
148
* This decorator handles asynchronous result types, finishing spans only when the async calls are
15-
* complete. The different async types are supported using {@link AsyncResultSupportExtension} that
16-
* should be registered using {@link #registerExtension(AsyncResultSupportExtension)} first.
9+
* complete. The different async types are supported using {@link AsyncResultExtension} that should
10+
* be registered using {@link AsyncResultExtensions#register(AsyncResultExtension)} first.
1711
*/
1812
public abstract class AsyncResultDecorator extends BaseDecorator {
19-
private static final CopyOnWriteArrayList<AsyncResultSupportExtension> EXTENSIONS =
20-
new CopyOnWriteArrayList<>(
21-
singletonList(new JavaUtilConcurrentAsyncResultSupportExtension()));
2213

23-
private static final ClassValue<AsyncResultSupportExtension> EXTENSION_CLASS_VALUE =
24-
new ClassValue<AsyncResultSupportExtension>() {
14+
private static final ClassValue<AsyncResultExtension> EXTENSION_CLASS_VALUE =
15+
new ClassValue<AsyncResultExtension>() {
2516
@Override
26-
protected AsyncResultSupportExtension computeValue(Class<?> type) {
27-
return EXTENSIONS.stream()
17+
protected AsyncResultExtension computeValue(Class<?> type) {
18+
return AsyncResultExtensions.registered().stream()
2819
.filter(extension -> extension.supports(type))
2920
.findFirst()
3021
.orElse(null);
3122
}
3223
};
3324

34-
/**
35-
* Registers an extension to add supported async types.
36-
*
37-
* @param extension The extension to register.
38-
*/
39-
public static void registerExtension(AsyncResultSupportExtension extension) {
40-
if (extension != null) {
41-
EXTENSIONS.add(extension);
42-
}
43-
}
44-
4525
/**
4626
* Look for asynchronous result and decorate it with span finisher. If the result is not
4727
* asynchronous, it will be return unmodified and span will be finished.
@@ -53,7 +33,7 @@ public static void registerExtension(AsyncResultSupportExtension extension) {
5333
*/
5434
public Object wrapAsyncResultOrFinishSpan(
5535
final Object result, final Class<?> methodReturnType, final AgentSpan span) {
56-
AsyncResultSupportExtension extension;
36+
AsyncResultExtension extension;
5737
if (result != null && (extension = EXTENSION_CLASS_VALUE.get(methodReturnType)) != null) {
5838
Object applied = extension.apply(result, span);
5939
if (applied != null) {
@@ -64,63 +44,4 @@ public Object wrapAsyncResultOrFinishSpan(
6444
span.finish();
6545
return result;
6646
}
67-
68-
/**
69-
* This interface defines asynchronous result type support extension. It allows deferring the
70-
* support implementations where types are available on classpath.
71-
*/
72-
public interface AsyncResultSupportExtension {
73-
/**
74-
* Checks whether this extensions support a result type.
75-
*
76-
* @param result The result type to check.
77-
* @return {@code true} if the type is supported by this extension, {@code false} otherwise.
78-
*/
79-
boolean supports(Class<?> result);
80-
81-
/**
82-
* Applies the extension to the async result.
83-
*
84-
* @param result The async result.
85-
* @param span The related span.
86-
* @return The result object to return (can be the original result if not modified), or {@code
87-
* null} if the extension could not be applied.
88-
*/
89-
Object apply(Object result, AgentSpan span);
90-
}
91-
92-
private static class JavaUtilConcurrentAsyncResultSupportExtension
93-
implements AsyncResultSupportExtension {
94-
@Override
95-
public boolean supports(Class<?> result) {
96-
return CompletableFuture.class.isAssignableFrom(result)
97-
|| CompletionStage.class.isAssignableFrom(result);
98-
}
99-
100-
@Override
101-
public Object apply(Object result, AgentSpan span) {
102-
if (result instanceof CompletableFuture<?>) {
103-
CompletableFuture<?> completableFuture = (CompletableFuture<?>) result;
104-
if (!completableFuture.isDone() && !completableFuture.isCancelled()) {
105-
return completableFuture.whenComplete(finishSpan(span));
106-
}
107-
} else if (result instanceof CompletionStage<?>) {
108-
CompletionStage<?> completionStage = (CompletionStage<?>) result;
109-
return completionStage.whenComplete(finishSpan(span));
110-
}
111-
return null;
112-
}
113-
114-
private <T> BiConsumer<T, Throwable> finishSpan(AgentSpan span) {
115-
return (o, throwable) -> {
116-
if (throwable != null) {
117-
span.addThrowable(
118-
throwable instanceof ExecutionException || throwable instanceof CompletionException
119-
? throwable.getCause()
120-
: throwable);
121-
}
122-
span.finish();
123-
};
124-
}
125-
}
12647
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package datadog.trace.bootstrap.instrumentation.java.concurrent;
2+
3+
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
4+
5+
/**
6+
* This interface defines asynchronous result type support extension. It allows deferring the
7+
* support implementations where types are available on classpath.
8+
*/
9+
public interface AsyncResultExtension {
10+
/**
11+
* Checks whether this extensions support a result type.
12+
*
13+
* @param result The result type to check.
14+
* @return {@code true} if the type is supported by this extension, {@code false} otherwise.
15+
*/
16+
boolean supports(Class<?> result);
17+
18+
/**
19+
* Applies the extension to the async result.
20+
*
21+
* @param result The async result.
22+
* @param span The related span.
23+
* @return The result object to return (can be the original result if not modified), or {@code
24+
* null} if the extension could not be applied.
25+
*/
26+
Object apply(Object result, AgentSpan span);
27+
}

0 commit comments

Comments
 (0)