Skip to content

Commit 6b34d40

Browse files
authored
Merge branch 'master' into alejandro.gonzalez/fix-resourceName-bug
2 parents 0e054ef + 35cee76 commit 6b34d40

35 files changed

Lines changed: 550 additions & 471 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ out/
6060

6161
# Others #
6262
##########
63+
/dumps
6364
/logs/*
6465
/bin
6566
/out

buildSrc/call-site-instrumentation-plugin/src/test/java/datadog/trace/plugin/csi/impl/TypeResolverPoolTest.java

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,86 +11,57 @@
1111

1212
class TypeResolverPoolTest {
1313

14+
TypeResolverPool resolver = new TypeResolverPool();
15+
1416
@Test
1517
void testResolvePrimitive() {
16-
TypeResolverPool resolver = new TypeResolverPool();
17-
18-
Class<?> result = resolver.resolveType(Type.INT_TYPE);
19-
20-
assertEquals(int.class, result);
18+
assertEquals(int.class, resolver.resolveType(Type.INT_TYPE));
2119
}
2220

2321
@Test
2422
void testResolvePrimitiveArray() {
25-
TypeResolverPool resolver = new TypeResolverPool();
2623
Type type = Type.getType("[I");
27-
28-
Class<?> result = resolver.resolveType(type);
29-
30-
assertEquals(int[].class, result);
24+
assertEquals(int[].class, resolver.resolveType(type));
3125
}
3226

3327
@Test
3428
void testResolvePrimitiveMultidimensionalArray() {
35-
TypeResolverPool resolver = new TypeResolverPool();
3629
Type type = Type.getType("[[[I");
37-
38-
Class<?> result = resolver.resolveType(type);
39-
40-
assertEquals(int[][][].class, result);
30+
assertEquals(int[][][].class, resolver.resolveType(type));
4131
}
4232

4333
@Test
4434
void testResolveClass() {
45-
TypeResolverPool resolver = new TypeResolverPool();
4635
Type type = Type.getType(String.class);
47-
48-
Class<?> result = resolver.resolveType(type);
49-
50-
assertEquals(String.class, result);
36+
assertEquals(String.class, resolver.resolveType(type));
5137
}
5238

5339
@Test
5440
void testResolveClassArray() {
55-
TypeResolverPool resolver = new TypeResolverPool();
5641
Type type = Type.getType(String[].class);
57-
58-
Class<?> result = resolver.resolveType(type);
59-
60-
assertEquals(String[].class, result);
42+
assertEquals(String[].class, resolver.resolveType(type));
6143
}
6244

6345
@Test
6446
void testResolveClassMultidimensionalArray() {
65-
TypeResolverPool resolver = new TypeResolverPool();
6647
Type type = Type.getType(String[][][].class);
67-
68-
Class<?> result = resolver.resolveType(type);
69-
70-
assertEquals(String[][][].class, result);
48+
assertEquals(String[][][].class, resolver.resolveType(type));
7149
}
7250

7351
@Test
7452
void testTypeResolverFromMethod() {
75-
TypeResolverPool resolver = new TypeResolverPool();
7653
Type type =
7754
Type.getMethodType(
7855
Type.getType(String[].class), Type.getType(String.class), Type.getType(String.class));
79-
80-
Class<?> result = resolver.resolveType(type.getReturnType());
81-
82-
assertEquals(String[].class, result);
56+
assertEquals(String[].class, resolver.resolveType(type.getReturnType()));
8357
}
8458

8559
@Test
8660
void testInheritedMethods() throws Exception {
87-
TypeResolverPool resolver = new TypeResolverPool();
8861
Type owner = Type.getType(HttpServletRequest.class);
8962
String name = "getParameter";
9063
Type descriptor = Type.getMethodType(Type.getType(String.class), Type.getType(String.class));
91-
9264
Method result = (Method) resolver.resolveMethod(new MethodType(owner, name, descriptor));
93-
9465
assertEquals(ServletRequest.class.getDeclaredMethod("getParameter", String.class), result);
9566
}
9667
}

buildSrc/call-site-instrumentation-plugin/src/test/java/datadog/trace/plugin/csi/impl/ext/IastExtensionTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import datadog.trace.plugin.csi.impl.assertion.CallSiteAssert;
2323
import datadog.trace.plugin.csi.impl.ext.tests.IastExtensionCallSite;
2424
import java.io.File;
25+
import java.io.IOException;
2526
import java.lang.reflect.Method;
2627
import java.nio.file.Files;
2728
import java.nio.file.Path;
@@ -46,12 +47,15 @@ class IastExtensionTest extends BaseCsiPluginTest {
4647

4748
@BeforeEach
4849
void setup() throws Exception {
49-
targetFolder = buildDir.toPath().resolve("target");
50-
Files.createDirectories(targetFolder);
51-
projectFolder = buildDir.toPath().resolve("project");
52-
Files.createDirectories(projectFolder);
53-
srcFolder = projectFolder.resolve("src/main/java");
54-
Files.createDirectories(srcFolder);
50+
targetFolder = createFolder("target");
51+
projectFolder = createFolder("project");
52+
srcFolder = createFolder("src/main/java");
53+
}
54+
55+
private Path createFolder(String folderName) throws IOException {
56+
Path folder = buildDir.toPath().resolve(folderName);
57+
Files.createDirectories(folder);
58+
return folder;
5559
}
5660

5761
@ParameterizedTest

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ commons-io:commons-io:2.20.0=spotbugs
5252
de.thetaphi:forbiddenapis:3.10=compileClasspath
5353
io.github.java-diff-utils:java-diff-utils:4.12=testRuntimeClasspath
5454
io.leangen.geantyref:geantyref:1.3.16=testRuntimeClasspath
55+
io.micrometer:micrometer-commons:1.12.0=testRuntimeClasspath
56+
io.micrometer:micrometer-observation:1.12.0=testRuntimeClasspath
5557
jakarta.annotation:jakarta.annotation-api:1.3.5=testCompileClasspath,testRuntimeClasspath
5658
jaxen:jaxen:2.0.0=spotbugs
5759
junit:junit:4.12=testCompileClasspath,testRuntimeClasspath
@@ -157,12 +159,16 @@ org.springframework.boot:spring-boot-starter-web:2.3.5.RELEASE=testCompileClassp
157159
org.springframework.boot:spring-boot-starter:2.3.5.RELEASE=testCompileClasspath,testRuntimeClasspath
158160
org.springframework.boot:spring-boot:2.3.5.RELEASE=testCompileClasspath,testRuntimeClasspath
159161
org.springframework:spring-aop:5.2.10.RELEASE=testCompileClasspath,testRuntimeClasspath
160-
org.springframework:spring-beans:5.2.10.RELEASE=testCompileClasspath,testRuntimeClasspath
162+
org.springframework:spring-beans:5.2.10.RELEASE=testCompileClasspath
163+
org.springframework:spring-beans:6.1.0=testRuntimeClasspath
161164
org.springframework:spring-context:5.2.10.RELEASE=testCompileClasspath,testRuntimeClasspath
162-
org.springframework:spring-core:5.2.10.RELEASE=testCompileClasspath,testRuntimeClasspath
165+
org.springframework:spring-core:5.2.10.RELEASE=testCompileClasspath
166+
org.springframework:spring-core:6.1.0=testRuntimeClasspath
163167
org.springframework:spring-expression:5.2.10.RELEASE=testCompileClasspath,testRuntimeClasspath
164-
org.springframework:spring-jcl:5.2.10.RELEASE=testCompileClasspath,testRuntimeClasspath
165-
org.springframework:spring-web:5.2.10.RELEASE=testCompileClasspath,testRuntimeClasspath
168+
org.springframework:spring-jcl:5.2.10.RELEASE=testCompileClasspath
169+
org.springframework:spring-jcl:6.1.0=testRuntimeClasspath
170+
org.springframework:spring-web:5.2.10.RELEASE=testCompileClasspath
171+
org.springframework:spring-web:6.1.0=testRuntimeClasspath
166172
org.springframework:spring-webmvc:5.2.10.RELEASE=testCompileClasspath,testRuntimeClasspath
167173
org.xmlresolver:xmlresolver:5.3.3=spotbugs
168174
org.yaml:snakeyaml:1.26=testCompileClasspath,testRuntimeClasspath

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/util/SpringHelper.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,50 @@
11
package com.datadog.debugger.util;
22

33
import java.lang.instrument.Instrumentation;
4+
import java.lang.reflect.Method;
5+
import java.util.regex.Matcher;
6+
import java.util.regex.Pattern;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
49

510
public class SpringHelper {
11+
private static final Logger LOGGER = LoggerFactory.getLogger(SpringHelper.class);
612

713
public static boolean isSpringUsingOnlyMethodParameters(Instrumentation inst) {
14+
try {
15+
return isSpringUsingOnlyMethodParametersSpringVersion(inst);
16+
} catch (Exception e) {
17+
LOGGER.debug("isSpringUsingOnlyMethodParameters failed for SpringVersion", e);
18+
// fallback to lookup for specific class
19+
return isSpringUsingOnlyMethodParametersSpecificClass(inst);
20+
}
21+
}
22+
23+
private static boolean isSpringUsingOnlyMethodParametersSpringVersion(Instrumentation inst) {
24+
try {
25+
// scan for getting an already loaded class and get the classloader
26+
ClassLoader springClassLoader = null;
27+
for (Class<?> clazz : inst.getAllLoadedClasses()) {
28+
if (clazz.getName().startsWith("org.springframework.core")) {
29+
springClassLoader = clazz.getClassLoader();
30+
}
31+
}
32+
if (springClassLoader == null) {
33+
throw new IllegalStateException("Cannot find Spring classloader");
34+
}
35+
Class<?> springVersionClass =
36+
Class.forName("org.springframework.core.SpringVersion", true, springClassLoader);
37+
Method m = springVersionClass.getDeclaredMethod("getVersion");
38+
String version = (String) m.invoke(null);
39+
ParsedSpringVersion springVersion = new ParsedSpringVersion(version);
40+
// if Spring version is 6.1+ only using MethodParameters
41+
return springVersion.major > 6 || (springVersion.major == 6 && springVersion.minor >= 1);
42+
} catch (Exception e) {
43+
throw new RuntimeException(e);
44+
}
45+
}
46+
47+
private static boolean isSpringUsingOnlyMethodParametersSpecificClass(Instrumentation inst) {
848
for (Class<?> clazz : inst.getAllLoadedClasses()) {
949
if ("org.springframework.web.client.RestClient".equals(clazz.getName())) {
1050
// If this class (coming from Spring web since version 6.1) is found loaded it means Spring
@@ -15,4 +55,23 @@ public static boolean isSpringUsingOnlyMethodParameters(Instrumentation inst) {
1555
// class not found, probably no Spring
1656
return false;
1757
}
58+
59+
private static class ParsedSpringVersion {
60+
private static final Pattern VERSION_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)");
61+
62+
final int major;
63+
final int minor;
64+
final int patch;
65+
66+
public ParsedSpringVersion(String strVersion) {
67+
Matcher matcher = VERSION_PATTERN.matcher(strVersion);
68+
if (matcher.find()) {
69+
major = Integer.parseInt(matcher.group(1));
70+
minor = Integer.parseInt(matcher.group(2));
71+
patch = Integer.parseInt(matcher.group(3));
72+
} else {
73+
throw new IllegalArgumentException("Cannot parse SpringVersion: " + strVersion);
74+
}
75+
}
76+
}
1877
}

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/ConfigurationUpdaterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ public void methodParametersAttribute() throws Exception {
639639
Class<?> testClass = loadClass(CLASS_NAME, buffers);
640640
if (JavaVirtualMachine.isJavaVersion(17)) {
641641
// on JDK 17 introduced Spring6 class
642-
Class<?> springClass = Class.forName("org.springframework.web.client.RestClient");
642+
Class<?> springClass = Class.forName("org.springframework.core.SpringVersion");
643643
when(inst.getAllLoadedClasses()).thenReturn(new Class[] {testClass, springClass});
644644
} else {
645645
when(inst.getAllLoadedClasses()).thenReturn(new Class[] {testClass});

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/util/SpringHelperTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,24 @@ class SpringHelperTest {
1313

1414
@Test
1515
@EnabledForJreRange(min = JRE.JAVA_17)
16-
void isSpringUsingOnlyMethodParametersTrue() throws Exception {
16+
void isSpringUsingOnlyMethodParametersTrueSpringVersion() throws Exception {
17+
Class<?> clazz = Class.forName("org.springframework.core.SpringVersion");
18+
Instrumentation inst = mock(Instrumentation.class);
19+
when(inst.getAllLoadedClasses()).thenReturn(new Class[] {clazz});
20+
assertTrue(SpringHelper.isSpringUsingOnlyMethodParameters(inst));
21+
}
22+
23+
@Test
24+
@EnabledForJreRange(min = JRE.JAVA_17)
25+
void isSpringUsingOnlyMethodParametersTrueFallback() throws Exception {
1726
Class<?> clazz = Class.forName("org.springframework.web.client.RestClient");
1827
Instrumentation inst = mock(Instrumentation.class);
1928
when(inst.getAllLoadedClasses()).thenReturn(new Class[] {clazz});
2029
assertTrue(SpringHelper.isSpringUsingOnlyMethodParameters(inst));
2130
}
2231

2332
@Test
24-
void isSpringUsingOnlyMethodParametersFalse() throws Exception {
33+
void isSpringUsingOnlyMethodParametersFalseFallback() throws Exception {
2534
Instrumentation inst = mock(Instrumentation.class);
2635
when(inst.getAllLoadedClasses()).thenReturn(new Class[0]);
2736
assertFalse(SpringHelper.isSpringUsingOnlyMethodParameters(inst));

dd-java-agent/appsec/gradle.lockfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ch.qos.logback:logback-classic:1.2.13=jmhRuntimeClasspath,testCompileClasspath,t
77
ch.qos.logback:logback-core:1.2.13=jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
88
com.datadoghq.okhttp3:okhttp:3.12.15=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
99
com.datadoghq.okio:okio:1.17.6=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
10+
com.datadoghq:dd-instrument-java:0.0.3=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
1011
com.datadoghq:dd-javac-plugin-client:0.2.2=compileClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1112
com.datadoghq:java-dogstatsd-client:4.4.3=jmhRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
1213
com.datadoghq:sketches-java:0.8.3=jmhRuntimeClasspath,runtimeClasspath,testRuntimeClasspath

dd-java-agent/ddprof-lib/gradle.lockfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
ch.qos.logback:logback-classic:1.2.13=testCompileClasspath,testRuntimeClasspath
55
ch.qos.logback:logback-core:1.2.13=testCompileClasspath,testRuntimeClasspath
66
com.datadoghq:dd-javac-plugin-client:0.2.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
7-
com.datadoghq:ddprof:1.37.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
7+
com.datadoghq:ddprof:1.38.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
88
com.github.javaparser:javaparser-core:3.25.6=codenarc
99
com.github.spotbugs:spotbugs-annotations:4.9.8=compileClasspath,spotbugs,testCompileClasspath,testRuntimeClasspath
1010
com.github.spotbugs:spotbugs:4.9.8=spotbugs

dd-java-agent/instrumentation/apache-httpcore/apache-httpcore-5.0/gradle.lockfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ org.apache.bcel:bcel:6.11.0=spotbugs
6262
org.apache.commons:commons-lang3:3.19.0=spotbugs
6363
org.apache.commons:commons-text:1.14.0=spotbugs
6464
org.apache.httpcomponents.core5:httpcore5:5.0=compileClasspath,testCompileClasspath,testRuntimeClasspath
65-
org.apache.httpcomponents.core5:httpcore5:5.4.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
65+
org.apache.httpcomponents.core5:httpcore5:5.4.2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
6666
org.apache.logging.log4j:log4j-api:2.25.2=spotbugs
6767
org.apache.logging.log4j:log4j-core:2.25.2=spotbugs
6868
org.apiguardian:apiguardian-api:1.1.2=latestDepTestCompileClasspath,testCompileClasspath

0 commit comments

Comments
 (0)