Skip to content

Commit 21afb48

Browse files
authored
Cleanup of zstd dependency and jps functionality (#9010)
* Make the zstd dependency more lightweight * Simplify the JVMs pids collection
1 parent e0a1fc0 commit 21afb48

File tree

9 files changed

+53
-183
lines changed

9 files changed

+53
-183
lines changed

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/Agent.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static datadog.trace.api.ConfigDefaults.DEFAULT_STARTUP_LOGS_ENABLED;
44
import static datadog.trace.api.Platform.isJavaVersionAtLeast;
55
import static datadog.trace.api.Platform.isOracleJDK8;
6-
import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY;
76
import static datadog.trace.bootstrap.Library.WILDFLY;
87
import static datadog.trace.bootstrap.Library.detectLibraries;
98
import static datadog.trace.util.AgentThreadFactory.AgentThread.JMX_STARTUP;
@@ -45,7 +44,6 @@
4544
import datadog.trace.util.AgentTaskScheduler;
4645
import datadog.trace.util.AgentThreadFactory.AgentThread;
4746
import datadog.trace.util.throwable.FatalAgentMisconfigurationError;
48-
import de.thetaphi.forbiddenapis.SuppressForbidden;
4947
import java.lang.instrument.Instrumentation;
5048
import java.lang.reflect.InvocationTargetException;
5149
import java.lang.reflect.Method;
@@ -291,8 +289,6 @@ public static void start(
291289
codeOriginEnabled = isFeatureEnabled(AgentFeature.CODE_ORIGIN);
292290
agentlessLogSubmissionEnabled = isFeatureEnabled(AgentFeature.AGENTLESS_LOG_SUBMISSION);
293291

294-
patchJPSAccess(inst);
295-
296292
if (profilingEnabled) {
297293
if (!isOracleJDK8()) {
298294
// Profiling agent startup code is written in a way to allow `startProfilingAgent` be called
@@ -422,23 +418,6 @@ private static void injectAgentArgsConfig(String agentArgs) {
422418
}
423419
}
424420

425-
@SuppressForbidden
426-
public static void patchJPSAccess(Instrumentation inst) {
427-
if (Platform.isJavaVersionAtLeast(9)) {
428-
// Unclear if supported for J9, may need to revisit
429-
try {
430-
Class.forName("datadog.trace.util.JPMSJPSAccess")
431-
.getMethod("patchModuleAccess", Instrumentation.class)
432-
.invoke(null, inst);
433-
} catch (Exception e) {
434-
log.debug(
435-
SEND_TELEMETRY,
436-
"Failed to patch module access for jvmstat and Java version "
437-
+ Platform.getRuntimeVersion());
438-
}
439-
}
440-
}
441-
442421
public static void shutdown(final boolean sync) {
443422
StaticEventLogger.end("Agent");
444423
StaticEventLogger.stop();

dd-java-agent/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ ext.generalShadowJarConfig = {
8383
exclude '**/com/kenai/jffi/Init.class'
8484
relocate('com.kenai.jffi.Init', 'com.kenai.jffi.PatchInit')
8585

86+
// Minimize and relocate the airlift compressor dependency for ZSTD
87+
exclude '**/io/airlift/compress/bzip2/**'
88+
exclude '**/io/airlift/compress/deflate/**'
89+
exclude '**/io/airlift/compress/gzip/**'
90+
exclude '**/io/airlift/compress/hadoop/**'
91+
exclude '**/io/airlift/compress/lz4/**'
92+
exclude '**/io/airlift/compress/lzo/**'
93+
exclude '**/io/airlift/compress/snappy/**'
94+
relocate 'io.airlift', 'datadog.io.airlift'
95+
8696
final String projectName = "${project.name}"
8797

8898
// Prevents conflict with other instances, but doesn't relocate instrumentation

dd-smoke-tests/profiling-integration-tests/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ dependencies {
2020
implementation project(':dd-trace-api')
2121
api project(':dd-trace-ot')
2222
implementation 'org.apache.commons:commons-math3:3.6.1'
23-
implementation 'org.lz4:lz4-java:1.8.0'
23+
implementation libs.lz4
24+
implementation libs.aircompressor
2425
implementation 'org.xerial.snappy:snappy-java:1.1.8.4'
2526

2627
testImplementation project(':dd-smoke-tests')
2728
testImplementation project(':dd-java-agent:agent-profiling:profiling-testing')
2829
testImplementation libs.bundles.junit5
2930
testImplementation libs.bundles.mockito
3031
testImplementation libs.bundles.jmc
32+
testImplementation libs.aircompressor
3133
testImplementation(group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.10')
3234
}
3335

dd-smoke-tests/profiling-integration-tests/src/test/java/datadog/smoketest/JFRBasedProfilingIntegrationTest.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
import datadog.trace.api.Platform;
1818
import datadog.trace.api.config.ProfilingConfig;
1919
import delight.fileupload.FileUpload;
20+
import io.airlift.compress.zstd.ZstdInputStream;
2021
import java.io.ByteArrayInputStream;
2122
import java.io.File;
2223
import java.io.IOException;
24+
import java.io.InputStream;
2325
import java.net.InetAddress;
2426
import java.nio.file.Files;
2527
import java.nio.file.Path;
@@ -150,7 +152,7 @@ void teardown() throws Exception {
150152
}
151153

152154
@Test
153-
@DisplayName("Test continuous recording - no jmx delay, no jmethodid cache")
155+
@DisplayName("Test continuous recording - no jmx delay, default compression")
154156
public void testContinuousRecording_no_jmx_delay(final TestInfo testInfo) throws Exception {
155157
testWithRetry(
156158
() ->
@@ -161,7 +163,7 @@ public void testContinuousRecording_no_jmx_delay(final TestInfo testInfo) throws
161163
}
162164

163165
@Test
164-
@DisplayName("Test continuous recording - no jmx delay, jmethodid cache")
166+
@DisplayName("Test continuous recording - no jmx delay, zstd compression")
165167
public void testContinuousRecording_no_jmx_delay_jmethodid_cache(final TestInfo testInfo)
166168
throws Exception {
167169
testWithRetry(
@@ -173,7 +175,7 @@ public void testContinuousRecording_no_jmx_delay_jmethodid_cache(final TestInfo
173175
}
174176

175177
@Test
176-
@DisplayName("Test continuous recording - 1 sec jmx delay, no jmethodid cache")
178+
@DisplayName("Test continuous recording - 1 sec jmx delay, default compression")
177179
public void testContinuousRecording(final TestInfo testInfo) throws Exception {
178180
testWithRetry(
179181
() ->
@@ -184,7 +186,7 @@ public void testContinuousRecording(final TestInfo testInfo) throws Exception {
184186
}
185187

186188
@Test
187-
@DisplayName("Test continuous recording - 1 sec jmx delay, jmethodid cache")
189+
@DisplayName("Test continuous recording - 1 sec jmx delay, zstd compression")
188190
public void testContinuousRecording_jmethodid_cache(final TestInfo testInfo) throws Exception {
189191
testWithRetry(
190192
() ->
@@ -198,7 +200,7 @@ private void testContinuousRecording(
198200
final int jmxFetchDelay,
199201
final boolean endpointCollectionEnabled,
200202
final boolean asyncProfilerEnabled,
201-
final boolean jmethodIdCacheEnabled)
203+
final boolean withZstd)
202204
throws Exception {
203205
final ObjectMapper mapper = new ObjectMapper();
204206
try {
@@ -207,7 +209,7 @@ private void testContinuousRecording(
207209
jmxFetchDelay,
208210
endpointCollectionEnabled,
209211
asyncProfilerEnabled,
210-
jmethodIdCacheEnabled,
212+
withZstd,
211213
logFilePath)
212214
.start();
213215

@@ -261,7 +263,11 @@ private void testContinuousRecording(
261263
assertEquals(InetAddress.getLocalHost().getHostName(), requestTags.get("host"));
262264

263265
assertFalse(logHasErrors(logFilePath));
264-
IItemCollection events = JfrLoaderToolkit.loadEvents(new ByteArrayInputStream(rawJfr.get()));
266+
InputStream eventStream = new ByteArrayInputStream(rawJfr.get());
267+
if (withZstd) {
268+
eventStream = new ZstdInputStream(eventStream);
269+
}
270+
IItemCollection events = JfrLoaderToolkit.loadEvents(eventStream);
265271
assertTrue(events.hasItems());
266272
Pair<Instant, Instant> rangeStartAndEnd = getRangeStartAndEnd(events);
267273
// This nano-second compensates for the added nano second in
@@ -308,7 +314,11 @@ private void testContinuousRecording(
308314
period > 0 && period <= upperLimit,
309315
() -> "Upload period = " + period + "ms, expected (0, " + upperLimit + "]ms");
310316

311-
events = JfrLoaderToolkit.loadEvents(new ByteArrayInputStream(rawJfr.get()));
317+
eventStream = new ByteArrayInputStream(rawJfr.get());
318+
if (withZstd) {
319+
eventStream = new ZstdInputStream(eventStream);
320+
}
321+
events = JfrLoaderToolkit.loadEvents(eventStream);
312322
assertTrue(events.hasItems());
313323
verifyDatadogEventsNotCorrupt(events);
314324
rangeStartAndEnd = getRangeStartAndEnd(events);
@@ -689,7 +699,7 @@ private ProcessBuilder createDefaultProcessBuilder(
689699
final int jmxFetchDelay,
690700
final boolean endpointCollectionEnabled,
691701
final boolean asyncProfilerEnabled,
692-
final boolean jmethodIdCacheEnabled,
702+
final boolean withZstd,
693703
final Path logFilePath) {
694704
return createProcessBuilder(
695705
VALID_API_KEY,
@@ -698,7 +708,7 @@ private ProcessBuilder createDefaultProcessBuilder(
698708
PROFILING_UPLOAD_PERIOD_SECONDS,
699709
endpointCollectionEnabled,
700710
asyncProfilerEnabled,
701-
jmethodIdCacheEnabled,
711+
withZstd,
702712
0,
703713
logFilePath);
704714
}
@@ -710,7 +720,7 @@ private ProcessBuilder createProcessBuilder(
710720
final int profilingUploadPeriodSecs,
711721
final boolean endpointCollectionEnabled,
712722
final boolean asyncProfilerEnabled,
713-
final boolean jmethodIdCacheEnabled,
723+
final boolean withZstd,
714724
final int exitDelay,
715725
final Path logFilePath) {
716726
return createProcessBuilder(
@@ -722,7 +732,7 @@ private ProcessBuilder createProcessBuilder(
722732
profilingUploadPeriodSecs,
723733
endpointCollectionEnabled,
724734
asyncProfilerEnabled,
725-
jmethodIdCacheEnabled,
735+
withZstd,
726736
exitDelay,
727737
logFilePath);
728738
}
@@ -736,7 +746,7 @@ private static ProcessBuilder createProcessBuilder(
736746
final int profilingUploadPeriodSecs,
737747
final boolean endpointCollectionEnabled,
738748
final boolean asyncProfilerEnabled,
739-
final boolean jmethodIdCacheEnabled,
749+
final boolean withZstd,
740750
final int exitDelay,
741751
final Path logFilePath) {
742752
final String templateOverride =
@@ -770,7 +780,7 @@ private static ProcessBuilder createProcessBuilder(
770780
"-Ddd.profiling.debug.dump_path=/tmp/dd-profiler",
771781
"-Ddd.profiling.queueing.time.enabled=true",
772782
"-Ddd.profiling.queueing.time.threshold.millis=0",
773-
"-Ddd.profiling.experimental.jmethodid_cache.enabled=" + jmethodIdCacheEnabled,
783+
"-Ddd.profiling.debug.upload.compression=" + (withZstd ? "zstd" : "on"),
774784
"-Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug",
775785
"-Ddd.profiling.context.attributes=foo,bar",
776786
"-Dorg.slf4j.simpleLogger.defaultLogLevel=debug",

gradle/dependencies.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ final class CachedData {
3636
exclude(dependency('com.datadoghq.okio:okio'))
3737
exclude(dependency('com.squareup.okio:okio'))
3838
exclude(dependency('org.lz4:lz4-java'))
39+
exclude(dependency('io.airlift:aircompressor'))
3940

4041
// dogstatsd and its transitives
4142
exclude(dependency('com.datadoghq:java-dogstatsd-client'))
@@ -67,7 +68,8 @@ CachedData.deps.shared = [
6768
libs.jnr.unixsocket,
6869
libs.moshi,
6970
libs.jctools,
70-
libs.lz4
71+
libs.lz4,
72+
libs.aircompressor
7173
]
7274

7375
ext {

internal-api/internal-api-9/src/main/java/datadog/trace/util/JPMSJPSAccess.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

internal-api/internal-api-9/src/test/groovy/datadog/trace/util/PidHelperTest.groovy

Lines changed: 0 additions & 21 deletions
This file was deleted.

internal-api/src/main/java/datadog/trace/util/JPSUtils.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)