Skip to content

Commit 41a63af

Browse files
committed
Address internal inconsistency & test instability
Squashed 3 commits
1 parent 627d36b commit 41a63af

File tree

6 files changed

+12
-16
lines changed

6 files changed

+12
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public static void patchJPSAccess(Instrumentation inst) {
430430
// Unclear if supported for J9, may need to revisit
431431
try {
432432
Class.forName("datadog.trace.util.JPMSJPSAccess")
433-
.getMethod("patchModuleAccess")
433+
.getMethod("patchModuleAccess", Instrumentation.class)
434434
.invoke(inst);
435435
} catch (Exception e) {
436436
log.debug(

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,6 @@ void testShutdown(final TestInfo testInfo) throws Exception {
507507
assertTrue(
508508
targetProcess.waitFor(
509509
duration + PROFILING_UPLOAD_TIMEOUT_SECONDS + 1, TimeUnit.SECONDS));
510-
assertTrue(
511-
checkLogLines(logFilePath, it -> it.contains("Successfully invoked jvmstat")));
512510
} finally {
513511
if (targetProcess != null) {
514512
targetProcess.destroyForcibly();

internal-api/internal-api-9/build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ forbiddenApisMain {
4141
failOnMissingClasses = false
4242
}
4343

44-
forbiddenApisMain_java11 {
45-
failOnMissingClasses = false
46-
}
47-
4844
idea {
4945
module {
5046
jdkName = '11'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
package datadog.trace.util
22

33
import datadog.trace.test.util.DDSpecification
4+
import net.bytebuddy.agent.ByteBuddyAgent
45

56
class PidHelperTest extends DDSpecification {
67

78
def "PID is available everywhere we test"() {
89
expect:
910
!PidHelper.getPid().isEmpty()
1011
}
12+
13+
def "JPS via jvmstat is used when possible"() {
14+
when:
15+
def inst = ByteBuddyAgent.install()
16+
JPMSJPSAccess.patchModuleAccess(inst)
17+
18+
then:
19+
JPSUtils.VMPids != null
20+
}
1121
}

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import de.thetaphi.forbiddenapis.SuppressForbidden;
44
import java.lang.reflect.Method;
5-
import java.util.HashSet;
6-
import java.util.List;
75
import java.util.Set;
86
import org.slf4j.Logger;
97
import org.slf4j.LoggerFactory;
@@ -13,21 +11,15 @@ public final class JPSUtils {
1311

1412
@SuppressForbidden
1513
public static Set<String> getVMPids() {
16-
Set<String> vmPids = new HashSet<>();
1714
try {
1815
Class<?> monitoredHostClass = Class.forName("sun.jvmstat.monitor.MonitoredHost");
1916
Method getMonitoredHostMethod =
2017
monitoredHostClass.getDeclaredMethod("getMonitoredHost", String.class);
2118
Object vmHost = getMonitoredHostMethod.invoke(null, "localhost");
22-
for (Integer vmPid :
23-
(List<Integer>) monitoredHostClass.getDeclaredMethod("activeVms").invoke(vmHost)) {
24-
vmPids.add(vmPid.toString());
25-
}
26-
log.debug("Successfully invoked jvmstat");
19+
return (Set<String>) monitoredHostClass.getDeclaredMethod("activeVms").invoke(vmHost);
2720
} catch (Exception e) {
2821
log.debug("Failed to invoke jvmstat with exception ", e);
2922
return null;
3023
}
31-
return vmPids;
3224
}
3325
}

0 commit comments

Comments
 (0)