From 6f760a1c93d10bbee2ab0723ee24518091749e6a Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:33:41 +0100 Subject: [PATCH 01/25] backport few changes from jetty PR --- .../target_systems/ActiveMqIntegrationTest.java | 9 +-------- .../target_systems/CassandraIntegrationTest.java | 10 +++------- .../target_systems/TargetSystemIntegrationTest.java | 10 ++++++++++ .../target_systems/TomcatIntegrationTest.java | 10 +--------- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java index 036996f5e..675c5d39d 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java @@ -23,14 +23,7 @@ protected GenericContainer createTargetContainer(int jmxPort) { new ImageFromDockerfile() .withDockerfileFromBuilder( builder -> builder.from("apache/activemq-classic:5.18.6").build())) - .withEnv( - "JAVA_TOOL_OPTIONS", - "-Dcom.sun.management.jmxremote.port=" - + jmxPort - + " -Dcom.sun.management.jmxremote.rmi.port=" - + jmxPort - + " -Dcom.sun.management.jmxremote.ssl=false" - + " -Dcom.sun.management.jmxremote.authenticate=false") + .withEnv("JAVA_TOOL_OPTIONS", genericJmxJvmArguments(jmxPort)) .withStartupTimeout(Duration.ofMinutes(2)) .waitingFor(Wait.forListeningPort()); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java index 756cbd502..b3d7982c4 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java @@ -29,13 +29,9 @@ protected GenericContainer createTargetContainer(int jmxPort) { .withDockerfileFromBuilder(builder -> builder.from("cassandra:5.0.2").build())) .withEnv( "JVM_EXTRA_OPTS", - " -Dcassandra.jmx.remote.port=" - + jmxPort - + " -Dcom.sun.management.jmxremote.rmi.port=" - + jmxPort - + " -Dcom.sun.management.jmxremote.local.only=false" - + " -Dcom.sun.management.jmxremote.ssl=false" - + " -Dcom.sun.management.jmxremote.authenticate=false") + genericJmxJvmArguments(jmxPort) + // making cassandra startup faster for single node, from ~1min to ~15s + + " -Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=0") .withStartupTimeout(Duration.ofMinutes(2)) .waitingFor(Wait.forLogMessage(".*Startup complete.*", 1)); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java index 510b4eab5..4d4ca988b 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java @@ -196,4 +196,14 @@ public void export( sb.http(0); } } + + protected static String genericJmxJvmArguments(int port) { + return "-Dcom.sun.management.jmxremote.local.only=false" + + " -Dcom.sun.management.jmxremote.authenticate=false" + + " -Dcom.sun.management.jmxremote.ssl=false" + + " -Dcom.sun.management.jmxremote.port=" + + port + + " -Dcom.sun.management.jmxremote.rmi.port=" + + port; + } } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java index 76bacf265..7b1313a1b 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java @@ -30,15 +30,7 @@ protected GenericContainer createTargetContainer(int jmxPort) { "https://tomcat.apache.org/tomcat-9.0-doc/appdev/sample/sample.war", "/usr/local/tomcat/webapps/ROOT.war") .build())) - .withEnv( - "CATALINA_OPTS", - "-Dcom.sun.management.jmxremote.local.only=false" - + " -Dcom.sun.management.jmxremote.authenticate=false" - + " -Dcom.sun.management.jmxremote.ssl=false" - + " -Dcom.sun.management.jmxremote.port=" - + jmxPort - + " -Dcom.sun.management.jmxremote.rmi.port=" - + jmxPort) + .withEnv("CATALINA_OPTS", genericJmxJvmArguments(jmxPort)) .withStartupTimeout(Duration.ofMinutes(2)) .waitingFor(Wait.forListeningPort()); } From f4c4be2027794eb42ae6d6224bab939c7814a7a5 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:09:56 +0100 Subject: [PATCH 02/25] add ability to use login/pwd + extra jars --- .../jmxscraper/JmxConnectorBuilderTest.java | 3 +- .../jmxscraper/JmxScraperContainer.java | 70 +++++++++++++++++-- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxConnectorBuilderTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxConnectorBuilderTest.java index 5766cd890..5b57121cb 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxConnectorBuilderTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxConnectorBuilderTest.java @@ -50,7 +50,8 @@ void loginPwdAuth() { testConnector( () -> JmxConnectorBuilder.createNew(app.getHost(), app.getMappedPort(port)) - .userCredentials(login, pwd) + .withUser(login) + .withPassword(pwd) .build()); } } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxScraperContainer.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxScraperContainer.java index 125b56a97..2d6b8864b 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxScraperContainer.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxScraperContainer.java @@ -26,6 +26,9 @@ public class JmxScraperContainer extends GenericContainer { private String serviceUrl; private int intervalMillis; private final Set customYamlFiles; + private String user; + private String password; + private final List extraJars; public JmxScraperContainer(String otlpEndpoint) { super("openjdk:8u342-jre-slim"); @@ -42,6 +45,7 @@ public JmxScraperContainer(String otlpEndpoint) { this.targetSystems = new HashSet<>(); this.customYamlFiles = new HashSet<>(); this.intervalMillis = 1000; + this.extraJars = new ArrayList<>(); } @CanIgnoreReturnValue @@ -57,11 +61,52 @@ public JmxScraperContainer withIntervalMillis(int intervalMillis) { } @CanIgnoreReturnValue - public JmxScraperContainer withService(String host, int port) { + public JmxScraperContainer withRmiServiceUrl(String host, int port) { // TODO: adding a way to provide 'host:port' syntax would make this easier for end users - this.serviceUrl = + return withServiceUrl( String.format( - Locale.getDefault(), "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi", host, port); + Locale.getDefault(), "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi", host, port)); + } + + @CanIgnoreReturnValue + public JmxScraperContainer withServiceUrl(String serviceUrl) { + this.serviceUrl = serviceUrl; + return this; + } + + /** + * Sets JMX user login + * + * @param user user login + * @return this + */ + @CanIgnoreReturnValue + public JmxScraperContainer withUser(String user) { + this.user = user; + return this; + } + + /** + * Sets JMX password + * + * @param password user password + * @return this + */ + @CanIgnoreReturnValue + public JmxScraperContainer withPassword(String password) { + this.password = password; + return this; + } + + /** + * Adds path to an extra jar for classpath + * + * @param jarPath path to an extra jar that should be added to jmx scraper classpath + * @return this + */ + @CanIgnoreReturnValue + public JmxScraperContainer withExtraJar(String jarPath) { + this.extraJars.add(jarPath); return this; } @@ -89,6 +134,13 @@ public void start() { arguments.add("-Dotel.jmx.service.url=" + serviceUrl); arguments.add("-Dotel.jmx.interval.milliseconds=" + intervalMillis); + if (user != null) { + arguments.add("-Dotel.jmx.username=" + user); + } + if (password != null) { + arguments.add("-Dotel.jmx.password=" + password); + } + if (!customYamlFiles.isEmpty()) { for (String yaml : customYamlFiles) { this.withCopyFileToContainer(MountableFile.forClasspathResource(yaml), yaml); @@ -96,8 +148,16 @@ public void start() { arguments.add("-Dotel.jmx.config=" + String.join(",", customYamlFiles)); } - arguments.add("-jar"); - arguments.add("/scraper.jar"); + if (extraJars.isEmpty()) { + // using "java -jar" to start + arguments.add("-jar"); + arguments.add("/scraper.jar"); + } else { + // using "java -cp" to start + arguments.add("-cp"); + arguments.add("/scraper.jar:" + String.join(":", extraJars)); + arguments.add("io.opentelemetry.contrib.jmxscraper.JmxScraper"); + } this.withCommand(arguments.toArray(new String[0])); From c42b6281f8fddbd6644833c9a1e7838db43e9e83 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:14:31 +0100 Subject: [PATCH 03/25] add support for login/pwd auth --- .../TargetSystemIntegrationTest.java | 2 +- .../contrib/jmxscraper/JmxConnectorBuilder.java | 17 +++++++++++------ .../contrib/jmxscraper/JmxScraper.java | 9 +++++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java index 4d4ca988b..cf89bc430 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java @@ -111,7 +111,7 @@ void endToEndTest() { new JmxScraperContainer(otlpEndpoint) .withLogConsumer(new Slf4jLogConsumer(jmxScraperLogger)) .withNetwork(network) - .withService(TARGET_SYSTEM_NETWORK_ALIAS, JMX_PORT); + .withRmiServiceUrl(TARGET_SYSTEM_NETWORK_ALIAS, JMX_PORT); scraper = customizeScraperContainer(scraper); scraper.start(); diff --git a/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxConnectorBuilder.java b/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxConnectorBuilder.java index eebca5fd4..5f34129ed 100644 --- a/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxConnectorBuilder.java +++ b/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxConnectorBuilder.java @@ -31,7 +31,7 @@ public class JmxConnectorBuilder { private static final Logger logger = Logger.getLogger(JmxConnectorBuilder.class.getName()); private final JMXServiceURL url; - @Nullable private String userName; + @Nullable private String user; @Nullable private String password; @Nullable private String profile; @Nullable private String realm; @@ -50,8 +50,13 @@ public static JmxConnectorBuilder createNew(String url) { } @CanIgnoreReturnValue - public JmxConnectorBuilder userCredentials(String userName, String password) { - this.userName = userName; + public JmxConnectorBuilder withUser(String user) { + this.user = user; + return this; + } + + @CanIgnoreReturnValue + public JmxConnectorBuilder withPassword(String password) { this.password = password; return this; } @@ -97,8 +102,8 @@ public JMXConnector build() throws IOException { private Map buildEnv() { Map env = new HashMap<>(); - if (userName != null && password != null) { - env.put(JMXConnector.CREDENTIALS, new String[] {userName, password}); + if (user != null && password != null) { + env.put(JMXConnector.CREDENTIALS, new String[] {user, password}); } if (profile != null) { @@ -118,7 +123,7 @@ private Map buildEnv() { callbacks -> { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { - ((NameCallback) callback).setName(userName); + ((NameCallback) callback).setName(user); } else if (callback instanceof PasswordCallback) { char[] pwd = password == null ? null : password.toCharArray(); ((PasswordCallback) callback).setPassword(pwd); diff --git a/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxScraper.java b/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxScraper.java index fdee1e0e4..fe82c698d 100644 --- a/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxScraper.java +++ b/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxScraper.java @@ -19,6 +19,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.Properties; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Logger; @@ -61,8 +62,12 @@ public static void main(String[] args) { JmxMetricInsight service = JmxMetricInsight.createService( GlobalOpenTelemetry.get(), config.getIntervalMilliseconds()); - JmxScraper jmxScraper = - new JmxScraper(JmxConnectorBuilder.createNew(config.getServiceUrl()), service, config); + JmxConnectorBuilder connectorBuilder = JmxConnectorBuilder.createNew(config.getServiceUrl()); + + Optional.ofNullable(config.getUsername()).ifPresent(connectorBuilder::withUser); + Optional.ofNullable(config.getPassword()).ifPresent(connectorBuilder::withPassword); + + JmxScraper jmxScraper = new JmxScraper(connectorBuilder, service, config); jmxScraper.start(); } catch (ArgumentsParsingException e) { From 8b5da8d5c73ab880802cafa2eab2f1e9e5536dbb Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:15:03 +0100 Subject: [PATCH 04/25] add wildfly with remote scraper config --- .../ActiveMqIntegrationTest.java | 3 +- .../CassandraIntegrationTest.java | 3 +- .../target_systems/JvmIntegrationTest.java | 3 +- .../TargetSystemIntegrationTest.java | 5 +- .../target_systems/TomcatIntegrationTest.java | 3 +- .../WildflyIntegrationTest.java | 83 +++++++++++++++++++ jmx-scraper/src/main/resources/wildfly.yaml | 12 +++ 7 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java create mode 100644 jmx-scraper/src/main/resources/wildfly.yaml diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java index 675c5d39d..caa5c35de 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java @@ -29,7 +29,8 @@ protected GenericContainer createTargetContainer(int jmxPort) { } @Override - protected JmxScraperContainer customizeScraperContainer(JmxScraperContainer scraper) { + protected JmxScraperContainer customizeScraperContainer( + JmxScraperContainer scraper, GenericContainer target) { return scraper.withTargetSystem("activemq"); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java index b3d7982c4..d382ceaf2 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java @@ -37,7 +37,8 @@ protected GenericContainer createTargetContainer(int jmxPort) { } @Override - protected JmxScraperContainer customizeScraperContainer(JmxScraperContainer scraper) { + protected JmxScraperContainer customizeScraperContainer( + JmxScraperContainer scraper, GenericContainer target) { return scraper.withTargetSystem("cassandra"); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JvmIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JvmIntegrationTest.java index 2b89914f3..7b85ad975 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JvmIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JvmIntegrationTest.java @@ -24,7 +24,8 @@ protected GenericContainer createTargetContainer(int jmxPort) { } @Override - protected JmxScraperContainer customizeScraperContainer(JmxScraperContainer scraper) { + protected JmxScraperContainer customizeScraperContainer( + JmxScraperContainer scraper, GenericContainer target) { return scraper.withTargetSystem("jvm"); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java index cf89bc430..bd42f9d7e 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java @@ -113,7 +113,7 @@ void endToEndTest() { .withNetwork(network) .withRmiServiceUrl(TARGET_SYSTEM_NETWORK_ALIAS, JMX_PORT); - scraper = customizeScraperContainer(scraper); + scraper = customizeScraperContainer(scraper, target); scraper.start(); verifyMetrics(); @@ -156,7 +156,8 @@ protected final void waitAndAssertMetrics(Consumer... assertions) { protected abstract void verifyMetrics(); - protected JmxScraperContainer customizeScraperContainer(JmxScraperContainer scraper) { + protected JmxScraperContainer customizeScraperContainer( + JmxScraperContainer scraper, GenericContainer target) { return scraper; } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java index 7b1313a1b..aebecfef9 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java @@ -36,7 +36,8 @@ protected GenericContainer createTargetContainer(int jmxPort) { } @Override - protected JmxScraperContainer customizeScraperContainer(JmxScraperContainer scraper) { + protected JmxScraperContainer customizeScraperContainer( + JmxScraperContainer scraper, GenericContainer target) { return scraper.withTargetSystem("tomcat"); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java new file mode 100644 index 000000000..d62523062 --- /dev/null +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java @@ -0,0 +1,83 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.contrib.jmxscraper.target_systems; + +import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.Duration; +import org.junit.jupiter.api.AfterAll; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.images.builder.ImageFromDockerfile; +import org.testcontainers.utility.MountableFile; + +public class WildflyIntegrationTest extends TargetSystemIntegrationTest { + + @SuppressWarnings("NonFinalStaticField") + private static Path tempJbossClient = null; + + @AfterAll + public static void cleanup() throws IOException { + if (tempJbossClient != null) { + Files.delete(tempJbossClient); + } + } + + // /opt/jboss/wildfly/standalone/tmp/auth/ + + @Override + protected GenericContainer createTargetContainer(int jmxPort) { + // JMX port is ignored here as we are using HTTP management interface + + return new GenericContainer<>( + new ImageFromDockerfile() + .withDockerfileFromBuilder( + builder -> + builder + .from("jboss/wildfly:23.0.1.Final") + // user/pwd needed for remote JMX access + .run("/opt/jboss/wildfly/bin/add-user.sh user password --silent") + // standalone with management (HTTP) interface enabled + .cmd( + "/opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0") + .expose(8080, 9990) + .build())) + .withStartupTimeout(Duration.ofMinutes(2)) + .waitingFor(Wait.forLogMessage(".*Http management interface listening on.*", 1)); + } + + @Override + protected JmxScraperContainer customizeScraperContainer( + JmxScraperContainer scraper, GenericContainer target) { + + if (tempJbossClient == null) { + // copy jboss-client.jar from jboss/wildfly container + try { + tempJbossClient = Files.createTempFile("jboss_", "_test").toAbsolutePath(); + target.copyFileFromContainer( + "/opt/jboss/wildfly/bin/client/jboss-client.jar", tempJbossClient.toString()); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + return scraper + .withTargetSystem("wildfly") + // copy jboss-client.jar and add it to scraper classpath + .withCopyFileToContainer(MountableFile.forHostPath(tempJbossClient), "/jboss-client.jar") + .withExtraJar("/jboss-client.jar") + // using jboss remote HTTP protocol provided in jboss-client.jar + .withServiceUrl("service:jmx:remote+http://targetsystem:9990") + // admin user created when creating container + .withUser("user") + .withPassword("password"); + } + + @Override + protected void verifyMetrics() {} +} diff --git a/jmx-scraper/src/main/resources/wildfly.yaml b/jmx-scraper/src/main/resources/wildfly.yaml new file mode 100644 index 000000000..ab6865988 --- /dev/null +++ b/jmx-scraper/src/main/resources/wildfly.yaml @@ -0,0 +1,12 @@ +--- + +rules: + + - bean: jboss.as:deployment=*,subsystem=undertow + metricAttribute: + deployment: param(deployment) + mapping: + sessionsCreated: + metric: wildfly.session.count + unit: "{session}" + desc: The number of sessions created. From 86fca55b10993536c2f5a24b9227dece6f4a1eff Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:56:11 +0100 Subject: [PATCH 05/25] fix inconsistencies + start testing --- .../WildflyIntegrationTest.java | 14 +++-- .../resources/target-systems/wildfly.groovy | 24 +++++--- .../target_systems/MetricAssertions.java | 2 +- .../WildflyIntegrationTest.java | 61 +++++++++++++++++-- jmx-scraper/src/main/resources/wildfly.yaml | 33 ++++++++++ 5 files changed, 111 insertions(+), 23 deletions(-) diff --git a/jmx-metrics/src/integrationTest/java/io/opentelemetry/contrib/jmxmetrics/target_systems/WildflyIntegrationTest.java b/jmx-metrics/src/integrationTest/java/io/opentelemetry/contrib/jmxmetrics/target_systems/WildflyIntegrationTest.java index 0aeaf0973..e6d3a6d0d 100644 --- a/jmx-metrics/src/integrationTest/java/io/opentelemetry/contrib/jmxmetrics/target_systems/WildflyIntegrationTest.java +++ b/jmx-metrics/src/integrationTest/java/io/opentelemetry/contrib/jmxmetrics/target_systems/WildflyIntegrationTest.java @@ -54,7 +54,7 @@ void endToEnd() { metric, "wildfly.request.count", "The number of requests received.", - "{requests}", + "{request}", attrs -> attrs.containsOnly( entry("server", "default-server"), entry("listener", "default"))), @@ -72,7 +72,7 @@ void endToEnd() { metric, "wildfly.request.server_error", "The number of requests that have resulted in a 5xx response.", - "{requests}", + "{request}", attrs -> attrs.containsOnly( entry("server", "default-server"), entry("listener", "default"))), @@ -92,12 +92,14 @@ void endToEnd() { entry("server", "default-server"), entry("listener", "default"), entry("state", "out"))), + + // TODO from here: metric -> assertSumWithAttributes( metric, "wildfly.jdbc.connection.open", "The number of open jdbc connections.", - "{connections}", + "{connection}", attrs -> attrs.containsOnly(entry("data_source", "ExampleDS"), entry("state", "active")), attrs -> @@ -107,20 +109,20 @@ void endToEnd() { metric, "wildfly.jdbc.request.wait", "The number of jdbc connections that had to wait before opening.", - "{requests}", + "{request}", attrs -> attrs.containsOnly(entry("data_source", "ExampleDS"))), metric -> assertSum( metric, "wildfly.jdbc.transaction.count", "The number of transactions created.", - "{transactions}"), + "{transaction}"), metric -> assertSumWithAttributes( metric, "wildfly.jdbc.rollback.count", "The number of transactions rolled back.", - "{transactions}", + "{transaction}", attrs -> attrs.containsOnly(entry("cause", "system")), attrs -> attrs.containsOnly(entry("cause", "resource")), attrs -> attrs.containsOnly(entry("cause", "application")))); diff --git a/jmx-metrics/src/main/resources/target-systems/wildfly.groovy b/jmx-metrics/src/main/resources/target-systems/wildfly.groovy index feaf4f22e..ae893f767 100644 --- a/jmx-metrics/src/main/resources/target-systems/wildfly.groovy +++ b/jmx-metrics/src/main/resources/target-systems/wildfly.groovy @@ -15,27 +15,31 @@ */ def beanWildflyDeployment = otel.mbeans("jboss.as:deployment=*,subsystem=undertow") -otel.instrument(beanWildflyDeployment, "wildfly.session.count", "The number of sessions created.", "{sessions}", +// no test covers sessions +otel.instrument(beanWildflyDeployment, "wildfly.session.count", "The number of sessions created.", "{session}", ["deployment": { mbean -> mbean.name().getKeyProperty("deployment")}], "sessionsCreated", otel.&longCounterCallback) -otel.instrument(beanWildflyDeployment, "wildfly.session.active", "The number of currently active sessions.", "{sessions}", + +otel.instrument(beanWildflyDeployment, "wildfly.session.active", "The number of currently active sessions.", "{session}", ["deployment": { mbean -> mbean.name().getKeyProperty("deployment")}], "activeSessions", otel.&longUpDownCounterCallback) -otel.instrument(beanWildflyDeployment, "wildfly.session.expired", "The number of sessions that have expired.", "{sessions}", +otel.instrument(beanWildflyDeployment, "wildfly.session.expired", "The number of sessions that have expired.", "{session}", ["deployment": { mbean -> mbean.name().getKeyProperty("deployment")}], "expiredSessions", otel.&longCounterCallback) -otel.instrument(beanWildflyDeployment, "wildfly.session.rejected", "The number of sessions that have been rejected.", "{sessions}", +otel.instrument(beanWildflyDeployment, "wildfly.session.rejected", "The number of sessions that have been rejected.", "{session}", ["deployment": { mbean -> mbean.name().getKeyProperty("deployment")}], "rejectedSessions", otel.&longCounterCallback) + + def beanWildflyHttpListener = otel.mbeans("jboss.as:subsystem=undertow,server=*,http-listener=*") -otel.instrument(beanWildflyHttpListener, "wildfly.request.count", "The number of requests received.", "{requests}", +otel.instrument(beanWildflyHttpListener, "wildfly.request.count", "The number of requests received.", "{request}", ["server": { mbean -> mbean.name().getKeyProperty("server")}, "listener": { mbean -> mbean.name().getKeyProperty("http-listener")}], "requestCount", otel.&longCounterCallback) otel.instrument(beanWildflyHttpListener, "wildfly.request.time", "The total amount of time spent on requests.", "ns", ["server": { mbean -> mbean.name().getKeyProperty("server")}, "listener": { mbean -> mbean.name().getKeyProperty("http-listener")}], "processingTime", otel.&longCounterCallback) -otel.instrument(beanWildflyHttpListener, "wildfly.request.server_error", "The number of requests that have resulted in a 5xx response.", "{requests}", +otel.instrument(beanWildflyHttpListener, "wildfly.request.server_error", "The number of requests that have resulted in a 5xx response.", "{request}", ["server": { mbean -> mbean.name().getKeyProperty("server")}, "listener": { mbean -> mbean.name().getKeyProperty("http-listener")}], "errorCount", otel.&longCounterCallback) otel.instrument(beanWildflyHttpListener, "wildfly.network.io", "The number of bytes transmitted.", "by", @@ -44,17 +48,17 @@ otel.instrument(beanWildflyHttpListener, "wildfly.network.io", "The number of by otel.&longCounterCallback) def beanWildflyDataSource = otel.mbeans("jboss.as:subsystem=datasources,data-source=*,statistics=pool") -otel.instrument(beanWildflyDataSource, "wildfly.jdbc.connection.open", "The number of open jdbc connections.", "{connections}", +otel.instrument(beanWildflyDataSource, "wildfly.jdbc.connection.open", "The number of open jdbc connections.", "{connection}", ["data_source": { mbean -> mbean.name().getKeyProperty("data-source")}], ["ActiveCount":["state":{"active"}], "IdleCount":["state":{"idle"}]], otel.&longUpDownCounterCallback) -otel.instrument(beanWildflyDataSource, "wildfly.jdbc.request.wait", "The number of jdbc connections that had to wait before opening.", "{requests}", +otel.instrument(beanWildflyDataSource, "wildfly.jdbc.request.wait", "The number of jdbc connections that had to wait before opening.", "{request}", ["data_source": { mbean -> mbean.name().getKeyProperty("data-source")}], "WaitCount", otel.&longCounterCallback) def beanWildflyTransaction = otel.mbean("jboss.as:subsystem=transactions") -otel.instrument(beanWildflyTransaction, "wildfly.jdbc.transaction.count", "The number of transactions created.", "{transactions}", +otel.instrument(beanWildflyTransaction, "wildfly.jdbc.transaction.count", "The number of transactions created.", "{transaction}", "numberOfTransactions", otel.&longCounterCallback) -otel.instrument(beanWildflyTransaction, "wildfly.jdbc.rollback.count", "The number of transactions rolled back.", "{transactions}", +otel.instrument(beanWildflyTransaction, "wildfly.jdbc.rollback.count", "The number of transactions rolled back.", "{transaction}", ["numberOfSystemRollbacks":["cause":{"system"}], "numberOfResourceRollbacks":["cause":{"resource"}], "numberOfApplicationRollbacks":["cause":{"application"}]], otel.&longCounterCallback) diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/MetricAssertions.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/MetricAssertions.java index cbd46c350..ceba8465b 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/MetricAssertions.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/MetricAssertions.java @@ -87,7 +87,7 @@ static void assertSumWithAttributes( assertThat(metric.getName()).isEqualTo(name); assertThat(metric.getDescription()).isEqualTo(description); assertThat(metric.getUnit()).isEqualTo(unit); - assertThat(metric.hasSum()).isTrue(); + assertThat(metric.hasSum()).describedAs("sum expected").isTrue(); assertThat(metric.getSum().getIsMonotonic()).isEqualTo(isMonotonic); assertAttributedPoints(metric.getSum().getDataPointsList(), attributeGroupAssertions); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java index d62523062..352356364 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java @@ -16,6 +16,9 @@ import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.utility.MountableFile; +import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributes; +import static org.assertj.core.api.Assertions.entry; + public class WildflyIntegrationTest extends TargetSystemIntegrationTest { @SuppressWarnings("NonFinalStaticField") @@ -28,8 +31,6 @@ public static void cleanup() throws IOException { } } - // /opt/jboss/wildfly/standalone/tmp/auth/ - @Override protected GenericContainer createTargetContainer(int jmxPort) { // JMX port is ignored here as we are using HTTP management interface @@ -68,16 +69,64 @@ protected JmxScraperContainer customizeScraperContainer( return scraper .withTargetSystem("wildfly") - // copy jboss-client.jar and add it to scraper classpath + // Copy jboss-client.jar and add it to scraper classpath .withCopyFileToContainer(MountableFile.forHostPath(tempJbossClient), "/jboss-client.jar") .withExtraJar("/jboss-client.jar") - // using jboss remote HTTP protocol provided in jboss-client.jar + // Using jboss remote HTTP protocol provided in jboss-client.jar .withServiceUrl("service:jmx:remote+http://targetsystem:9990") - // admin user created when creating container + // Admin user created when creating container + // When scraper is running on same host as jboss/wildfly a local file challenge can be used + // for authentication, but here we have to use valid credentials for remote access .withUser("user") .withPassword("password"); } @Override - protected void verifyMetrics() {} + protected void verifyMetrics() { + waitAndAssertMetrics( + metric -> + assertSumWithAttributes( + metric, + "wildfly.request.count", + "The number of requests received.", + "{request}", + attrs -> + attrs.containsOnly( + entry("server", "default-server"), entry("listener", "default"))), + metric -> + assertSumWithAttributes( + metric, + "wildfly.request.time", + "The total amount of time spent on requests.", + "ns", + attrs -> + attrs.containsOnly( + entry("server", "default-server"), entry("listener", "default"))), + metric -> + assertSumWithAttributes( + metric, + "wildfly.request.server_error", + "The number of requests that have resulted in a 5xx response.", + "{request}", + attrs -> + attrs.containsOnly( + entry("server", "default-server"), entry("listener", "default"))), + metric -> + assertSumWithAttributes( + metric, + "wildfly.network.io", + "The number of bytes transmitted.", + "by", + attrs -> + attrs.containsOnly( + entry("server", "default-server"), + entry("listener", "default"), + entry("state", "in")), + attrs -> + attrs.containsOnly( + entry("server", "default-server"), + entry("listener", "default"), + entry("state", "out"))) + ); + } } diff --git a/jmx-scraper/src/main/resources/wildfly.yaml b/jmx-scraper/src/main/resources/wildfly.yaml index ab6865988..0a43b07c6 100644 --- a/jmx-scraper/src/main/resources/wildfly.yaml +++ b/jmx-scraper/src/main/resources/wildfly.yaml @@ -2,6 +2,7 @@ rules: + # TODO: sessions are not tested in the original groovy implementation - bean: jboss.as:deployment=*,subsystem=undertow metricAttribute: deployment: param(deployment) @@ -10,3 +11,35 @@ rules: metric: wildfly.session.count unit: "{session}" desc: The number of sessions created. + + - bean: jboss.as:subsystem=undertow,server=*,http-listener=* + metricAttribute: + server: param(server) + listener: param(http-listener) + prefix: wildfly. + type: counter + mapping: + requestCount: + metric: request.count + unit: "{request}" + desc: The number of requests received. + processingTime: + metric: request.time + unit: ns + desc: The total amount of time spent on requests. + errorCount: + metric: request.server_error + unit: "{request}" + desc: The number of requests that have resulted in a 5xx response. + bytesSent: + metric: network.io + unit: "by" + desc: "The number of bytes transmitted." + metricAttribute: + state: const(out) + bytesReceived: + metric: network.io + unit: "by" + desc: "The number of bytes transmitted." + metricAttribute: + state: const(in) From 7dbafa830554503b7b41fdf8e700020a9b63ae9e Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:59:17 +0100 Subject: [PATCH 06/25] remove useless changes + reformat --- .../target_systems/ActiveMqIntegrationTest.java | 9 ++++++++- .../target_systems/CassandraIntegrationTest.java | 10 +++++++--- .../target_systems/TargetSystemIntegrationTest.java | 10 ---------- .../target_systems/TomcatIntegrationTest.java | 10 +++++++++- .../target_systems/WildflyIntegrationTest.java | 9 ++++----- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java index caa5c35de..88a380835 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java @@ -23,7 +23,14 @@ protected GenericContainer createTargetContainer(int jmxPort) { new ImageFromDockerfile() .withDockerfileFromBuilder( builder -> builder.from("apache/activemq-classic:5.18.6").build())) - .withEnv("JAVA_TOOL_OPTIONS", genericJmxJvmArguments(jmxPort)) + .withEnv( + "JAVA_TOOL_OPTIONS", + "-Dcom.sun.management.jmxremote.port=" + + jmxPort + + " -Dcom.sun.management.jmxremote.rmi.port=" + + jmxPort + + " -Dcom.sun.management.jmxremote.ssl=false" + + " -Dcom.sun.management.jmxremote.authenticate=false") .withStartupTimeout(Duration.ofMinutes(2)) .waitingFor(Wait.forListeningPort()); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java index d382ceaf2..4d1cf7cce 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java @@ -29,9 +29,13 @@ protected GenericContainer createTargetContainer(int jmxPort) { .withDockerfileFromBuilder(builder -> builder.from("cassandra:5.0.2").build())) .withEnv( "JVM_EXTRA_OPTS", - genericJmxJvmArguments(jmxPort) - // making cassandra startup faster for single node, from ~1min to ~15s - + " -Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=0") + " -Dcassandra.jmx.remote.port=" + + jmxPort + + " -Dcom.sun.management.jmxremote.rmi.port=" + + jmxPort + + " -Dcom.sun.management.jmxremote.local.only=false" + + " -Dcom.sun.management.jmxremote.ssl=false" + + " -Dcom.sun.management.jmxremote.authenticate=false") .withStartupTimeout(Duration.ofMinutes(2)) .waitingFor(Wait.forLogMessage(".*Startup complete.*", 1)); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java index bd42f9d7e..7e5789ed9 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java @@ -197,14 +197,4 @@ public void export( sb.http(0); } } - - protected static String genericJmxJvmArguments(int port) { - return "-Dcom.sun.management.jmxremote.local.only=false" - + " -Dcom.sun.management.jmxremote.authenticate=false" - + " -Dcom.sun.management.jmxremote.ssl=false" - + " -Dcom.sun.management.jmxremote.port=" - + port - + " -Dcom.sun.management.jmxremote.rmi.port=" - + port; - } } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java index aebecfef9..a70c9c173 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java @@ -30,7 +30,15 @@ protected GenericContainer createTargetContainer(int jmxPort) { "https://tomcat.apache.org/tomcat-9.0-doc/appdev/sample/sample.war", "/usr/local/tomcat/webapps/ROOT.war") .build())) - .withEnv("CATALINA_OPTS", genericJmxJvmArguments(jmxPort)) + .withEnv( + "CATALINA_OPTS", + "-Dcom.sun.management.jmxremote.local.only=false" + + " -Dcom.sun.management.jmxremote.authenticate=false" + + " -Dcom.sun.management.jmxremote.ssl=false" + + " -Dcom.sun.management.jmxremote.port=" + + jmxPort + + " -Dcom.sun.management.jmxremote.rmi.port=" + + jmxPort) .withStartupTimeout(Duration.ofMinutes(2)) .waitingFor(Wait.forListeningPort()); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java index 352356364..6e16c5abc 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java @@ -5,6 +5,9 @@ package io.opentelemetry.contrib.jmxscraper.target_systems; +import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributes; +import static org.assertj.core.api.Assertions.entry; + import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer; import java.io.IOException; import java.nio.file.Files; @@ -16,9 +19,6 @@ import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.utility.MountableFile; -import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributes; -import static org.assertj.core.api.Assertions.entry; - public class WildflyIntegrationTest extends TargetSystemIntegrationTest { @SuppressWarnings("NonFinalStaticField") @@ -126,7 +126,6 @@ protected void verifyMetrics() { attrs.containsOnly( entry("server", "default-server"), entry("listener", "default"), - entry("state", "out"))) - ); + entry("state", "out")))); } } From 20354afab6e5a2927067be8928d8a0dd7cb76b44 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:30:36 +0100 Subject: [PATCH 07/25] all but session metrics covered --- .../WildflyIntegrationTest.java | 36 +++++++++++- jmx-scraper/src/main/resources/wildfly.yaml | 57 +++++++++++++++---- 2 files changed, 82 insertions(+), 11 deletions(-) diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java index 6e16c5abc..743ee36a4 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.contrib.jmxscraper.target_systems; +import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSum; import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributes; import static org.assertj.core.api.Assertions.entry; @@ -126,6 +127,39 @@ protected void verifyMetrics() { attrs.containsOnly( entry("server", "default-server"), entry("listener", "default"), - entry("state", "out")))); + entry("state", "out"))), + metric -> + assertSumWithAttributes( + metric, + "wildfly.jdbc.connection.open", + "The number of open jdbc connections.", + "{connection}", + attrs -> + attrs.containsOnly(entry("data_source", "ExampleDS"), entry("state", "active")), + attrs -> + attrs.containsOnly(entry("data_source", "ExampleDS"), entry("state", "idle"))), + metric -> + assertSumWithAttributes( + metric, + "wildfly.jdbc.request.wait", + "The number of jdbc connections that had to wait before opening.", + "{request}", + attrs -> attrs.containsOnly(entry("data_source", "ExampleDS"))), + metric -> + assertSum( + metric, + "wildfly.jdbc.transaction.count", + "The number of transactions created.", + "{transaction}"), + metric -> + assertSumWithAttributes( + metric, + "wildfly.jdbc.rollback.count", + "The number of transactions rolled back.", + "{transaction}", + attrs -> attrs.containsOnly(entry("cause", "system")), + attrs -> attrs.containsOnly(entry("cause", "resource")), + attrs -> attrs.containsOnly(entry("cause", "application"))) + ); } } diff --git a/jmx-scraper/src/main/resources/wildfly.yaml b/jmx-scraper/src/main/resources/wildfly.yaml index 0a43b07c6..0e9ca80eb 100644 --- a/jmx-scraper/src/main/resources/wildfly.yaml +++ b/jmx-scraper/src/main/resources/wildfly.yaml @@ -2,16 +2,6 @@ rules: - # TODO: sessions are not tested in the original groovy implementation - - bean: jboss.as:deployment=*,subsystem=undertow - metricAttribute: - deployment: param(deployment) - mapping: - sessionsCreated: - metric: wildfly.session.count - unit: "{session}" - desc: The number of sessions created. - - bean: jboss.as:subsystem=undertow,server=*,http-listener=* metricAttribute: server: param(server) @@ -43,3 +33,50 @@ rules: desc: "The number of bytes transmitted." metricAttribute: state: const(in) + + - bean: jboss.as:subsystem=datasources,data-source=*,statistics=pool + metricAttribute: + data_source: param(data-source) + type: counter + prefix: wildfly.jdbc. + mapping: + ActiveCount: + metric: connection.open + unit: "{connection}" + desc: The number of open jdbc connections. + metricAttribute: + state: const(active) + IdleCount: + metric: connection.open + unit: "{connection}" + desc: The number of open jdbc connections. + metricAttribute: + state: const(idle) + WaitCount: + metric: request.wait + unit: "{request}" + desc: The number of jdbc connections that had to wait before opening. + + - bean: jboss.as:subsystem=transactions + prefix: wildfly.jdbc. + unit: "{transaction}" + type: counter + mapping: + numberOfTransactions: + metric: transaction.count + desc: The number of transactions created. + numberOfSystemRollbacks: + metric: rollback.count + desc: The number of transactions rolled back. + metricAttribute: + cause: const(system) + numberOfResourceRollbacks: + metric: rollback.count + desc: The number of transactions rolled back. + metricAttribute: + cause: const(resource) + numberOfApplicationRollbacks: + metric: rollback.count + desc: The number of transactions rolled back. + metricAttribute: + cause: const(application) From 927fee2706fecc3f29f51dbf56af351f8b1ba39e Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:42:04 +0100 Subject: [PATCH 08/25] prepare moving TestApp to separate sourceSet --- .../contrib/jmxscraper/JmxConnectorBuilderTest.java | 2 +- .../io/opentelemetry/contrib/jmxscraper/TestApp.java | 9 +++------ .../contrib/jmxscraper/TestAppContainer.java | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxConnectorBuilderTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxConnectorBuilderTest.java index 5b57121cb..f3f931e58 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxConnectorBuilderTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxConnectorBuilderTest.java @@ -76,7 +76,7 @@ private static void testConnector(ConnectorSupplier connectorSupplier) { .satisfies( connection -> { try { - ObjectName name = new ObjectName(TestApp.OBJECT_NAME); + ObjectName name = new ObjectName("io.opentelemetry.test:name=TestApp"); Object value = connection.getAttribute(name, "IntValue"); assertThat(value).isEqualTo(42); } catch (Exception e) { diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestApp.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestApp.java index 1316ca036..c7f91ac18 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestApp.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestApp.java @@ -9,14 +9,11 @@ import javax.management.MBeanServer; import javax.management.ObjectName; -@SuppressWarnings("all") public class TestApp implements TestAppMXBean { - public static final String APP_STARTED_MSG = "app started"; - public static final String OBJECT_NAME = "io.opentelemetry.test:name=TestApp"; - private volatile boolean running; + @SuppressWarnings("BusyWait") public static void main(String[] args) { TestApp app = TestApp.start(); while (app.isRunning()) { @@ -34,13 +31,13 @@ static TestApp start() { TestApp app = new TestApp(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { - ObjectName objectName = new ObjectName(OBJECT_NAME); + ObjectName objectName = new ObjectName("io.opentelemetry.test:name=TestApp"); mbs.registerMBean(app, objectName); } catch (Exception e) { throw new RuntimeException(e); } app.running = true; - System.out.println(APP_STARTED_MSG); + System.out.println("app started"); return app; } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestAppContainer.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestAppContainer.java index 990a316c9..3b2fe13d7 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestAppContainer.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestAppContainer.java @@ -21,7 +21,7 @@ import org.testcontainers.shaded.com.google.errorprone.annotations.CanIgnoreReturnValue; import org.testcontainers.utility.MountableFile; -/** Test container that allows to execute {@link TestApp} in an isolated container */ +/** Test container that allows to execute TestApp in an isolated container */ public class TestAppContainer extends GenericContainer { private final Map properties; @@ -38,7 +38,7 @@ public TestAppContainer() { this.withCopyFileToContainer(MountableFile.forHostPath(appJar), "/app.jar") .waitingFor( - Wait.forLogMessage(TestApp.APP_STARTED_MSG + "\\n", 1) + Wait.forLogMessage("app started\\n", 1) .withStartupTimeout(Duration.ofSeconds(5))) .withCommand("java", "-jar", "/app.jar"); } From 2029c991ae7684961cfa62a9b6c392424140ef47 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:52:22 +0100 Subject: [PATCH 09/25] move test app to separate sourceset --- jmx-scraper/build.gradle.kts | 7 ++++++- .../java/io/opentelemetry/contrib/jmxscraper/TestApp.java | 2 +- .../io/opentelemetry/contrib/jmxscraper/TestAppMXBean.java | 0 3 files changed, 7 insertions(+), 2 deletions(-) rename jmx-scraper/src/{integrationTest => testApp}/java/io/opentelemetry/contrib/jmxscraper/TestApp.java (95%) rename jmx-scraper/src/{integrationTest => testApp}/java/io/opentelemetry/contrib/jmxscraper/TestAppMXBean.java (100%) diff --git a/jmx-scraper/build.gradle.kts b/jmx-scraper/build.gradle.kts index c2e7eb387..52e0cf37b 100644 --- a/jmx-scraper/build.gradle.kts +++ b/jmx-scraper/build.gradle.kts @@ -43,6 +43,11 @@ testing { } } +sourceSets { + create("testApp") { + } +} + tasks { shadowJar { mergeServiceFiles() @@ -75,7 +80,7 @@ tasks { } tasks.register("appJar") { - from(sourceSets.get("integrationTest").output) + from(sourceSets.get("testApp").output) archiveClassifier.set("app") manifest { attributes["Main-Class"] = "io.opentelemetry.contrib.jmxscraper.TestApp" diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestApp.java b/jmx-scraper/src/testApp/java/io/opentelemetry/contrib/jmxscraper/TestApp.java similarity index 95% rename from jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestApp.java rename to jmx-scraper/src/testApp/java/io/opentelemetry/contrib/jmxscraper/TestApp.java index c7f91ac18..0bf43a04b 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestApp.java +++ b/jmx-scraper/src/testApp/java/io/opentelemetry/contrib/jmxscraper/TestApp.java @@ -9,11 +9,11 @@ import javax.management.MBeanServer; import javax.management.ObjectName; +@SuppressWarnings("all") // for busy wait + stdout public class TestApp implements TestAppMXBean { private volatile boolean running; - @SuppressWarnings("BusyWait") public static void main(String[] args) { TestApp app = TestApp.start(); while (app.isRunning()) { diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestAppMXBean.java b/jmx-scraper/src/testApp/java/io/opentelemetry/contrib/jmxscraper/TestAppMXBean.java similarity index 100% rename from jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestAppMXBean.java rename to jmx-scraper/src/testApp/java/io/opentelemetry/contrib/jmxscraper/TestAppMXBean.java From bccf90d92cdefbdd402da1ac7482a0f04009d011 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:51:13 +0100 Subject: [PATCH 10/25] move test apps + deploy on wildfly --- jmx-scraper/build.gradle.kts | 24 +++++++------------ .../jmxscraper/JmxScraperContainer.java | 4 ++-- .../contrib/jmxscraper/TestAppContainer.java | 3 +-- .../TargetSystemIntegrationTest.java | 6 ++++- .../WildflyIntegrationTest.java | 20 +++++++++++++--- jmx-scraper/test-app/build.gradle.kts | 13 ++++++++++ .../contrib/jmxscraper/testapp}/TestApp.java | 4 ++-- .../jmxscraper/testapp/TestAppMxBean.java} | 7 ++++-- jmx-scraper/test-webapp/build.gradle.kts | 15 ++++++++++++ .../jmxscraper/testwebapp/SimpleServlet.java | 24 +++++++++++++++++++ .../src/main/webapp/WEB-INF/web.xml | 14 +++++++++++ settings.gradle.kts | 2 ++ 12 files changed, 109 insertions(+), 27 deletions(-) create mode 100644 jmx-scraper/test-app/build.gradle.kts rename jmx-scraper/{src/testApp/java/io/opentelemetry/contrib/jmxscraper => test-app/src/main/java/io/opentelemetry/contrib/jmxscraper/testapp}/TestApp.java (91%) rename jmx-scraper/{src/testApp/java/io/opentelemetry/contrib/jmxscraper/TestAppMXBean.java => test-app/src/main/java/io/opentelemetry/contrib/jmxscraper/testapp/TestAppMxBean.java} (55%) create mode 100644 jmx-scraper/test-webapp/build.gradle.kts create mode 100644 jmx-scraper/test-webapp/src/main/java/io/opentelemetry/contrib/jmxscraper/testwebapp/SimpleServlet.java create mode 100644 jmx-scraper/test-webapp/src/main/webapp/WEB-INF/web.xml diff --git a/jmx-scraper/build.gradle.kts b/jmx-scraper/build.gradle.kts index 52e0cf37b..964fc79fb 100644 --- a/jmx-scraper/build.gradle.kts +++ b/jmx-scraper/build.gradle.kts @@ -43,11 +43,6 @@ testing { } } -sourceSets { - create("testApp") { - } -} - tasks { shadowJar { mergeServiceFiles() @@ -65,9 +60,16 @@ tasks { withType().configureEach { dependsOn(shadowJar) - dependsOn(named("appJar")) systemProperty("shadow.jar.path", shadowJar.get().archiveFile.get().asFile.absolutePath) - systemProperty("app.jar.path", named("appJar").get().archiveFile.get().asFile.absolutePath) + + val testAppTask = project("test-app").tasks.named("jar") + dependsOn(testAppTask) + systemProperty("app.jar.path", testAppTask.get().archiveFile.get().asFile.absolutePath) + + val testWarTask = project("test-webapp").tasks.named("war") + dependsOn(testWarTask) + systemProperty("app.war.path", testWarTask.get().archiveFile.get().asFile.absolutePath) + systemProperty("gradle.project.version", "${project.version}") } @@ -79,14 +81,6 @@ tasks { } } -tasks.register("appJar") { - from(sourceSets.get("testApp").output) - archiveClassifier.set("app") - manifest { - attributes["Main-Class"] = "io.opentelemetry.contrib.jmxscraper.TestApp" - } -} - // Don't publish non-shadowed jar (shadowJar is in shadowRuntimeElements) with(components["java"] as AdhocComponentWithVariants) { configurations.forEach { diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxScraperContainer.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxScraperContainer.java index 2d6b8864b..cbb06a784 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxScraperContainer.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxScraperContainer.java @@ -30,8 +30,8 @@ public class JmxScraperContainer extends GenericContainer { private String password; private final List extraJars; - public JmxScraperContainer(String otlpEndpoint) { - super("openjdk:8u342-jre-slim"); + public JmxScraperContainer(String otlpEndpoint, String baseImage) { + super(baseImage); String scraperJarPath = System.getProperty("shadow.jar.path"); assertThat(scraperJarPath).isNotNull(); diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestAppContainer.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestAppContainer.java index 3b2fe13d7..649153a41 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestAppContainer.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestAppContainer.java @@ -38,8 +38,7 @@ public TestAppContainer() { this.withCopyFileToContainer(MountableFile.forHostPath(appJar), "/app.jar") .waitingFor( - Wait.forLogMessage("app started\\n", 1) - .withStartupTimeout(Duration.ofSeconds(5))) + Wait.forLogMessage("app started\\n", 1).withStartupTimeout(Duration.ofSeconds(5))) .withCommand("java", "-jar", "/app.jar"); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java index 7e5789ed9..206f03ee4 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java @@ -97,6 +97,10 @@ void afterEach() { } } + protected String scraperBaseImage() { + return "openjdk:8u342-jre-slim"; + } + @Test void endToEndTest() { @@ -108,7 +112,7 @@ void endToEndTest() { target.start(); scraper = - new JmxScraperContainer(otlpEndpoint) + new JmxScraperContainer(otlpEndpoint, scraperBaseImage()) .withLogConsumer(new Slf4jLogConsumer(jmxScraperLogger)) .withNetwork(network) .withRmiServiceUrl(TARGET_SYSTEM_NETWORK_ALIAS, JMX_PORT); diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java index 743ee36a4..098315563 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java @@ -7,12 +7,14 @@ import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSum; import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributes; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.time.Duration; import org.junit.jupiter.api.AfterAll; import org.testcontainers.containers.GenericContainer; @@ -36,12 +38,16 @@ public static void cleanup() throws IOException { protected GenericContainer createTargetContainer(int jmxPort) { // JMX port is ignored here as we are using HTTP management interface + String appWar = System.getProperty("app.war.path"); + Path appWarPath = Paths.get(appWar); + assertThat(appWarPath).isNotEmptyFile().isReadable(); + return new GenericContainer<>( new ImageFromDockerfile() .withDockerfileFromBuilder( builder -> builder - .from("jboss/wildfly:23.0.1.Final") + .from("quay.io/wildfly/wildfly:32.0.1.Final-jdk11") // user/pwd needed for remote JMX access .run("/opt/jboss/wildfly/bin/add-user.sh user password --silent") // standalone with management (HTTP) interface enabled @@ -49,10 +55,19 @@ protected GenericContainer createTargetContainer(int jmxPort) { "/opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0") .expose(8080, 9990) .build())) + .withCopyFileToContainer( + MountableFile.forHostPath(appWarPath), + "/opt/jboss/wildfly/standalone/deployments/testapp.war") .withStartupTimeout(Duration.ofMinutes(2)) .waitingFor(Wait.forLogMessage(".*Http management interface listening on.*", 1)); } + @Override + protected String scraperBaseImage() { + // we need to run the scraper with Java 11+ because jboss client jar is using Java 11 + return "eclipse-temurin:11.0.25_9-jdk-noble"; + } + @Override protected JmxScraperContainer customizeScraperContainer( JmxScraperContainer scraper, GenericContainer target) { @@ -159,7 +174,6 @@ protected void verifyMetrics() { "{transaction}", attrs -> attrs.containsOnly(entry("cause", "system")), attrs -> attrs.containsOnly(entry("cause", "resource")), - attrs -> attrs.containsOnly(entry("cause", "application"))) - ); + attrs -> attrs.containsOnly(entry("cause", "application")))); } } diff --git a/jmx-scraper/test-app/build.gradle.kts b/jmx-scraper/test-app/build.gradle.kts new file mode 100644 index 000000000..543318410 --- /dev/null +++ b/jmx-scraper/test-app/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + application +} + +description = "JMX metrics scraper - test application" + +tasks { + jar { + manifest { + attributes["Main-Class"] = "io.opentelemetry.contrib.jmxscraper.testapp.TestApp" + } + } +} diff --git a/jmx-scraper/src/testApp/java/io/opentelemetry/contrib/jmxscraper/TestApp.java b/jmx-scraper/test-app/src/main/java/io/opentelemetry/contrib/jmxscraper/testapp/TestApp.java similarity index 91% rename from jmx-scraper/src/testApp/java/io/opentelemetry/contrib/jmxscraper/TestApp.java rename to jmx-scraper/test-app/src/main/java/io/opentelemetry/contrib/jmxscraper/testapp/TestApp.java index 0bf43a04b..9883abceb 100644 --- a/jmx-scraper/src/testApp/java/io/opentelemetry/contrib/jmxscraper/TestApp.java +++ b/jmx-scraper/test-app/src/main/java/io/opentelemetry/contrib/jmxscraper/testapp/TestApp.java @@ -3,14 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.contrib.jmxscraper; +package io.opentelemetry.contrib.jmxscraper.testapp; import java.lang.management.ManagementFactory; import javax.management.MBeanServer; import javax.management.ObjectName; @SuppressWarnings("all") // for busy wait + stdout -public class TestApp implements TestAppMXBean { +public class TestApp implements TestAppMxBean { private volatile boolean running; diff --git a/jmx-scraper/src/testApp/java/io/opentelemetry/contrib/jmxscraper/TestAppMXBean.java b/jmx-scraper/test-app/src/main/java/io/opentelemetry/contrib/jmxscraper/testapp/TestAppMxBean.java similarity index 55% rename from jmx-scraper/src/testApp/java/io/opentelemetry/contrib/jmxscraper/TestAppMXBean.java rename to jmx-scraper/test-app/src/main/java/io/opentelemetry/contrib/jmxscraper/testapp/TestAppMxBean.java index 11ea69905..3038b46b5 100644 --- a/jmx-scraper/src/testApp/java/io/opentelemetry/contrib/jmxscraper/TestAppMXBean.java +++ b/jmx-scraper/test-app/src/main/java/io/opentelemetry/contrib/jmxscraper/testapp/TestAppMxBean.java @@ -3,10 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.contrib.jmxscraper; +package io.opentelemetry.contrib.jmxscraper.testapp; +import javax.management.MXBean; + +@MXBean @SuppressWarnings("unused") -public interface TestAppMXBean { +public interface TestAppMxBean { int getIntValue(); diff --git a/jmx-scraper/test-webapp/build.gradle.kts b/jmx-scraper/test-webapp/build.gradle.kts new file mode 100644 index 000000000..c5f838508 --- /dev/null +++ b/jmx-scraper/test-webapp/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + war +} + +description = "JMX metrics scraper - test web application" + +dependencies { + providedCompile("jakarta.servlet:jakarta.servlet-api:5.0.0") +} + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(11) + } +} diff --git a/jmx-scraper/test-webapp/src/main/java/io/opentelemetry/contrib/jmxscraper/testwebapp/SimpleServlet.java b/jmx-scraper/test-webapp/src/main/java/io/opentelemetry/contrib/jmxscraper/testwebapp/SimpleServlet.java new file mode 100644 index 000000000..01feb7332 --- /dev/null +++ b/jmx-scraper/test-webapp/src/main/java/io/opentelemetry/contrib/jmxscraper/testwebapp/SimpleServlet.java @@ -0,0 +1,24 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.contrib.jmxscraper.testwebapp; + +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +public class SimpleServlet extends HttpServlet { + + private static final long serialVersionUID = 3726145372238690099L; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + try (PrintWriter out = resp.getWriter()) { + out.write("hello!"); + } + } +} diff --git a/jmx-scraper/test-webapp/src/main/webapp/WEB-INF/web.xml b/jmx-scraper/test-webapp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..5ede05330 --- /dev/null +++ b/jmx-scraper/test-webapp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,14 @@ + + + servlet_name + io.opentelemetry.contrib.jmxscraper.testwebapp.SimpleServlet + + + servlet_name + /* + + diff --git a/settings.gradle.kts b/settings.gradle.kts index c2a3b27e5..d6489ed97 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -72,6 +72,8 @@ include(":jfr-events") include(":jfr-connection") include(":jmx-metrics") include(":jmx-scraper") +include(":jmx-scraper:test-app") +include(":jmx-scraper:test-webapp") include(":maven-extension") include(":micrometer-meter-provider") include(":noop-api") From 04ea4bc363d5c2bb49558782a4983d96dc0d9b38 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 6 Nov 2024 16:11:32 +0100 Subject: [PATCH 11/25] add wildfly session metrics + tests --- .../WildflyIntegrationTest.java | 29 +++++++++++++++++++ jmx-scraper/src/main/resources/wildfly.yaml | 22 ++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java index 098315563..394f53789 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java @@ -100,6 +100,35 @@ protected JmxScraperContainer customizeScraperContainer( @Override protected void verifyMetrics() { waitAndAssertMetrics( + metric -> + assertSumWithAttributes( + metric, + "wildfly.session.count", + "The number of sessions created.", + "{session}", + attrs -> attrs.containsOnly(entry("deployment", "testapp.war"))), + metric -> + assertSumWithAttributes( + metric, + "wildfly.session.active", + "The number of currently active sessions.", + "{session}", + /* isMonotonic= */ false, + attrs -> attrs.containsOnly(entry("deployment", "testapp.war"))), + metric -> + assertSumWithAttributes( + metric, + "wildfly.session.expired", + "The number of sessions that have expired.", + "{session}", + attrs -> attrs.containsOnly(entry("deployment", "testapp.war"))), + metric -> + assertSumWithAttributes( + metric, + "wildfly.session.rejected", + "The number of sessions that have been rejected.", + "{session}", + attrs -> attrs.containsOnly(entry("deployment", "testapp.war"))), metric -> assertSumWithAttributes( metric, diff --git a/jmx-scraper/src/main/resources/wildfly.yaml b/jmx-scraper/src/main/resources/wildfly.yaml index 0e9ca80eb..6bc2d191e 100644 --- a/jmx-scraper/src/main/resources/wildfly.yaml +++ b/jmx-scraper/src/main/resources/wildfly.yaml @@ -1,6 +1,28 @@ --- rules: + - bean: jboss.as:deployment=*,subsystem=undertow + metricAttribute: + deployment: param(deployment) + prefix: wildfly.session. + unit: "{session}" + mapping: + sessionsCreated: + metric: count + type: counter + desc: The number of sessions created. + activeSessions: + metric: active + type: updowncounter + desc: The number of currently active sessions. + expiredSessions: + metric: expired + type: counter + desc: The number of sessions that have expired. + rejectedSessions: + metric: rejected + type: counter + desc: The number of sessions that have been rejected. - bean: jboss.as:subsystem=undertow,server=*,http-listener=* metricAttribute: From 3a53a2fd270dc3cd0e5b71ce1fa7a99808797d16 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:32:05 +0100 Subject: [PATCH 12/25] fix api change --- .../jmxscraper/target_systems/JettyIntegrationTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java index d6d8502b2..f2be4afc6 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java @@ -45,7 +45,8 @@ protected GenericContainer createTargetContainer(int jmxPort) { } @Override - protected JmxScraperContainer customizeScraperContainer(JmxScraperContainer scraper) { + protected JmxScraperContainer customizeScraperContainer( + JmxScraperContainer scraper, GenericContainer target) { return scraper.withTargetSystem("jetty"); } From 7fca8cac52b2b694c54d52a9ee2e92b141d2075f Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:43:30 +0100 Subject: [PATCH 13/25] fix test app for java8 compat --- jmx-scraper/test-app/build.gradle.kts | 6 ++++++ jmx-scraper/test-webapp/build.gradle.kts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/jmx-scraper/test-app/build.gradle.kts b/jmx-scraper/test-app/build.gradle.kts index 543318410..721f6fed7 100644 --- a/jmx-scraper/test-app/build.gradle.kts +++ b/jmx-scraper/test-app/build.gradle.kts @@ -4,6 +4,12 @@ plugins { description = "JMX metrics scraper - test application" +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} + tasks { jar { manifest { diff --git a/jmx-scraper/test-webapp/build.gradle.kts b/jmx-scraper/test-webapp/build.gradle.kts index c5f838508..ac863095b 100644 --- a/jmx-scraper/test-webapp/build.gradle.kts +++ b/jmx-scraper/test-webapp/build.gradle.kts @@ -10,6 +10,6 @@ dependencies { java { toolchain { - languageVersion = JavaLanguageVersion.of(11) + languageVersion = JavaLanguageVersion.of(8) } } From 171b1419228dc8bdb4ee6411693e3506b5798be5 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:50:25 +0100 Subject: [PATCH 14/25] attempt to make activemq startup detect better --- .../jmxscraper/target_systems/ActiveMqIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java index caa5c35de..319eae6a0 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java @@ -25,7 +25,7 @@ protected GenericContainer createTargetContainer(int jmxPort) { builder -> builder.from("apache/activemq-classic:5.18.6").build())) .withEnv("JAVA_TOOL_OPTIONS", genericJmxJvmArguments(jmxPort)) .withStartupTimeout(Duration.ofMinutes(2)) - .waitingFor(Wait.forListeningPort()); + .waitingFor(Wait.forLogMessage(".*Apache ActiveMQ.*started.*", 1)); } @Override From 5abd3c858caf8b61a6d328f0fcb0e65bc41eaf67 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Thu, 7 Nov 2024 13:32:15 +0100 Subject: [PATCH 15/25] bootstrap documentation --- jmx-scraper/README.md | 35 +++++++++++++++++++++++++++++++ jmx-scraper/test-app/README.md | 2 ++ jmx-scraper/test-webapp/README.md | 2 ++ 3 files changed, 39 insertions(+) create mode 100644 jmx-scraper/test-app/README.md create mode 100644 jmx-scraper/test-webapp/README.md diff --git a/jmx-scraper/README.md b/jmx-scraper/README.md index 38d3a3d44..9f279ae1c 100644 --- a/jmx-scraper/README.md +++ b/jmx-scraper/README.md @@ -7,6 +7,41 @@ The JMX MBeans and their metric mappings are defined in YAML and reuse implement This is currently a work-in-progress component not ready to be used in production. The end goal is to provide an alternative to the [JMX Gatherer](../jmx-metrics/README.md) utility. +## Usage + +The general command to invoke JMX scraper is `java -jar scraper.jar `, where `scraper.jar` +is the `build/libs/opentelemetry-jmx-scraper-.jar` packaged binary when building this module. + +Minimal configuration required +- `otel.jmx.service.url` for example `service:jmx:rmi:///jndi/rmi://server:9999/jmxrmi` for `server` + host on port `9999` with RMI JMX connector. +- `otel.jmx.target.system` or `otel.jmx.custom.scraping.config` + +Configuration can be provided through: +- command line arguments: `java -jar scraper.jar --config ` +- system properties `java -jar scraper.jar` +- java properties file: `java -jar config.properties` + +TODO: update this once autoconfiguration is supported + +### Configuration reference + +TODO + +### Extra libraries in classpath + +By default, only the RMI JMX connector is provided by the JVM, so it might be required to add extra +libraries in the classpath when connecting to remote JVMs that are not directly accessible with RMI. + +One known example of this is the Wildfly/Jboss HTTP management interface for which the `jboss-client.jar` +needs to be used to support `otel.jmx.service.url` = `service:jmx:remote+http://server:9999`. + +When doing so, the `java -jar` command can´t be used, we have to provide the classpath with +`-cp`/`--class-path`/`-classpath` option and provide the main class file name: +``` +java -cp scraper.jar:jboss-client.jar io.opentelemetry.contrib.jmxscraper.JmxScraper +``` + ## Component owners - [Jason Plumb](https://github.com/breedx-splk), Splunk diff --git a/jmx-scraper/test-app/README.md b/jmx-scraper/test-app/README.md new file mode 100644 index 000000000..0bc33f842 --- /dev/null +++ b/jmx-scraper/test-app/README.md @@ -0,0 +1,2 @@ +This is a test CLI application that is only used for integration tests. +The goal of this application is to publish custom MBeans in JMX and then allow end-to-end testing. diff --git a/jmx-scraper/test-webapp/README.md b/jmx-scraper/test-webapp/README.md new file mode 100644 index 000000000..3ec669184 --- /dev/null +++ b/jmx-scraper/test-webapp/README.md @@ -0,0 +1,2 @@ +This is a test web application that is only used for integration tests when metrics are published +only when an application is deployed to the container, for example with Wildfly session metrics. From 83ad212ac6222a736d73f57ac9f45563f3c7be44 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Thu, 7 Nov 2024 13:47:40 +0100 Subject: [PATCH 16/25] lint markdown --- jmx-scraper/README.md | 5 ++++- jmx-scraper/test-app/README.md | 2 ++ jmx-scraper/test-webapp/README.md | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/jmx-scraper/README.md b/jmx-scraper/README.md index 9f279ae1c..7aad6c1c2 100644 --- a/jmx-scraper/README.md +++ b/jmx-scraper/README.md @@ -13,12 +13,14 @@ The general command to invoke JMX scraper is `java -jar scraper.jar `, w is the `build/libs/opentelemetry-jmx-scraper-.jar` packaged binary when building this module. Minimal configuration required + - `otel.jmx.service.url` for example `service:jmx:rmi:///jndi/rmi://server:9999/jmxrmi` for `server` host on port `9999` with RMI JMX connector. - `otel.jmx.target.system` or `otel.jmx.custom.scraping.config` Configuration can be provided through: -- command line arguments: `java -jar scraper.jar --config ` + +- command line arguments: `java -jar scraper.jar --config otel.jmx.target.system=...` - system properties `java -jar scraper.jar` - java properties file: `java -jar config.properties` @@ -38,6 +40,7 @@ needs to be used to support `otel.jmx.service.url` = `service:jmx:remote+http:// When doing so, the `java -jar` command can´t be used, we have to provide the classpath with `-cp`/`--class-path`/`-classpath` option and provide the main class file name: + ``` java -cp scraper.jar:jboss-client.jar io.opentelemetry.contrib.jmxscraper.JmxScraper ``` diff --git a/jmx-scraper/test-app/README.md b/jmx-scraper/test-app/README.md index 0bc33f842..2aa7b5c94 100644 --- a/jmx-scraper/test-app/README.md +++ b/jmx-scraper/test-app/README.md @@ -1,2 +1,4 @@ +# test-app + This is a test CLI application that is only used for integration tests. The goal of this application is to publish custom MBeans in JMX and then allow end-to-end testing. diff --git a/jmx-scraper/test-webapp/README.md b/jmx-scraper/test-webapp/README.md index 3ec669184..f7c3af0e0 100644 --- a/jmx-scraper/test-webapp/README.md +++ b/jmx-scraper/test-webapp/README.md @@ -1,2 +1,4 @@ +# test-webapp + This is a test web application that is only used for integration tests when metrics are published only when an application is deployed to the container, for example with Wildfly session metrics. From 3ab2f28de2385af89c56705b4a38f58de5dca2ab Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:55:03 +0100 Subject: [PATCH 17/25] detect container startup with open ports --- .../jmxscraper/target_systems/ActiveMqIntegrationTest.java | 3 ++- .../target_systems/CassandraIntegrationTest.java | 3 ++- .../jmxscraper/target_systems/JettyIntegrationTest.java | 3 ++- .../jmxscraper/target_systems/JvmIntegrationTest.java | 7 ++++++- .../jmxscraper/target_systems/TomcatIntegrationTest.java | 3 ++- .../jmxscraper/target_systems/WildflyIntegrationTest.java | 3 ++- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java index 319eae6a0..af5698691 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java @@ -25,7 +25,8 @@ protected GenericContainer createTargetContainer(int jmxPort) { builder -> builder.from("apache/activemq-classic:5.18.6").build())) .withEnv("JAVA_TOOL_OPTIONS", genericJmxJvmArguments(jmxPort)) .withStartupTimeout(Duration.ofMinutes(2)) - .waitingFor(Wait.forLogMessage(".*Apache ActiveMQ.*started.*", 1)); + .withExposedPorts(61616, jmxPort) + .waitingFor(Wait.forListeningPorts(61616, jmxPort)); } @Override diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java index 3274c06f2..746a3f457 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java @@ -30,7 +30,8 @@ protected GenericContainer createTargetContainer(int jmxPort) { // making cassandra startup faster for single node, from ~1min to ~15s + " -Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=0") .withStartupTimeout(Duration.ofMinutes(2)) - .waitingFor(Wait.forLogMessage(".*Startup complete.*", 1)); + .withExposedPorts(9042, jmxPort) + .waitingFor(Wait.forListeningPorts(9042, jmxPort)); } @Override diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java index f2be4afc6..9de0ced7b 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java @@ -39,7 +39,8 @@ protected GenericContainer createTargetContainer(int jmxPort) { container .withEnv("JAVA_OPTIONS", genericJmxJvmArguments(jmxPort)) .withStartupTimeout(Duration.ofMinutes(2)) - .waitingFor(Wait.forLogMessage(".*Started Server.*", 1)); + .withExposedPorts(8080, jmxPort) + .waitingFor(Wait.forListeningPorts(8080, jmxPort)); return container; } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JvmIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JvmIntegrationTest.java index 7b85ad975..2177935af 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JvmIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JvmIntegrationTest.java @@ -14,13 +14,18 @@ import java.util.Arrays; import java.util.List; import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; public class JvmIntegrationTest extends TargetSystemIntegrationTest { @Override protected GenericContainer createTargetContainer(int jmxPort) { // reusing test application for JVM metrics and custom yaml - return new TestAppContainer().withJmxPort(jmxPort); + //noinspection resource + return new TestAppContainer() + .withJmxPort(jmxPort) + .withExposedPorts(jmxPort) + .waitingFor(Wait.forListeningPorts(jmxPort)); } @Override diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java index aebecfef9..ea35c2a16 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java @@ -32,7 +32,8 @@ protected GenericContainer createTargetContainer(int jmxPort) { .build())) .withEnv("CATALINA_OPTS", genericJmxJvmArguments(jmxPort)) .withStartupTimeout(Duration.ofMinutes(2)) - .waitingFor(Wait.forListeningPort()); + .withExposedPorts(8080, jmxPort) + .waitingFor(Wait.forListeningPorts(8080, jmxPort)); } @Override diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java index 394f53789..7e6e4b9f7 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java @@ -59,7 +59,8 @@ protected GenericContainer createTargetContainer(int jmxPort) { MountableFile.forHostPath(appWarPath), "/opt/jboss/wildfly/standalone/deployments/testapp.war") .withStartupTimeout(Duration.ofMinutes(2)) - .waitingFor(Wait.forLogMessage(".*Http management interface listening on.*", 1)); + .withExposedPorts(8080, 9990) + .waitingFor(Wait.forListeningPorts(8080, 9990)); } @Override From 50063dbe27a6b68ddd8fa48a8840e27f347b20f8 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:32:59 +0100 Subject: [PATCH 18/25] use constants for ports --- .../target_systems/ActiveMqIntegrationTest.java | 6 ++++-- .../target_systems/CassandraIntegrationTest.java | 6 ++++-- .../target_systems/JettyIntegrationTest.java | 6 ++++-- .../target_systems/TomcatIntegrationTest.java | 6 ++++-- .../target_systems/WildflyIntegrationTest.java | 11 +++++++---- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java index af5698691..4ec72d28c 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java @@ -17,6 +17,8 @@ public class ActiveMqIntegrationTest extends TargetSystemIntegrationTest { + private static final int ACTIVEMQ_PORT = 61616; + @Override protected GenericContainer createTargetContainer(int jmxPort) { return new GenericContainer<>( @@ -25,8 +27,8 @@ protected GenericContainer createTargetContainer(int jmxPort) { builder -> builder.from("apache/activemq-classic:5.18.6").build())) .withEnv("JAVA_TOOL_OPTIONS", genericJmxJvmArguments(jmxPort)) .withStartupTimeout(Duration.ofMinutes(2)) - .withExposedPorts(61616, jmxPort) - .waitingFor(Wait.forListeningPorts(61616, jmxPort)); + .withExposedPorts(ACTIVEMQ_PORT, jmxPort) + .waitingFor(Wait.forListeningPorts(ACTIVEMQ_PORT, jmxPort)); } @Override diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java index 746a3f457..060598953 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java @@ -21,6 +21,8 @@ public class CassandraIntegrationTest extends TargetSystemIntegrationTest { + private static final int CASSANDRA_PORT = 9042; + @Override protected GenericContainer createTargetContainer(int jmxPort) { return new GenericContainer<>("cassandra:5.0.2") @@ -30,8 +32,8 @@ protected GenericContainer createTargetContainer(int jmxPort) { // making cassandra startup faster for single node, from ~1min to ~15s + " -Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=0") .withStartupTimeout(Duration.ofMinutes(2)) - .withExposedPorts(9042, jmxPort) - .waitingFor(Wait.forListeningPorts(9042, jmxPort)); + .withExposedPorts(CASSANDRA_PORT, jmxPort) + .waitingFor(Wait.forListeningPorts(CASSANDRA_PORT, jmxPort)); } @Override diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java index 9de0ced7b..ffe1662b1 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java @@ -18,6 +18,8 @@ public class JettyIntegrationTest extends TargetSystemIntegrationTest { + private static final int JETTY_PORT = 8080; + @Override protected GenericContainer createTargetContainer(int jmxPort) { GenericContainer container = @@ -39,8 +41,8 @@ protected GenericContainer createTargetContainer(int jmxPort) { container .withEnv("JAVA_OPTIONS", genericJmxJvmArguments(jmxPort)) .withStartupTimeout(Duration.ofMinutes(2)) - .withExposedPorts(8080, jmxPort) - .waitingFor(Wait.forListeningPorts(8080, jmxPort)); + .withExposedPorts(JETTY_PORT, jmxPort) + .waitingFor(Wait.forListeningPorts(JETTY_PORT, jmxPort)); return container; } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java index ea35c2a16..f71e11956 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java @@ -17,6 +17,8 @@ public class TomcatIntegrationTest extends TargetSystemIntegrationTest { + private static final int TOMCAT_PORT = 8080; + @Override protected GenericContainer createTargetContainer(int jmxPort) { return new GenericContainer<>( @@ -32,8 +34,8 @@ protected GenericContainer createTargetContainer(int jmxPort) { .build())) .withEnv("CATALINA_OPTS", genericJmxJvmArguments(jmxPort)) .withStartupTimeout(Duration.ofMinutes(2)) - .withExposedPorts(8080, jmxPort) - .waitingFor(Wait.forListeningPorts(8080, jmxPort)); + .withExposedPorts(TOMCAT_PORT, jmxPort) + .waitingFor(Wait.forListeningPorts(TOMCAT_PORT, jmxPort)); } @Override diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java index 7e6e4b9f7..d224b038a 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java @@ -24,6 +24,9 @@ public class WildflyIntegrationTest extends TargetSystemIntegrationTest { + private static final int WILDFLY_SERVICE_PORT = 8080; + private static final int WILDFLY_MANAGEMENT_PORT = 9990; + @SuppressWarnings("NonFinalStaticField") private static Path tempJbossClient = null; @@ -53,14 +56,14 @@ protected GenericContainer createTargetContainer(int jmxPort) { // standalone with management (HTTP) interface enabled .cmd( "/opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0") - .expose(8080, 9990) + .expose(WILDFLY_SERVICE_PORT, WILDFLY_MANAGEMENT_PORT) .build())) .withCopyFileToContainer( MountableFile.forHostPath(appWarPath), "/opt/jboss/wildfly/standalone/deployments/testapp.war") .withStartupTimeout(Duration.ofMinutes(2)) - .withExposedPorts(8080, 9990) - .waitingFor(Wait.forListeningPorts(8080, 9990)); + .withExposedPorts(WILDFLY_SERVICE_PORT, WILDFLY_MANAGEMENT_PORT) + .waitingFor(Wait.forListeningPorts(WILDFLY_SERVICE_PORT, WILDFLY_MANAGEMENT_PORT)); } @Override @@ -90,7 +93,7 @@ protected JmxScraperContainer customizeScraperContainer( .withCopyFileToContainer(MountableFile.forHostPath(tempJbossClient), "/jboss-client.jar") .withExtraJar("/jboss-client.jar") // Using jboss remote HTTP protocol provided in jboss-client.jar - .withServiceUrl("service:jmx:remote+http://targetsystem:9990") + .withServiceUrl("service:jmx:remote+http://targetsystem:" + WILDFLY_MANAGEMENT_PORT) // Admin user created when creating container // When scraper is running on same host as jboss/wildfly a local file challenge can be used // for authentication, but here we have to use valid credentials for remote access From 4c25755c2b19b8a6a5f1915900b455d65aac9c72 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:43:50 +0100 Subject: [PATCH 19/25] avoid manual temp file management --- .../ActiveMqIntegrationTest.java | 3 +- .../CassandraIntegrationTest.java | 3 +- .../target_systems/JettyIntegrationTest.java | 3 +- .../target_systems/JvmIntegrationTest.java | 3 +- .../TargetSystemIntegrationTest.java | 8 +-- .../target_systems/TomcatIntegrationTest.java | 3 +- .../WildflyIntegrationTest.java | 54 ++++++++----------- 7 files changed, 36 insertions(+), 41 deletions(-) diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java index 4ec72d28c..5cd1ff608 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/ActiveMqIntegrationTest.java @@ -10,6 +10,7 @@ import static org.assertj.core.api.Assertions.entry; import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer; +import java.nio.file.Path; import java.time.Duration; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; @@ -33,7 +34,7 @@ protected GenericContainer createTargetContainer(int jmxPort) { @Override protected JmxScraperContainer customizeScraperContainer( - JmxScraperContainer scraper, GenericContainer target) { + JmxScraperContainer scraper, GenericContainer target, Path tempDir) { return scraper.withTargetSystem("activemq"); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java index 060598953..b909e62f7 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/CassandraIntegrationTest.java @@ -11,6 +11,7 @@ import static org.assertj.core.api.Assertions.entry; import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer; +import java.nio.file.Path; import java.time.Duration; import java.util.Arrays; import java.util.List; @@ -38,7 +39,7 @@ protected GenericContainer createTargetContainer(int jmxPort) { @Override protected JmxScraperContainer customizeScraperContainer( - JmxScraperContainer scraper, GenericContainer target) { + JmxScraperContainer scraper, GenericContainer target, Path tempDir) { return scraper.withTargetSystem("cassandra"); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java index ffe1662b1..fb1f489b1 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JettyIntegrationTest.java @@ -11,6 +11,7 @@ import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributesMultiplePoints; import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer; +import java.nio.file.Path; import java.time.Duration; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; @@ -49,7 +50,7 @@ protected GenericContainer createTargetContainer(int jmxPort) { @Override protected JmxScraperContainer customizeScraperContainer( - JmxScraperContainer scraper, GenericContainer target) { + JmxScraperContainer scraper, GenericContainer target, Path tempDir) { return scraper.withTargetSystem("jetty"); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JvmIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JvmIntegrationTest.java index 2177935af..d22f27496 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JvmIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JvmIntegrationTest.java @@ -11,6 +11,7 @@ import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer; import io.opentelemetry.contrib.jmxscraper.TestAppContainer; +import java.nio.file.Path; import java.util.Arrays; import java.util.List; import org.testcontainers.containers.GenericContainer; @@ -30,7 +31,7 @@ protected GenericContainer createTargetContainer(int jmxPort) { @Override protected JmxScraperContainer customizeScraperContainer( - JmxScraperContainer scraper, GenericContainer target) { + JmxScraperContainer scraper, GenericContainer target, Path tempDir) { return scraper.withTargetSystem("jvm"); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java index 22da7bd41..064e4f021 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java @@ -18,6 +18,7 @@ import io.opentelemetry.proto.collector.metrics.v1.MetricsServiceGrpc; import io.opentelemetry.proto.metrics.v1.Metric; import io.opentelemetry.proto.metrics.v1.ResourceMetrics; +import java.nio.file.Path; import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; @@ -32,6 +33,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testcontainers.Testcontainers; @@ -102,7 +104,7 @@ protected String scraperBaseImage() { } @Test - void endToEndTest() { + void endToEndTest(@TempDir Path tmpDir) { target = createTargetContainer(JMX_PORT) @@ -117,7 +119,7 @@ void endToEndTest() { .withNetwork(network) .withRmiServiceUrl(TARGET_SYSTEM_NETWORK_ALIAS, JMX_PORT); - scraper = customizeScraperContainer(scraper, target); + scraper = customizeScraperContainer(scraper, target, tmpDir); scraper.start(); verifyMetrics(); @@ -161,7 +163,7 @@ protected final void waitAndAssertMetrics(Consumer... assertions) { protected abstract void verifyMetrics(); protected JmxScraperContainer customizeScraperContainer( - JmxScraperContainer scraper, GenericContainer target) { + JmxScraperContainer scraper, GenericContainer target, Path tempDir) { return scraper; } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java index f71e11956..66fb3ec86 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java @@ -10,6 +10,7 @@ import static org.assertj.core.api.Assertions.entry; import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer; +import java.nio.file.Path; import java.time.Duration; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; @@ -40,7 +41,7 @@ protected GenericContainer createTargetContainer(int jmxPort) { @Override protected JmxScraperContainer customizeScraperContainer( - JmxScraperContainer scraper, GenericContainer target) { + JmxScraperContainer scraper, GenericContainer target, Path tempDir) { return scraper.withTargetSystem("tomcat"); } diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java index d224b038a..7c1e828a4 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java @@ -16,7 +16,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.time.Duration; -import org.junit.jupiter.api.AfterAll; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.images.builder.ImageFromDockerfile; @@ -27,16 +26,6 @@ public class WildflyIntegrationTest extends TargetSystemIntegrationTest { private static final int WILDFLY_SERVICE_PORT = 8080; private static final int WILDFLY_MANAGEMENT_PORT = 9990; - @SuppressWarnings("NonFinalStaticField") - private static Path tempJbossClient = null; - - @AfterAll - public static void cleanup() throws IOException { - if (tempJbossClient != null) { - Files.delete(tempJbossClient); - } - } - @Override protected GenericContainer createTargetContainer(int jmxPort) { // JMX port is ignored here as we are using HTTP management interface @@ -46,18 +35,18 @@ protected GenericContainer createTargetContainer(int jmxPort) { assertThat(appWarPath).isNotEmptyFile().isReadable(); return new GenericContainer<>( - new ImageFromDockerfile() - .withDockerfileFromBuilder( - builder -> - builder - .from("quay.io/wildfly/wildfly:32.0.1.Final-jdk11") - // user/pwd needed for remote JMX access - .run("/opt/jboss/wildfly/bin/add-user.sh user password --silent") - // standalone with management (HTTP) interface enabled - .cmd( - "/opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0") - .expose(WILDFLY_SERVICE_PORT, WILDFLY_MANAGEMENT_PORT) - .build())) + new ImageFromDockerfile() + .withDockerfileFromBuilder( + builder -> + builder + .from("quay.io/wildfly/wildfly:32.0.1.Final-jdk11") + // user/pwd needed for remote JMX access + .run("/opt/jboss/wildfly/bin/add-user.sh user password --silent") + // standalone with management (HTTP) interface enabled + .cmd( + "/opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0") + .expose(WILDFLY_SERVICE_PORT, WILDFLY_MANAGEMENT_PORT) + .build())) .withCopyFileToContainer( MountableFile.forHostPath(appWarPath), "/opt/jboss/wildfly/standalone/deployments/testapp.war") @@ -74,17 +63,16 @@ protected String scraperBaseImage() { @Override protected JmxScraperContainer customizeScraperContainer( - JmxScraperContainer scraper, GenericContainer target) { + JmxScraperContainer scraper, GenericContainer target, Path tempDir) { - if (tempJbossClient == null) { - // copy jboss-client.jar from jboss/wildfly container - try { - tempJbossClient = Files.createTempFile("jboss_", "_test").toAbsolutePath(); - target.copyFileFromContainer( - "/opt/jboss/wildfly/bin/client/jboss-client.jar", tempJbossClient.toString()); - } catch (IOException e) { - throw new IllegalStateException(e); - } + Path tempJbossClient; + // copy jboss-client.jar from jboss/wildfly container + try { + tempJbossClient = Files.createTempFile(tempDir, "jboss_", "_test").toAbsolutePath(); + target.copyFileFromContainer( + "/opt/jboss/wildfly/bin/client/jboss-client.jar", tempJbossClient.toString()); + } catch (IOException e) { + throw new IllegalStateException(e); } return scraper From 250e3ed287b1e45c6bcec7d04d28090f1ffefa2a Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:46:22 +0100 Subject: [PATCH 20/25] use 'By' in place of 'by' for units --- jmx-metrics/src/main/resources/target-systems/wildfly.groovy | 2 +- jmx-scraper/src/main/resources/wildfly.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jmx-metrics/src/main/resources/target-systems/wildfly.groovy b/jmx-metrics/src/main/resources/target-systems/wildfly.groovy index ae893f767..4e5519e1f 100644 --- a/jmx-metrics/src/main/resources/target-systems/wildfly.groovy +++ b/jmx-metrics/src/main/resources/target-systems/wildfly.groovy @@ -42,7 +42,7 @@ otel.instrument(beanWildflyHttpListener, "wildfly.request.time", "The total amou otel.instrument(beanWildflyHttpListener, "wildfly.request.server_error", "The number of requests that have resulted in a 5xx response.", "{request}", ["server": { mbean -> mbean.name().getKeyProperty("server")}, "listener": { mbean -> mbean.name().getKeyProperty("http-listener")}], "errorCount", otel.&longCounterCallback) -otel.instrument(beanWildflyHttpListener, "wildfly.network.io", "The number of bytes transmitted.", "by", +otel.instrument(beanWildflyHttpListener, "wildfly.network.io", "The number of bytes transmitted.", "By", ["server": { mbean -> mbean.name().getKeyProperty("server")}, "listener": { mbean -> mbean.name().getKeyProperty("http-listener")}], ["bytesSent":["state":{"out"}], "bytesReceived":["state":{"in"}]], otel.&longCounterCallback) diff --git a/jmx-scraper/src/main/resources/wildfly.yaml b/jmx-scraper/src/main/resources/wildfly.yaml index 6bc2d191e..38bb3ae2d 100644 --- a/jmx-scraper/src/main/resources/wildfly.yaml +++ b/jmx-scraper/src/main/resources/wildfly.yaml @@ -45,13 +45,13 @@ rules: desc: The number of requests that have resulted in a 5xx response. bytesSent: metric: network.io - unit: "by" + unit: By desc: "The number of bytes transmitted." metricAttribute: state: const(out) bytesReceived: metric: network.io - unit: "by" + unit: By desc: "The number of bytes transmitted." metricAttribute: state: const(in) From d2866226c758a7ee88269a283c71e42ca7436100 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:57:10 +0100 Subject: [PATCH 21/25] remove duplication in wildfly yaml --- jmx-scraper/src/main/resources/wildfly.yaml | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/jmx-scraper/src/main/resources/wildfly.yaml b/jmx-scraper/src/main/resources/wildfly.yaml index 38bb3ae2d..687699407 100644 --- a/jmx-scraper/src/main/resources/wildfly.yaml +++ b/jmx-scraper/src/main/resources/wildfly.yaml @@ -44,15 +44,15 @@ rules: unit: "{request}" desc: The number of requests that have resulted in a 5xx response. bytesSent: - metric: network.io - unit: By - desc: "The number of bytes transmitted." + metric: &metric network.io + unit: &unit By + desc: &desc "The number of bytes transmitted." metricAttribute: state: const(out) bytesReceived: - metric: network.io - unit: By - desc: "The number of bytes transmitted." + metric: *metric + unit: *unit + desc: *desc metricAttribute: state: const(in) @@ -63,15 +63,15 @@ rules: prefix: wildfly.jdbc. mapping: ActiveCount: - metric: connection.open - unit: "{connection}" - desc: The number of open jdbc connections. + metric: &metric connection.open + unit: &unit "{connection}" + desc: &desc The number of open jdbc connections. metricAttribute: state: const(active) IdleCount: - metric: connection.open - unit: "{connection}" - desc: The number of open jdbc connections. + metric: *metric + unit: *unit + desc: *desc metricAttribute: state: const(idle) WaitCount: From 6645d4b1d845330f5159a0a4357a91c601d38140 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:57:24 +0100 Subject: [PATCH 22/25] fix test change for units --- .../jmxmetrics/target_systems/WildflyIntegrationTest.java | 3 +-- .../jmxscraper/target_systems/WildflyIntegrationTest.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/jmx-metrics/src/integrationTest/java/io/opentelemetry/contrib/jmxmetrics/target_systems/WildflyIntegrationTest.java b/jmx-metrics/src/integrationTest/java/io/opentelemetry/contrib/jmxmetrics/target_systems/WildflyIntegrationTest.java index e6d3a6d0d..686159e79 100644 --- a/jmx-metrics/src/integrationTest/java/io/opentelemetry/contrib/jmxmetrics/target_systems/WildflyIntegrationTest.java +++ b/jmx-metrics/src/integrationTest/java/io/opentelemetry/contrib/jmxmetrics/target_systems/WildflyIntegrationTest.java @@ -81,7 +81,7 @@ void endToEnd() { metric, "wildfly.network.io", "The number of bytes transmitted.", - "by", + "By", attrs -> attrs.containsOnly( entry("server", "default-server"), @@ -93,7 +93,6 @@ void endToEnd() { entry("listener", "default"), entry("state", "out"))), - // TODO from here: metric -> assertSumWithAttributes( metric, diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java index 7c1e828a4..d23e5291e 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java @@ -153,7 +153,7 @@ protected void verifyMetrics() { metric, "wildfly.network.io", "The number of bytes transmitted.", - "by", + "By", attrs -> attrs.containsOnly( entry("server", "default-server"), From 1a858bba8f8f5330fa7bb1d4fdc1f448dbffb580 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:28:05 +0100 Subject: [PATCH 23/25] enhance readme --- jmx-scraper/README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/jmx-scraper/README.md b/jmx-scraper/README.md index 7aad6c1c2..b57c508c1 100644 --- a/jmx-scraper/README.md +++ b/jmx-scraper/README.md @@ -20,9 +20,13 @@ Minimal configuration required Configuration can be provided through: -- command line arguments: `java -jar scraper.jar --config otel.jmx.target.system=...` -- system properties `java -jar scraper.jar` -- java properties file: `java -jar config.properties` +- command line arguments: + `java -jar scraper.jar --config otel.jmx.service.url=service:jmx:rmi:///jndi/rmi://tomcat:9010/jmxrmi otel.jmx.target.system=tomcat`. +- command line arguments JVM system properties: + `java -Dotel.jmx.service.url=service:jmx:rmi:///jndi/rmi://tomcat:9010/jmxrmi -Dotel.jmx.target.system=tomcat -jar scraper.jar`. +- java properties file: `java -jar scraper.jar -config config.properties`. +- stdin: `java -jar scraper.jar -config -` where `otel.jmx.target.system=tomcat` and + `otel.jmx.service.url=service:jmx:rmi:///jndi/rmi://tomcat:9010/jmxrmi` is written to stdin. TODO: update this once autoconfiguration is supported From 6e704883bf69a934b44b5d4db96c524728b014dc Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:25:18 +0100 Subject: [PATCH 24/25] reformat --- .../WildflyIntegrationTest.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java index d23e5291e..503622bf8 100644 --- a/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java +++ b/jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/WildflyIntegrationTest.java @@ -35,18 +35,18 @@ protected GenericContainer createTargetContainer(int jmxPort) { assertThat(appWarPath).isNotEmptyFile().isReadable(); return new GenericContainer<>( - new ImageFromDockerfile() - .withDockerfileFromBuilder( - builder -> - builder - .from("quay.io/wildfly/wildfly:32.0.1.Final-jdk11") - // user/pwd needed for remote JMX access - .run("/opt/jboss/wildfly/bin/add-user.sh user password --silent") - // standalone with management (HTTP) interface enabled - .cmd( - "/opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0") - .expose(WILDFLY_SERVICE_PORT, WILDFLY_MANAGEMENT_PORT) - .build())) + new ImageFromDockerfile() + .withDockerfileFromBuilder( + builder -> + builder + .from("quay.io/wildfly/wildfly:32.0.1.Final-jdk11") + // user/pwd needed for remote JMX access + .run("/opt/jboss/wildfly/bin/add-user.sh user password --silent") + // standalone with management (HTTP) interface enabled + .cmd( + "/opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0") + .expose(WILDFLY_SERVICE_PORT, WILDFLY_MANAGEMENT_PORT) + .build())) .withCopyFileToContainer( MountableFile.forHostPath(appWarPath), "/opt/jboss/wildfly/standalone/deployments/testapp.war") From e15e4c8fa28fe970227e9edc331795318de5973a Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:34:53 +0100 Subject: [PATCH 25/25] reformat again --- .../jmxmetrics/target_systems/WildflyIntegrationTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jmx-metrics/src/integrationTest/java/io/opentelemetry/contrib/jmxmetrics/target_systems/WildflyIntegrationTest.java b/jmx-metrics/src/integrationTest/java/io/opentelemetry/contrib/jmxmetrics/target_systems/WildflyIntegrationTest.java index 686159e79..c5e208f78 100644 --- a/jmx-metrics/src/integrationTest/java/io/opentelemetry/contrib/jmxmetrics/target_systems/WildflyIntegrationTest.java +++ b/jmx-metrics/src/integrationTest/java/io/opentelemetry/contrib/jmxmetrics/target_systems/WildflyIntegrationTest.java @@ -92,7 +92,6 @@ void endToEnd() { entry("server", "default-server"), entry("listener", "default"), entry("state", "out"))), - metric -> assertSumWithAttributes( metric,