Skip to content
Draft
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
4 changes: 4 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ SoundCloud Ltd. (https://soundcloud.com/).

This product includes software developed by the Caffeine Authors
(https://github.com/ben-manes/caffeine/).

This product includes software developed by The Legion of the Bouncy Castle Inc.
(https://www.bouncycastle.org/). Bouncy Castle is licensed under the MIT License
(https://www.bouncycastle.org/licence.html).
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
public class PBKDF2WithHmacExporterTestEnvironmentFilter implements Predicate<JmxExporterTestEnvironment> {

private final Set<String> filteredDockerImages =
private static final Set<String> filteredDockerImages =
Set.of("ibmjava:8", "ibmjava:8-jre", "ibmjava:8-sdk", "ibmjava:8-sfj");

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
public class PKCS12KeyStoreExporterTestEnvironmentFilter implements Predicate<JmxExporterTestEnvironment> {

private final Set<String> filteredDockerImages = Set.of(
private static final Set<String> filteredDockerImages = Set.of(
"eclipse-temurin:8-alpine",
"ghcr.io/graalvm/jdk:java8",
"ibmjava:8",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
* Copyright (C) The Prometheus jmx_exporter Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.prometheus.jmx.test.http.ssl;

import static io.prometheus.jmx.test.support.http.HttpResponse.assertHealthyResponse;
import static io.prometheus.jmx.test.support.metrics.MetricsAssertions.assertMetrics;
import static io.prometheus.jmx.test.support.metrics.MetricsAssertions.assertMetricsContentType;
import static io.prometheus.jmx.test.support.metrics.MetricsParser.parseMap;
import static org.paramixel.api.Context.withInstance;
import static org.paramixel.api.action.Instance.instance;
import static org.paramixel.api.action.Scope.scope;
import static org.paramixel.api.action.Sequential.sequential;
import static org.paramixel.api.action.Step.step;

import io.prometheus.jmx.test.support.environment.JmxExporterPath;
import io.prometheus.jmx.test.support.environment.JmxExporterTestEnvironment;
import io.prometheus.jmx.test.support.http.HttpClient;
import io.prometheus.jmx.test.support.http.HttpHeader;
import io.prometheus.jmx.test.support.http.HttpResponse;
import io.prometheus.jmx.test.support.metrics.Metric;
import io.prometheus.jmx.test.support.metrics.MetricsContentType;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.stream.Collectors;
import org.altcontainers.api.Network;
import org.paramixel.api.Paramixel;
import org.paramixel.api.Runner;
import org.paramixel.api.action.Action;
import org.paramixel.api.action.Each;

public class SSLWithPEMCertificateTest {

private final JmxExporterTestEnvironment environment;

private Network network;

public static void main(String[] args) throws Throwable {
Runner.defaultRunner().runAndExit(factory());
}

@Paramixel.Factory
public static Action factory() throws Throwable {
// Filter specific Java versions / containers that don't provide libraries for PEM support
var environments = JmxExporterTestEnvironment.createTestEnvironments(SSLWithPEMCertificateTest.class).stream()
.filter(environment -> !environment.getJavaDockerImage().contains("eclipse-temurin:8"))
.filter(environment -> !environment.getJavaDockerImage().contains("ibmjava:8"))
.collect(Collectors.toList());

return Each.parallel(
SSLWithPEMCertificateTest.class.getName(),
environments,
environment -> instance(environment.name(), () -> new SSLWithPEMCertificateTest(environment))
.body(scope("scenario")
.before(step(
"setUp()",
withInstance(
SSLWithPEMCertificateTest.class,
SSLWithPEMCertificateTest::setUp)))
.body(sequential("tests")
.child(step(
"testHealthy()",
withInstance(
SSLWithPEMCertificateTest.class,
SSLWithPEMCertificateTest::testHealthy)))
.child(step(
"testDefaultTextMetrics()",
withInstance(
SSLWithPEMCertificateTest.class,
SSLWithPEMCertificateTest::testDefaultTextMetrics)))
.child(step(
"testOpenMetricsTextMetrics()",
withInstance(
SSLWithPEMCertificateTest.class,
SSLWithPEMCertificateTest::testOpenMetricsTextMetrics)))
.child(step(
"testPrometheusTextMetrics()",
withInstance(
SSLWithPEMCertificateTest.class,
SSLWithPEMCertificateTest::testPrometheusTextMetrics)))
.child(step(
"testPrometheusProtobufMetrics()",
withInstance(
SSLWithPEMCertificateTest.class,
SSLWithPEMCertificateTest
::testPrometheusProtobufMetrics))))
.after(step(
"tearDown()",
withInstance(
SSLWithPEMCertificateTest.class,
SSLWithPEMCertificateTest::tearDown)))))
.build();
}

private SSLWithPEMCertificateTest(JmxExporterTestEnvironment environment) {
this.environment = environment;
}

public void setUp() throws Throwable {
environment.setBaseUrl("https://localhost");
network = Network.create();
environment.initialize(network);
}

public void tearDown() {
try {
environment.close();
} finally {
Network.close(network);
}
}

public void testHealthy() throws IOException {
String url = environment.getUrl(JmxExporterPath.HEALTHY);
HttpResponse httpResponse = HttpClient.sendRequest(url);
assertHealthyResponse(httpResponse);
}

public void testDefaultTextMetrics() throws IOException {
String url = environment.getUrl(JmxExporterPath.METRICS);
HttpResponse httpResponse = HttpClient.sendRequest(url);
assertMetricsResponse(httpResponse, MetricsContentType.DEFAULT);
}

public void testOpenMetricsTextMetrics() throws IOException {
String url = environment.getUrl(JmxExporterPath.METRICS);
HttpResponse httpResponse =
HttpClient.sendRequest(url, HttpHeader.ACCEPT, MetricsContentType.OPEN_METRICS_TEXT_METRICS.toString());
assertMetricsResponse(httpResponse, MetricsContentType.OPEN_METRICS_TEXT_METRICS);
}

public void testPrometheusTextMetrics() throws IOException {
String url = environment.getUrl(JmxExporterPath.METRICS);
HttpResponse httpResponse =
HttpClient.sendRequest(url, HttpHeader.ACCEPT, MetricsContentType.PROMETHEUS_TEXT_METRICS.toString());
assertMetricsResponse(httpResponse, MetricsContentType.PROMETHEUS_TEXT_METRICS);
}

public void testPrometheusProtobufMetrics() throws IOException {
String url = environment.getUrl(JmxExporterPath.METRICS);
HttpResponse httpResponse = HttpClient.sendRequest(
url, HttpHeader.ACCEPT, MetricsContentType.PROMETHEUS_PROTOBUF_METRICS.toString());
assertMetricsResponse(httpResponse, MetricsContentType.PROMETHEUS_PROTOBUF_METRICS);
}

private void assertMetricsResponse(HttpResponse httpResponse, MetricsContentType metricsContentType) {
assertMetricsContentType(httpResponse, metricsContentType);

Map<String, Collection<Metric>> metrics = parseMap(httpResponse);
String mode = environment.getJmxExporterMode().name();
String javaDockerImage = environment.getJavaDockerImage();

assertMetrics(SSLWithPEMCertificateTest.class, javaDockerImage, mode, metrics);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

java \
-Xmx512M \
-javaagent:/common/jmx_prometheus_javaagent.jar=8888:exporter.yaml \
-jar /common/jmx_example_application.jar
Loading
Loading