Skip to content

Commit 9bc2136

Browse files
authored
Merge branch 'master' into ygree/snakeyaml-engine-migration
2 parents c68d1b1 + fc74eaa commit 9bc2136

File tree

19 files changed

+449
-143
lines changed

19 files changed

+449
-143
lines changed

.github/workflows/analyze-changes.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
${{ runner.os }}-gradle-
4141
4242
- name: Initialize CodeQL
43-
uses: github/codeql-action/init@60168efe1c415ce0f5521ea06d5c2062adbeed1b # v3.28.17
43+
uses: github/codeql-action/init@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
4444
with:
4545
languages: 'java'
4646
build-mode: 'manual'
@@ -57,7 +57,7 @@ jobs:
5757
--build-cache --parallel --stacktrace --no-daemon --max-workers=4
5858
5959
- name: Perform CodeQL Analysis and upload results to GitHub Security tab
60-
uses: github/codeql-action/analyze@60168efe1c415ce0f5521ea06d5c2062adbeed1b # v3.28.17
60+
uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
6161

6262
trivy:
6363
name: Analyze changes with Trivy
@@ -120,7 +120,7 @@ jobs:
120120
TRIVY_JAVA_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-java-db,public.ecr.aws/aquasecurity/trivy-java-db
121121

122122
- name: Upload Trivy scan results to GitHub Security tab
123-
uses: github/codeql-action/upload-sarif@60168efe1c415ce0f5521ea06d5c2062adbeed1b # v3.28.17
123+
uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
124124
if: always()
125125
with:
126126
sarif_file: 'trivy-results.sarif'

.gitlab-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ muzzle-dep-report:
414414
- .circleci/collect_results.sh
415415
- .circleci/upload_ciapp.sh tests $testJvm
416416
- gitlab_section_end "collect-reports"
417+
- URL_ENCODED_JOB_NAME=$(jq -rn --arg x "$CI_JOB_NAME" '$x|@uri')
418+
- echo -e "${TEXT_BOLD}${TEXT_YELLOW}See test results in Datadog:${TEXT_CLEAR} https://app.datadoghq.com/ci/test/runs?query=test_level%3Atest%20%40test.service%3Add-trace-java%20%40ci.pipeline.id%3A${CI_PIPELINE_ID}%20%40ci.job.name%3A%22${URL_ENCODED_JOB_NAME}%22"
417419
artifacts:
418420
when: always
419421
paths:

.gitlab/gitlab-utils.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ function gitlab_section_end () {
1515

1616
echo -e "section_end:`date +%s`:${section_title}\r\e[0K"
1717
}
18+
19+
# A subset of ansi color/formatting codes https://misc.flogisoft.com/bash/tip_colors_and_formatting
20+
export TEXT_RED="\e[31m"
21+
export TEXT_GREEN="\e[32m"
22+
export TEXT_YELLOW="\e[33m"
23+
export TEXT_BLUE="\e[34m"
24+
export TEXT_MAGENTA="\e[35m"
25+
export TEXT_CYAN="\e[36m"
26+
export TEXT_CLEAR="\e[0m"
27+
export TEXT_BOLD="\e[1m"

dd-java-agent/agent-debugger/debugger-el/src/main/java/com/datadog/debugger/el/JsonToExpressionConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public class JsonToExpressionConverter {
5050
"endsWith",
5151
"contains",
5252
"matches",
53-
"instanceof"));
53+
"instanceof",
54+
"isDefined"));
5455

5556
@FunctionalInterface
5657
interface BinaryPredicateExpressionFunction<T extends Expression> {

dd-java-agent/agent-debugger/debugger-el/src/test/resources/test_one_liner_value_expr_01.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
{"dsl": "", "json": {"contains": [{"ref": "str"}, "ll"]}}
2020
{"dsl": "", "json": {"matches": [{"ref": "str"}, "[helo]+"]}}
2121
{"dsl": "", "json": {"instanceof": [{"ref": "str"}, "java.lang.String"]}}
22+
{"dsl": "", "json": {"isDefined": {"ref": "str"}}}

dd-java-agent/agent-debugger/debugger-el/src/test/resources/test_value_expr_01.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
{"endsWith": [{"ref": "str"}, "llo"]},
2525
{"contains": [{"ref": "str"}, "ll"]},
2626
{"matches": [{"ref": "str"}, "[helo]+"]},
27-
{"instanceof": [{"ref": "str"}, "java.lang.String"]}
27+
{"instanceof": [{"ref": "str"}, "java.lang.String"]},
28+
{"isDefined": {"ref": "str"}}
2829
]
2930
}
3031
]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ public static void startExceptionReplay() {
212212
configurationUpdater,
213213
classNameFilter,
214214
Duration.ofSeconds(config.getDebuggerExceptionCaptureInterval()),
215-
config.getDebuggerMaxExceptionPerSecond());
215+
config.getDebuggerMaxExceptionPerSecond(),
216+
config.getDebuggerExceptionMaxCapturedFrames());
216217
DebuggerContext.initExceptionDebugger(exceptionDebugger);
217218
LOGGER.info("Started Exception Replay");
218219
}

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/DefaultExceptionDebugger.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,33 @@ public class DefaultExceptionDebugger implements DebuggerContext.ExceptionDebugg
3838
private final ConfigurationUpdater configurationUpdater;
3939
private final ClassNameFilter classNameFiltering;
4040
private final CircuitBreaker circuitBreaker;
41+
private final int maxCapturedFrames;
4142

4243
public DefaultExceptionDebugger(
4344
ConfigurationUpdater configurationUpdater,
4445
ClassNameFilter classNameFiltering,
4546
Duration captureInterval,
46-
int maxExceptionPerSecond) {
47+
int maxExceptionPerSecond,
48+
int maxCapturedFrames) {
4749
this(
4850
new ExceptionProbeManager(classNameFiltering, captureInterval),
4951
configurationUpdater,
5052
classNameFiltering,
51-
maxExceptionPerSecond);
53+
maxExceptionPerSecond,
54+
maxCapturedFrames);
5255
}
5356

5457
DefaultExceptionDebugger(
5558
ExceptionProbeManager exceptionProbeManager,
5659
ConfigurationUpdater configurationUpdater,
5760
ClassNameFilter classNameFiltering,
58-
int maxExceptionPerSecond) {
61+
int maxExceptionPerSecond,
62+
int maxCapturedFrames) {
5963
this.exceptionProbeManager = exceptionProbeManager;
6064
this.configurationUpdater = configurationUpdater;
6165
this.classNameFiltering = classNameFiltering;
6266
this.circuitBreaker = new CircuitBreaker(maxExceptionPerSecond, Duration.ofSeconds(1));
67+
this.maxCapturedFrames = maxCapturedFrames;
6368
}
6469

6570
@Override
@@ -91,7 +96,8 @@ public void handleException(Throwable t, AgentSpan span) {
9196
LOGGER.debug("Unable to find state for throwable: {}", innerMostException.toString());
9297
return;
9398
}
94-
processSnapshotsAndSetTags(t, span, state, chainedExceptionsList, fingerprint);
99+
processSnapshotsAndSetTags(
100+
t, span, state, chainedExceptionsList, fingerprint, maxCapturedFrames);
95101
exceptionProbeManager.updateLastCapture(fingerprint);
96102
} else {
97103
// climb up the exception chain to find the first exception that has instrumented frames
@@ -128,7 +134,8 @@ private static void processSnapshotsAndSetTags(
128134
AgentSpan span,
129135
ThrowableState state,
130136
List<Throwable> chainedExceptions,
131-
String fingerprint) {
137+
String fingerprint,
138+
int maxCapturedFrames) {
132139
if (span.getTag(DD_DEBUG_ERROR_EXCEPTION_ID) != null) {
133140
LOGGER.debug("Clear previous frame tags");
134141
// already set for this span, clear the frame tags
@@ -142,7 +149,8 @@ private static void processSnapshotsAndSetTags(
142149
}
143150
boolean snapshotAssigned = false;
144151
List<Snapshot> snapshots = state.getSnapshots();
145-
for (int i = 0; i < snapshots.size(); i++) {
152+
int maxSnapshotSize = Math.min(snapshots.size(), maxCapturedFrames);
153+
for (int i = 0; i < maxSnapshotSize; i++) {
146154
Snapshot snapshot = snapshots.get(i);
147155
Throwable currentEx = chainedExceptions.get(snapshot.getChainedExceptionIdx());
148156
int[] mapping = createThrowableMapping(currentEx, t);

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/exception/DefaultExceptionDebuggerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void setUp() {
6767
new HashSet<>(singletonList("com.datadog.debugger.exception.ThirdPartyCode")));
6868
exceptionDebugger =
6969
new DefaultExceptionDebugger(
70-
configurationUpdater, classNameFiltering, Duration.ofHours(1), 100);
70+
configurationUpdater, classNameFiltering, Duration.ofHours(1), 100, 3);
7171
listener = new TestSnapshotListener(createConfig(), mock(ProbeStatusSink.class));
7272
DebuggerAgentHelper.injectSink(listener);
7373
}
@@ -275,7 +275,7 @@ public void nestedExceptionFullThirdParty() {
275275
public void filteringOutErrors() {
276276
ExceptionProbeManager manager = mock(ExceptionProbeManager.class);
277277
exceptionDebugger =
278-
new DefaultExceptionDebugger(manager, configurationUpdater, classNameFiltering, 100);
278+
new DefaultExceptionDebugger(manager, configurationUpdater, classNameFiltering, 100, 3);
279279
exceptionDebugger.handleException(new AssertionError("test"), mock(AgentSpan.class));
280280
verify(manager, times(0)).isAlreadyInstrumented(any());
281281
}

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/exception/ExceptionProbeInstrumentationTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.datadog.debugger.agent.ClassesToRetransformFinder;
1818
import com.datadog.debugger.agent.Configuration;
1919
import com.datadog.debugger.agent.ConfigurationUpdater;
20-
import com.datadog.debugger.agent.DebuggerAgent;
2120
import com.datadog.debugger.agent.DebuggerAgentHelper;
2221
import com.datadog.debugger.agent.DebuggerTransformer;
2322
import com.datadog.debugger.agent.JsonSnapshotSerializer;
@@ -99,7 +98,10 @@ public void before() {
9998
ProbeRateLimiter.setSamplerSupplier(rate -> rate < 101 ? probeSampler : globalSampler);
10099
ProbeRateLimiter.setGlobalSnapshotRate(1000);
101100
// to activate the call to DebuggerContext.handleException
102-
DebuggerAgent.startExceptionReplay();
101+
DebuggerContext.ProductConfigUpdater mockProductConfigUpdater =
102+
mock(DebuggerContext.ProductConfigUpdater.class);
103+
when(mockProductConfigUpdater.isExceptionReplayEnabled()).thenReturn(true);
104+
DebuggerContext.initProductConfigUpdater(mockProductConfigUpdater);
103105
setFieldInConfig(Config.get(), "debuggerExceptionEnabled", true);
104106
setFieldInConfig(Config.get(), "dynamicInstrumentationClassFileDumpEnabled", true);
105107
}
@@ -224,7 +226,8 @@ public void recursive() throws Exception {
224226
callMethodFiboException(testClass); // generate snapshots
225227
Map<String, Set<String>> probeIdsByMethodName =
226228
extractProbeIdsByMethodName(exceptionProbeManager);
227-
assertEquals(10, listener.snapshots.size());
229+
// limited by Config::getDebuggerExceptionMaxCapturedFrames
230+
assertEquals(3, listener.snapshots.size());
228231
Snapshot snapshot0 = listener.snapshots.get(0);
229232
assertProbeId(probeIdsByMethodName, "fiboException", snapshot0.getProbe().getId());
230233
assertEquals(
@@ -234,8 +237,6 @@ public void recursive() throws Exception {
234237
assertEquals("2", getValue(snapshot1.getCaptures().getReturn().getArguments().get("n")));
235238
Snapshot snapshot2 = listener.snapshots.get(2);
236239
assertEquals("3", getValue(snapshot2.getCaptures().getReturn().getArguments().get("n")));
237-
Snapshot snapshot9 = listener.snapshots.get(9);
238-
assertEquals("10", getValue(snapshot9.getCaptures().getReturn().getArguments().get("n")));
239240
// sampling happens only once ont he first snapshot then forced for coordinated sampling
240241
assertEquals(1, probeSampler.getCallCount());
241242
assertEquals(1, globalSampler.getCallCount());
@@ -382,7 +383,7 @@ private TestSnapshotListener setupExceptionDebugging(
382383
DebuggerContext.initValueSerializer(new JsonSnapshotSerializer());
383384
DefaultExceptionDebugger exceptionDebugger =
384385
new DefaultExceptionDebugger(
385-
exceptionProbeManager, configurationUpdater, classNameFiltering, 100);
386+
exceptionProbeManager, configurationUpdater, classNameFiltering, 100, 3);
386387
DebuggerContext.initExceptionDebugger(exceptionDebugger);
387388
configurationUpdater.accept(REMOTE_CONFIG, definitions);
388389
return listener;

0 commit comments

Comments
 (0)