Skip to content

Commit

Permalink
Updates deps and and adds more JDK versions in CI (#437)
Browse files Browse the repository at this point in the history
* Updates lombok and mockito to ideally get tests passing on modern JDKs

* Refactor build and lint steps into yaml mixins

* Adds multiple jdk versions up to and including latest

* Uses latest available circle-ci convenience images

* Updates AttachAPI usage to be compatible with newer JVMs

* Utilizes reflection to invoke newer startLocalManagementAgent method

* Adds openjdk ticket refs and fixes linting errors
  • Loading branch information
scottopell authored May 10, 2023
1 parent b03f5d5 commit 65aed6f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 12 deletions.
44 changes: 35 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
version: 2
lint_steps: &lint_steps
steps:
- checkout
- run: mvn verify -B -Dhttps.protocols=TLSv1.2 -DskipTests -Dlog4j.configuration=log4j2.travis.properties
build_steps: &build_steps
steps:
- checkout
- run: mvn test -B -Dhttps.protocols=TLSv1.2 -Dcheckstyle.skip=true -Dlog4j.configurationFile=log4j2.travis.properties -Dtests.log_level=info -Djdk.attach.allowAttachSelf=true
- run:
when: on_fail
command: for log in target/surefire-reports/*.txt; do echo "$log ========================" ; cat $log ; done

jobs:
lint_openjdk8:
docker:
- image: circleci/openjdk:8-jdk
steps:
- checkout
- run: mvn verify -B -Dhttps.protocols=TLSv1.2 -DskipTests -Dlog4j.configuration=log4j2.travis.properties
<<: *lint_steps
test_openjdk8:
docker:
- image: circleci/openjdk:8-jdk
steps:
- checkout
- run: mvn test -B -Dhttps.protocols=TLSv1.2 -Dcheckstyle.skip=true -Dlog4j.configurationFile=log4j2.travis.properties -Dtests.log_level=info
- run:
when: on_fail
command: for log in target/surefire-reports/*.txt; do echo "$log ========================" ; cat $log ; done
<<: *build_steps
test_openjdk11:
docker:
- image: cimg/openjdk:11.0
<<: *build_steps
test_openjdk15:
docker:
- image: cimg/openjdk:15.0
<<: *build_steps
test_openjdk17:
docker:
- image: cimg/openjdk:17.0
<<: *build_steps
test_openjdk19:
docker:
- image: cimg/openjdk:19.0
<<: *build_steps

workflows:
version: 2
workflow:
jobs:
- lint_openjdk8
- test_openjdk8
- test_openjdk11
- test_openjdk15
- test_openjdk17
- test_openjdk19
8 changes: 6 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@


<junit.version>4.13.1</junit.version>
<mockito.version>2.2.27</mockito.version>
<mockito.version>2.28.2</mockito.version>

<maven-surefire-plugin.version>2.9</maven-surefire-plugin.version>
<buildnumber-maven-plugin.version>1.4</buildnumber-maven-plugin.version>
Expand Down Expand Up @@ -166,7 +166,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -215,6 +215,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<!-- required for tests in jdk9+ ref https://bugs.openjdk.org/browse/JDK-8180425 -->
<argLine>-Djdk.attach.allowAttachSelf=true</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/org/datadog/jmxfetch/AttachApiConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import javax.management.remote.JMXServiceURL;
Expand Down Expand Up @@ -57,6 +58,10 @@ private String getJmxUrlForProcessRegex(String processRegex)
"No match found. Available JVMs can be listed with the `list_jvms` command.");
}

// management-agent.jar has been removed in java 8+
// Once JMXFetch drops java7 support, this should be simplified to simply invoke
// vm.startLocalManagementAgent
// ref https://bugs.openjdk.org/browse/JDK-8179063
private void loadJmxAgent(com.sun.tools.attach.VirtualMachine vm) throws IOException {
String agent =
vm.getSystemProperties().getProperty("java.home")
Expand All @@ -67,7 +72,18 @@ private void loadJmxAgent(com.sun.tools.attach.VirtualMachine vm) throws IOExcep
try {
vm.loadAgent(agent);
} catch (Exception e) {
log.warn("Error initializing JMX agent", e);
log.warn("Error initializing JMX agent from management-agent.jar", e);

try {
Method method = com.sun.tools.attach.VirtualMachine
.class.getMethod("startLocalManagementAgent");
log.info("Found startLocalManagementAgent API, attempting to use it.");
method.invoke(vm);
} catch (NoSuchMethodException noMethodE) {
log.warn("startLocalManagementAgent method not found, must be on java7", noMethodE);
} catch (Exception reflectionE) {
log.warn("Error invoking the startLocalManagementAgent method", reflectionE);
}
}
}
}

0 comments on commit 65aed6f

Please sign in to comment.