Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fixed packaging to add version and name to build info metric #768

Merged
merged 1 commit into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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<String> 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<String> metrics = scraper.scrape(10 * 1000);
metrics.stream()
.filter(line -> line.startsWith("jmx_exporter_build_info"))
.findAny()
.ifPresent(line -> {
Assert.assertTrue(!line.contains("\"unknown\""));
});
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,13 +11,16 @@

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.
*/
@RunWith(Parameterized.class)
public class HttpServerIT {

private final String httpServerModule;
private final Volume volume;
private final GenericContainer<?> javaContainer;
private final Scraper scraper;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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<String> 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<String> metrics = scraper.scrape(10 * 1000);
metrics.stream()
.filter(line -> line.startsWith("jmx_exporter_build_info"))
.findAny()
.ifPresent(line -> {
Assert.assertTrue(!line.contains("\"unknown\""));
});
}
}
2 changes: 2 additions & 0 deletions jmx_prometheus_httpserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>io.prometheus.jmx.WebServer</Main-Class>
<Implementation-Version>${project.version}</Implementation-Version>
<Implementation-Title>${project.artifactId}</Implementation-Title>
</manifestEntries>
</transformer>
</transformers>
Expand Down
2 changes: 2 additions & 0 deletions jmx_prometheus_httpserver_java6/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>io.prometheus.jmx.WebServer</Main-Class>
<Implementation-Version>${project.version}</Implementation-Version>
<Implementation-Title>${project.artifactId}</Implementation-Title>
</manifestEntries>
</transformer>
</transformers>
Expand Down