From f9a86809a71db33e5849c430de4b9f22e8f589e1 Mon Sep 17 00:00:00 2001 From: Carlos Roman Date: Fri, 15 Dec 2023 13:25:02 +0000 Subject: [PATCH] Added option to pass JAVA_OPTS and image to use to MisbehavingJMXServer --- .../datadog/jmxfetch/util/MisbehavingJMXServer.java | 12 ++++++++++-- tools/misbehaving-jmx-server/scripts/start.sh | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/datadog/jmxfetch/util/MisbehavingJMXServer.java b/src/test/java/org/datadog/jmxfetch/util/MisbehavingJMXServer.java index 06896deb6..9531caac7 100644 --- a/src/test/java/org/datadog/jmxfetch/util/MisbehavingJMXServer.java +++ b/src/test/java/org/datadog/jmxfetch/util/MisbehavingJMXServer.java @@ -17,7 +17,10 @@ public class MisbehavingJMXServer implements Startable { private static final String RMI_PORT = "RMI_PORT"; private static final String CONTROL_PORT = "CONTROL_PORT"; private static final String SUPERVISOR_PORT = "SUPERVISOR_PORT"; + public static final String JAVA_OPTS = "JAVA_OPTS"; private final String jdkImage; + + private final String javaOpts; private final int controlPort; private final int supervisorPort; private final GenericContainer server; @@ -28,23 +31,27 @@ public MisbehavingJMXServer( final int rmiPort, final int controlPort, final int supervisorPort) { - this(DEFAULT_JDK_IMAGE, rmiPort, controlPort, supervisorPort); + this(DEFAULT_JDK_IMAGE, "", rmiPort, controlPort, supervisorPort); } public MisbehavingJMXServer( final String jdkImage, + final String javaOpts, final int rmiPort, final int controlPort, final int supervisorPort) { + this.javaOpts = javaOpts; this.controlPort = controlPort; this.supervisorPort = supervisorPort; this.jdkImage = jdkImage; final ImageFromDockerfile img = new ImageFromDockerfile() - .withFileFromPath(".", Paths.get("./tools/misbehaving-jmx-server/")); + .withFileFromPath(".", Paths.get("./tools/misbehaving-jmx-server/")) + .withBuildArg("FINAL_JRE_IMAGE", this.jdkImage); this.server = new GenericContainer<>(img) .withEnv(RMI_PORT, String.valueOf(rmiPort)) .withEnv(CONTROL_PORT, String.valueOf(controlPort)) .withEnv(SUPERVISOR_PORT, String.valueOf(supervisorPort)) + .withEnv(JAVA_OPTS, this.javaOpts) .waitingFor(Wait.forLogMessage( ".*Supervisor HTTP Server Started. Waiting for initialization payload POST to /init.*", 1)); @@ -52,6 +59,7 @@ public MisbehavingJMXServer( @Override public void start() { + log.info("Starting MisbehavingJMXServer with Docker image '{}' with JAVA_OPTS '{}'", this.jdkImage, this.javaOpts); this.server.start(); final String ipAddress = this.getIp(); this.controlClient = new JMXServerControlClient(ipAddress, this.controlPort); diff --git a/tools/misbehaving-jmx-server/scripts/start.sh b/tools/misbehaving-jmx-server/scripts/start.sh index 6fb93ebdb..ccc8a8a89 100755 --- a/tools/misbehaving-jmx-server/scripts/start.sh +++ b/tools/misbehaving-jmx-server/scripts/start.sh @@ -6,6 +6,9 @@ echo "Running $@" [ -n "$JAVA_OPTS" ] || JAVA_OPTS="-Xmx128M -Xms128M" +echo "Using `java --version`" +echo "With JAVA_OPTS '${JAVA_OPTS}'" + # shellcheck disable=SC2086 java \ ${JAVA_OPTS} \