Skip to content

Commit 8ce24d6

Browse files
authored
Merge branch 'master' into andrea.marziali/swap-messaging
2 parents 672de2a + c04d61b commit 8ce24d6

46 files changed

Lines changed: 200 additions & 168 deletions

File tree

Some content is hidden

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

.claude/skills/migrate-groovy-to-java/SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Migrate test Groovy files to Java using JUnit 5
1414
When converting Groovy code to Java code, make sure that:
1515
- The Java code generated is compatible with JDK 8
1616
- When translating Spock tests, favor using `@CsvSource` with `|` delimiters
17-
- When using `@MethodSource`, name the arguments method by appending `Arguments` using camelCase to the test method name (e.g. `testMethodArguments`)
18-
- Ensure parameterized test names are human-readable (i.e. no hashcodes); instead add a description string as the first `Arguments.of(...)` value or index the test case
17+
- When using `@MethodSource`, name the arguments method by appending `Arguments` using camelCase to the test method name (e.g. `testMethodArguments`) and return a `Stream` of arguments using `Stream.of(...)` and `arguments(...)` with static import.
18+
- Ensure parameterized test names are human-readable (i.e. no hashcodes); instead add a description string as the first `Arguments.arguments(...)` value or index the test case
1919
- When converting tuples, create a light dedicated structure instead to keep the typing system
2020
- Instead of checking a state and throwing an exception, use JUnit asserts
2121
- Do not wrap checked exceptions and throw a Runtime exception; prefer adding a throws clause at method declaration

components/json/src/test/java/datadog/json/JsonMapperTest.java

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import static java.util.Collections.emptyMap;
55
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
66
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
78
import static org.junit.jupiter.api.Assertions.assertThrows;
89
import static org.junit.jupiter.api.Assertions.assertTrue;
10+
import static org.junit.jupiter.params.provider.Arguments.arguments;
911

1012
import java.io.IOException;
1113
import java.util.ArrayList;
@@ -24,7 +26,8 @@ class JsonMapperTest {
2426

2527
@ParameterizedTest(name = "test mapping to JSON object: {0}")
2628
@MethodSource("testMappingToJsonObjectArguments")
27-
void testMappingToJsonObject(String testCase, Map<String, Object> input, String expected)
29+
void testMappingToJsonObject(
30+
@SuppressWarnings("unused") String testCase, Map<String, Object> input, String expected)
2831
throws IOException {
2932
String json = JsonMapper.toJson(input);
3033
assertEquals(expected, json);
@@ -42,7 +45,7 @@ void testMappingToJsonObject(String testCase, Map<String, Object> input, String
4245
if (expectedValue instanceof UnsupportedType) {
4346
assertEquals(expectedValue.toString(), parsedValue);
4447
} else if (expectedValue instanceof Float) {
45-
assertTrue(parsedValue instanceof Double);
48+
assertInstanceOf(Double.class, parsedValue);
4649
assertEquals((Float) expectedValue, (Double) parsedValue, 0.001);
4750
} else {
4851
assertEquals(expectedValue, parsedValue);
@@ -74,15 +77,15 @@ static Stream<Arguments> testMappingToJsonObjectArguments() {
7477
complexMap.put("key8", new UnsupportedType());
7578

7679
return Stream.of(
77-
Arguments.of("null input", null, "{}"),
78-
Arguments.of("empty map", new HashMap<>(), "{}"),
79-
Arguments.of("single entry", singleEntry, "{\"key1\":\"value1\"}"),
80-
Arguments.of("two entries", twoEntries, "{\"key1\":\"value1\",\"key2\":\"value2\"}"),
81-
Arguments.of(
80+
arguments("null input", null, "{}"),
81+
arguments("empty map", new HashMap<>(), "{}"),
82+
arguments("single entry", singleEntry, "{\"key1\":\"value1\"}"),
83+
arguments("two entries", twoEntries, "{\"key1\":\"value1\",\"key2\":\"value2\"}"),
84+
arguments(
8285
"quoted entries",
8386
quotedEntries,
8487
"{\"key1\":\"va\\\"lu\\\"e1\",\"ke\\\"y2\":\"value2\"}"),
85-
Arguments.of(
88+
arguments(
8689
"complex map",
8790
complexMap,
8891
"{\"key1\":null,\"key2\":\"bar\",\"key3\":3,\"key4\":3456789123,\"key5\":3.142,\"key6\":3.141592653589793,\"key7\":true,\"key8\":\"toString\"}"));
@@ -96,8 +99,7 @@ void testMappingToMapFromEmptyJsonObject(String json) throws IOException {
9699
}
97100

98101
static Stream<Arguments> testMappingToMapFromEmptyJsonObjectArguments() {
99-
return Stream.of(
100-
Arguments.of((Object) null), Arguments.of("null"), Arguments.of(""), Arguments.of("{}"));
102+
return Stream.of(arguments((Object) null), arguments("null"), arguments(""), arguments("{}"));
101103
}
102104

103105
@ParameterizedTest(name = "test mapping to Map from non-object JSON: {0}")
@@ -118,11 +120,11 @@ void testMappingIterableToJsonArray(List<String> input, String expected) throws
118120

119121
static Stream<Arguments> testMappingIterableToJsonArrayArguments() {
120122
return Stream.of(
121-
Arguments.of(null, "[]"),
122-
Arguments.of(new ArrayList<>(), "[]"),
123-
Arguments.of(Arrays.asList("value1"), "[\"value1\"]"),
124-
Arguments.of(Arrays.asList("value1", "value2"), "[\"value1\",\"value2\"]"),
125-
Arguments.of(Arrays.asList("va\"lu\"e1", "value2"), "[\"va\\\"lu\\\"e1\",\"value2\"]"));
123+
arguments(null, "[]"),
124+
arguments(new ArrayList<>(), "[]"),
125+
arguments(Arrays.asList("value1"), "[\"value1\"]"),
126+
arguments(Arrays.asList("value1", "value2"), "[\"value1\",\"value2\"]"),
127+
arguments(Arrays.asList("va\"lu\"e1", "value2"), "[\"va\\\"lu\\\"e1\",\"value2\"]"));
126128
}
127129

128130
@ParameterizedTest(name = "test mapping array to JSON array: {0}")
@@ -138,11 +140,11 @@ void testMappingArrayToJsonArray(String testCase, String[] input, String expecte
138140

139141
static Stream<Arguments> testMappingArrayToJsonArrayArguments() {
140142
return Stream.of(
141-
Arguments.of("null input", (Object) null, "[]"),
142-
Arguments.of("empty array", new String[] {}, "[]"),
143-
Arguments.of("single element", new String[] {"value1"}, "[\"value1\"]"),
144-
Arguments.of("two elements", new String[] {"value1", "value2"}, "[\"value1\",\"value2\"]"),
145-
Arguments.of(
143+
arguments("null input", (Object) null, "[]"),
144+
arguments("empty array", new String[] {}, "[]"),
145+
arguments("single element", new String[] {"value1"}, "[\"value1\"]"),
146+
arguments("two elements", new String[] {"value1", "value2"}, "[\"value1\",\"value2\"]"),
147+
arguments(
146148
"escaped quotes",
147149
new String[] {"va\"lu\"e1", "value2"},
148150
"[\"va\\\"lu\\\"e1\",\"value2\"]"));
@@ -156,8 +158,7 @@ void testMappingToListFromEmptyJsonObject(String json) throws IOException {
156158
}
157159

158160
static Stream<Arguments> testMappingToListFromEmptyJsonObjectArguments() {
159-
return Stream.of(
160-
Arguments.of((Object) null), Arguments.of("null"), Arguments.of(""), Arguments.of("[]"));
161+
return Stream.of(arguments((Object) null), arguments("null"), arguments(""), arguments("[]"));
161162
}
162163

163164
@ParameterizedTest(name = "test mapping to JSON string: {0}")
@@ -169,20 +170,20 @@ void testMappingToJsonString(String input, String expected) {
169170

170171
static Stream<Arguments> testMappingToJsonStringArguments() {
171172
return Stream.of(
172-
Arguments.of((Object) null, ""),
173-
Arguments.of("", ""),
174-
Arguments.of(String.valueOf((char) 4096), "\"\\u1000\""),
175-
Arguments.of(String.valueOf((char) 256), "\"\\u0100\""),
176-
Arguments.of(String.valueOf((char) 128), "\"\\u0080\""),
177-
Arguments.of("\b", "\"\\b\""),
178-
Arguments.of("\t", "\"\\t\""),
179-
Arguments.of("\n", "\"\\n\""),
180-
Arguments.of("\f", "\"\\f\""),
181-
Arguments.of("\r", "\"\\r\""),
182-
Arguments.of("\"", "\"\\\"\""),
183-
Arguments.of("/", "\"\\/\""),
184-
Arguments.of("\\", "\"\\\\\""),
185-
Arguments.of("a", "\"a\""));
173+
arguments((Object) null, ""),
174+
arguments("", ""),
175+
arguments(String.valueOf((char) 4096), "\"\\u1000\""),
176+
arguments(String.valueOf((char) 256), "\"\\u0100\""),
177+
arguments(String.valueOf((char) 128), "\"\\u0080\""),
178+
arguments("\b", "\"\\b\""),
179+
arguments("\t", "\"\\t\""),
180+
arguments("\n", "\"\\n\""),
181+
arguments("\f", "\"\\f\""),
182+
arguments("\r", "\"\\r\""),
183+
arguments("\"", "\"\\\"\""),
184+
arguments("/", "\"\\/\""),
185+
arguments("\\", "\"\\\\\""),
186+
arguments("a", "\"a\""));
186187
}
187188

188189
private static class UnsupportedType {

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/JsonSnapshotSerializer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
import datadog.trace.api.ProcessTags;
1010
import datadog.trace.bootstrap.debugger.CapturedContext;
1111
import datadog.trace.bootstrap.debugger.DebuggerContext;
12+
import java.time.Duration;
13+
import java.time.temporal.ChronoUnit;
1214

1315
/** Serializes snapshots in Json using Moshi */
1416
public class JsonSnapshotSerializer implements DebuggerContext.ValueSerializer {
1517
private static final JsonAdapter<IntakeRequest> ADAPTER =
16-
MoshiHelper.createMoshiSnapshot().adapter(IntakeRequest.class);
18+
MoshiHelper.createMoshiSnapshot(
19+
Duration.of(
20+
Config.get().getDynamicInstrumentationCaptureTimeout(), ChronoUnit.MILLIS))
21+
.adapter(IntakeRequest.class);
1722
private static final JsonAdapter<CapturedContext.CapturedValue> VALUE_ADAPTER =
1823
new MoshiSnapshotHelper.CapturedValueAdapter();
1924

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.squareup.moshi.Types;
1212
import datadog.trace.bootstrap.debugger.el.DebuggerScript;
1313
import java.lang.reflect.ParameterizedType;
14+
import java.time.Duration;
1415
import java.util.Map;
1516

1617
/** Helper for creating Moshi instances with the right adapters depending on the context */
@@ -32,9 +33,9 @@ public static Moshi.Builder createMoshiConfigBuilder() {
3233
.add(ProbeDefinition.Tag[].class, new ProbeDefinition.TagAdapter());
3334
}
3435

35-
public static Moshi createMoshiSnapshot() {
36+
public static Moshi createMoshiSnapshot(Duration captureTimeOut) {
3637
return new Moshi.Builder()
37-
.add(new MoshiSnapshotHelper.SnapshotJsonFactory())
38+
.add(new MoshiSnapshotHelper.SnapshotJsonFactory(captureTimeOut))
3839
.add(
3940
DebuggerScript.class,
4041
new ProbeCondition.ProbeConditionJsonAdapter()) // ProbeDetails in Snapshot

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.squareup.moshi.JsonWriter;
77
import com.squareup.moshi.Moshi;
88
import com.squareup.moshi.Types;
9+
import datadog.trace.api.Config;
910
import datadog.trace.bootstrap.debugger.CapturedContext;
1011
import datadog.trace.bootstrap.debugger.CapturedStackFrame;
1112
import datadog.trace.bootstrap.debugger.Limits;
@@ -62,14 +63,20 @@ public class MoshiSnapshotHelper {
6263
public static final String LOCATION = "location";
6364
public static final String MESSAGE = "message";
6465
public static final String STACKTRACE = "stacktrace";
65-
private static final Duration TIME_OUT = Duration.ofMillis(200);
6666

6767
public static class SnapshotJsonFactory implements JsonAdapter.Factory {
68+
private final Duration captureTimeOut;
69+
70+
public SnapshotJsonFactory(Duration captureTimeOut) {
71+
this.captureTimeOut = captureTimeOut;
72+
}
73+
6874
@Override
6975
public JsonAdapter<?> create(Type type, Set<? extends Annotation> set, Moshi moshi) {
7076
if (Types.equals(type, Snapshot.Captures.class)) {
7177
return new CapturesAdapter(
7278
moshi,
79+
captureTimeOut,
7380
new CapturedContextAdapter(
7481
moshi, new CapturedValueAdapter(), new CapturedThrowableAdapter(moshi)));
7582
}
@@ -88,12 +95,15 @@ public JsonAdapter<?> create(Type type, Set<? extends Annotation> set, Moshi mos
8895
}
8996

9097
public static class CapturesAdapter extends JsonAdapter<Snapshot.Captures> {
98+
protected final Duration captureTimeOut;
9199
protected final JsonAdapter<CapturedContext> capturedContextAdapter;
92100
protected final JsonAdapter<Map<Integer, CapturedContext>> linesAdapter;
93101
protected final JsonAdapter<List<CapturedContext.CapturedThrowable>> caughtExceptionsAdapter;
94102

95-
public CapturesAdapter(Moshi moshi, JsonAdapter<CapturedContext> capturedContextAdapter) {
103+
public CapturesAdapter(
104+
Moshi moshi, Duration captureTimeout, JsonAdapter<CapturedContext> capturedContextAdapter) {
96105
this.capturedContextAdapter = capturedContextAdapter;
106+
this.captureTimeOut = captureTimeout;
97107
linesAdapter =
98108
moshi.adapter(
99109
Types.newParameterizedType(Map.class, Integer.class, CapturedContext.class));
@@ -109,7 +119,7 @@ public void toJson(JsonWriter jsonWriter, Snapshot.Captures captures) throws IOE
109119
return;
110120
}
111121
jsonWriter.setTag(
112-
TimeoutChecker.class, new TimeoutChecker(System.currentTimeMillis(), TIME_OUT));
122+
TimeoutChecker.class, new TimeoutChecker(System.currentTimeMillis(), captureTimeOut));
113123
jsonWriter.beginObject();
114124
jsonWriter.name(ENTRY);
115125
capturedContextAdapter.toJson(jsonWriter, captures.getEntry());
@@ -149,7 +159,9 @@ public void toJson(JsonWriter jsonWriter, CapturedContext capturedContext) throw
149159
}
150160
TimeoutChecker timeoutChecker = jsonWriter.tag(TimeoutChecker.class);
151161
if (timeoutChecker == null) {
152-
timeoutChecker = new TimeoutChecker(TIME_OUT);
162+
Duration timeout =
163+
Duration.of(Config.get().getDynamicInstrumentationCaptureTimeout(), ChronoUnit.MILLIS);
164+
timeoutChecker = new TimeoutChecker(timeout);
153165
}
154166
// need to 'freeze' the context before serializing it
155167
capturedContext.freeze(timeoutChecker);

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,10 @@ public void length255() throws IOException {
789789
@Test
790790
public void capturesAdapterNull() {
791791
MoshiSnapshotHelper.CapturesAdapter capturesAdapter =
792-
new MoshiSnapshotHelper.CapturesAdapter(MoshiHelper.createMoshiSnapshot(), null);
792+
new MoshiSnapshotHelper.CapturesAdapter(
793+
MoshiSnapshotTestHelper.createMoshiSnapshot(),
794+
Duration.of(5, ChronoUnit.SECONDS),
795+
null);
793796
Assertions.assertEquals("null", capturesAdapter.toJson(null));
794797
}
795798

@@ -921,7 +924,9 @@ public void fieldCount20() throws IOException {
921924
public void timeOut() throws IOException {
922925
DebuggerContext.initValueSerializer(
923926
new TimeoutSnapshotSerializer(Duration.of(150, ChronoUnit.MILLIS)));
924-
JsonAdapter<Snapshot> adapter = createSnapshotAdapter();
927+
JsonAdapter<Snapshot> adapter =
928+
MoshiHelper.createMoshiSnapshot(Duration.of(100, ChronoUnit.MILLIS))
929+
.adapter(Snapshot.class);
925930
Snapshot snapshot = createSnapshot();
926931
CapturedContext context = new CapturedContext();
927932
CapturedContext.CapturedValue arg1 = CapturedContext.CapturedValue.of("arg1", "int", 42);

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import java.io.IOException;
4040
import java.lang.annotation.Annotation;
4141
import java.lang.reflect.Type;
42+
import java.time.Duration;
43+
import java.time.temporal.ChronoUnit;
4244
import java.util.ArrayList;
4345
import java.util.Arrays;
4446
import java.util.Collections;
@@ -90,11 +92,18 @@ public static String getValue(CapturedContext.CapturedValue capturedValue) {
9092
}
9193

9294
public static class SnapshotJsonFactory implements JsonAdapter.Factory {
95+
private final Duration captureTimeOut;
96+
97+
public SnapshotJsonFactory(Duration captureTimeout) {
98+
this.captureTimeOut = captureTimeout;
99+
}
100+
93101
@Override
94102
public JsonAdapter<?> create(Type type, Set<? extends Annotation> set, Moshi moshi) {
95103
if (Types.equals(type, Snapshot.Captures.class)) {
96104
return new MoshiSnapshotTestHelper.CapturesAdapter(
97105
moshi,
106+
captureTimeOut,
98107
new CapturedContextAdapter(
99108
moshi, new CapturedValueAdapter(), new CapturedThrowableAdapter(moshi)));
100109
}
@@ -113,8 +122,9 @@ public JsonAdapter<?> create(Type type, Set<? extends Annotation> set, Moshi mos
113122
}
114123

115124
public static Moshi createMoshiSnapshot() {
125+
// By default, for tests we have a capture timeout of 5 seconds
116126
return new Moshi.Builder()
117-
.add(new MoshiSnapshotTestHelper.SnapshotJsonFactory())
127+
.add(new MoshiSnapshotTestHelper.SnapshotJsonFactory(Duration.of(5, ChronoUnit.SECONDS)))
118128
.add(
119129
DebuggerScript.class,
120130
new ProbeCondition.ProbeConditionJsonAdapter()) // ProbeDetails in Snapshot
@@ -152,8 +162,9 @@ private static String primitiveArrayToString(Object obj) {
152162

153163
private static class CapturesAdapter extends MoshiSnapshotHelper.CapturesAdapter {
154164

155-
public CapturesAdapter(Moshi moshi, JsonAdapter<CapturedContext> capturedContextAdapter) {
156-
super(moshi, capturedContextAdapter);
165+
public CapturesAdapter(
166+
Moshi moshi, Duration captureTimeout, JsonAdapter<CapturedContext> capturedContextAdapter) {
167+
super(moshi, captureTimeout, capturedContextAdapter);
157168
}
158169

159170
@Override

dd-java-agent/instrumentation/confluent-schema-registry/confluent-schema-registry-4.1/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ muzzle {
66
group = "io.confluent"
77
module = "kafka-schema-registry-client"
88
versions = "[4.1.0,)"
9+
// broken POMs: depend on non-existent org.eclipse.jetty:jetty-bom:9.4.59
10+
// can be fixed after https://github.com/confluentinc/kafka-connect-storage-common/issues/468 is resolved
11+
skipVersions += ['7.4.14', '7.5.13', '7.6.10', '7.7.8', '7.8.7']
912
excludeDependency "org.codehaus.jackson:jackson-mapper-asl" // missing on some releases
1013
assertInverse = true
1114
}

dd-java-agent/instrumentation/junit/junit-4/junit-4-cucumber-5.4/src/test/resources/test-attempt-to-fix-disabled-failed/events.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,4 @@
149149
},
150150
"type" : "test_module_end",
151151
"version" : 1
152-
} ]
152+
} ]

dd-java-agent/instrumentation/junit/junit-4/junit-4-cucumber-5.4/src/test/resources/test-attempt-to-fix-failed/events.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,4 @@
147147
},
148148
"type" : "test_module_end",
149149
"version" : 1
150-
} ]
150+
} ]

0 commit comments

Comments
 (0)