Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates deps and and adds more JDK versions in CI #437

Merged
merged 7 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
}