diff --git a/integration_tests/smoke_tests/src/test/java/io/prometheus/jmx/AgentJavaVersionsIT.java b/integration_tests/smoke_tests/src/test/java/io/prometheus/jmx/AgentJavaVersionsIT.java index 4f82fcfc..4e1f22d1 100644 --- a/integration_tests/smoke_tests/src/test/java/io/prometheus/jmx/AgentJavaVersionsIT.java +++ b/integration_tests/smoke_tests/src/test/java/io/prometheus/jmx/AgentJavaVersionsIT.java @@ -12,6 +12,8 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; /** * Runs the JmxExampleApplication on different Java Docker images with the jmx_exporter agent attached, @@ -23,6 +25,7 @@ @RunWith(Parameterized.class) public class AgentJavaVersionsIT { + private final String agentModule; private final GenericContainer javaContainer; private final Volume volume; private final Scraper scraper; @@ -59,6 +62,7 @@ public static String[][] images() { } public AgentJavaVersionsIT(String baseImage, String agentModule) throws IOException, URISyntaxException { + this.agentModule = agentModule; volume = Volume.create("agent-integration-test-"); volume.copyAgentJar(agentModule); volume.copyConfigYaml("config.yml"); @@ -108,4 +112,32 @@ public void testTabularMetric() throws Exception { .orElseThrow(() -> new AssertionError("Metric " + expectedMetric + " not found.")); } } + + @Test + public void testBuildInfoMetricName() { + AtomicReference expectedName = new AtomicReference("\"jmx_prometheus_javaagent\""); + if (agentModule.endsWith("_java6")) { + expectedName.set("\"jmx_prometheus_javaagent_java6\""); + } + + List metrics = scraper.scrape(10 * 1000); + metrics.stream() + .filter(line -> line.startsWith("jmx_exporter_build_info")) + .findAny() + .ifPresent(line -> { + Assert.assertTrue(line.contains((String) expectedName.get())); + }); + } + + @Test + public void testBuildVersionMetricNotUnknown() { + // No easy way to test the version, so make sure it's not "unknown" + List metrics = scraper.scrape(10 * 1000); + metrics.stream() + .filter(line -> line.startsWith("jmx_exporter_build_info")) + .findAny() + .ifPresent(line -> { + Assert.assertTrue(!line.contains("\"unknown\"")); + }); + } } diff --git a/integration_tests/smoke_tests/src/test/java/io/prometheus/jmx/HttpServerIT.java b/integration_tests/smoke_tests/src/test/java/io/prometheus/jmx/HttpServerIT.java index 7fcf1a85..7aa5ce79 100644 --- a/integration_tests/smoke_tests/src/test/java/io/prometheus/jmx/HttpServerIT.java +++ b/integration_tests/smoke_tests/src/test/java/io/prometheus/jmx/HttpServerIT.java @@ -1,6 +1,7 @@ package io.prometheus.jmx; import org.junit.After; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -10,6 +11,8 @@ import java.io.IOException; import java.net.URISyntaxException; +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; /** * Simple test of the jmx_prometheus_httpserver getting metrics from the JmxExampleApplication. @@ -17,6 +20,7 @@ @RunWith(Parameterized.class) public class HttpServerIT { + private final String httpServerModule; private final Volume volume; private final GenericContainer javaContainer; private final Scraper scraper; @@ -53,6 +57,7 @@ public static String[][] images() { } public HttpServerIT(String baseImage, String httpServerModule) throws IOException, URISyntaxException { + this.httpServerModule = httpServerModule; volume = Volume.create("http-server-integration-test-"); volume.copyHttpServer(httpServerModule); volume.copyConfigYaml("config-httpserver.yml"); @@ -92,4 +97,32 @@ public void testExampleMetrics() throws Exception { .orElseThrow(() -> new AssertionError("Metric " + metric + " not found.")); } } + + @Test + public void testBuildInfoMetricName() { + AtomicReference expectedName = new AtomicReference("\"jmx_prometheus_httpserver\""); + if (httpServerModule.endsWith("_java6")) { + expectedName.set("\"jmx_prometheus_httpserver_java6\""); + } + + List metrics = scraper.scrape(10 * 1000); + metrics.stream() + .filter(line -> line.startsWith("jmx_exporter_build_info")) + .findAny() + .ifPresent(line -> { + Assert.assertTrue(line.contains((String) expectedName.get())); + }); + } + + @Test + public void testBuildVersionMetricNotUnknown() { + // No easy way to test the version, so make sure it's not "unknown" + List metrics = scraper.scrape(10 * 1000); + metrics.stream() + .filter(line -> line.startsWith("jmx_exporter_build_info")) + .findAny() + .ifPresent(line -> { + Assert.assertTrue(!line.contains("\"unknown\"")); + }); + } } diff --git a/jmx_prometheus_httpserver/pom.xml b/jmx_prometheus_httpserver/pom.xml index 18ec3592..af9344f0 100644 --- a/jmx_prometheus_httpserver/pom.xml +++ b/jmx_prometheus_httpserver/pom.xml @@ -52,6 +52,8 @@ io.prometheus.jmx.WebServer + ${project.version} + ${project.artifactId} diff --git a/jmx_prometheus_httpserver_java6/pom.xml b/jmx_prometheus_httpserver_java6/pom.xml index 136fa669..3c0dfeab 100644 --- a/jmx_prometheus_httpserver_java6/pom.xml +++ b/jmx_prometheus_httpserver_java6/pom.xml @@ -63,6 +63,8 @@ io.prometheus.jmx.WebServer + ${project.version} + ${project.artifactId}