Skip to content

Commit e392ea1

Browse files
committed
feature: SSL PEM support
Signed-off-by: dhoard <doug.hoard@gmail.com>
1 parent 026219c commit e392ea1

223 files changed

Lines changed: 28206 additions & 100 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

NOTICE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ SoundCloud Ltd. (https://soundcloud.com/).
66

77
This product includes software developed by the Caffeine Authors
88
(https://github.com/ben-manes/caffeine/).
9+
10+
This product includes software developed by The Legion of the Bouncy Castle Inc.
11+
(https://www.bouncycastle.org/). Bouncy Castle is licensed under the MIT License
12+
(https://www.bouncycastle.org/licence.html).

integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/filter/PBKDF2WithHmacExporterTestEnvironmentFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public class PBKDF2WithHmacExporterTestEnvironmentFilter implements Predicate<JmxExporterTestEnvironment> {
2828

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

3232
/**

integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/filter/PKCS12KeyStoreExporterTestEnvironmentFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public class PKCS12KeyStoreExporterTestEnvironmentFilter implements Predicate<JmxExporterTestEnvironment> {
2828

29-
private final Set<String> filteredDockerImages = Set.of(
29+
private static final Set<String> filteredDockerImages = Set.of(
3030
"eclipse-temurin:8-alpine",
3131
"ghcr.io/graalvm/jdk:java8",
3232
"ibmjava:8",
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
* Copyright (C) The Prometheus jmx_exporter Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.prometheus.jmx.test.http.ssl;
18+
19+
import static io.prometheus.jmx.test.support.http.HttpResponse.assertHealthyResponse;
20+
import static io.prometheus.jmx.test.support.metrics.MetricsAssertions.assertMetrics;
21+
import static io.prometheus.jmx.test.support.metrics.MetricsAssertions.assertMetricsContentType;
22+
import static io.prometheus.jmx.test.support.metrics.MetricsParser.parseMap;
23+
import static org.paramixel.api.Context.withInstance;
24+
import static org.paramixel.api.action.Instance.instance;
25+
import static org.paramixel.api.action.Scope.scope;
26+
import static org.paramixel.api.action.Sequential.sequential;
27+
import static org.paramixel.api.action.Step.step;
28+
29+
import io.prometheus.jmx.test.support.environment.JmxExporterPath;
30+
import io.prometheus.jmx.test.support.environment.JmxExporterTestEnvironment;
31+
import io.prometheus.jmx.test.support.http.HttpClient;
32+
import io.prometheus.jmx.test.support.http.HttpHeader;
33+
import io.prometheus.jmx.test.support.http.HttpResponse;
34+
import io.prometheus.jmx.test.support.metrics.Metric;
35+
import io.prometheus.jmx.test.support.metrics.MetricsContentType;
36+
import java.io.IOException;
37+
import java.util.Collection;
38+
import java.util.Map;
39+
import java.util.stream.Collectors;
40+
import org.altcontainers.api.Network;
41+
import org.paramixel.api.Paramixel;
42+
import org.paramixel.api.Runner;
43+
import org.paramixel.api.action.Action;
44+
import org.paramixel.api.action.Each;
45+
46+
public class SSLWithPEMCertificateTest {
47+
48+
private final JmxExporterTestEnvironment environment;
49+
50+
private Network network;
51+
52+
public static void main(String[] args) throws Throwable {
53+
Runner.defaultRunner().runAndExit(factory());
54+
}
55+
56+
@Paramixel.Factory
57+
public static Action factory() throws Throwable {
58+
// Filter specific Java versions / containers that don't provide libraries for PEM support
59+
var environments = JmxExporterTestEnvironment.createTestEnvironments(SSLWithPEMCertificateTest.class).stream()
60+
.filter(environment -> !environment.getJavaDockerImage().contains("eclipse-temurin:8"))
61+
.filter(environment -> !environment.getJavaDockerImage().contains("ibmjava:8"))
62+
.collect(Collectors.toList());
63+
64+
return Each.parallel(
65+
SSLWithPEMCertificateTest.class.getName(),
66+
environments,
67+
environment -> instance(environment.name(), () -> new SSLWithPEMCertificateTest(environment))
68+
.body(scope("scenario")
69+
.before(step(
70+
"setUp()",
71+
withInstance(
72+
SSLWithPEMCertificateTest.class,
73+
SSLWithPEMCertificateTest::setUp)))
74+
.body(sequential("tests")
75+
.child(step(
76+
"testHealthy()",
77+
withInstance(
78+
SSLWithPEMCertificateTest.class,
79+
SSLWithPEMCertificateTest::testHealthy)))
80+
.child(step(
81+
"testDefaultTextMetrics()",
82+
withInstance(
83+
SSLWithPEMCertificateTest.class,
84+
SSLWithPEMCertificateTest::testDefaultTextMetrics)))
85+
.child(step(
86+
"testOpenMetricsTextMetrics()",
87+
withInstance(
88+
SSLWithPEMCertificateTest.class,
89+
SSLWithPEMCertificateTest::testOpenMetricsTextMetrics)))
90+
.child(step(
91+
"testPrometheusTextMetrics()",
92+
withInstance(
93+
SSLWithPEMCertificateTest.class,
94+
SSLWithPEMCertificateTest::testPrometheusTextMetrics)))
95+
.child(step(
96+
"testPrometheusProtobufMetrics()",
97+
withInstance(
98+
SSLWithPEMCertificateTest.class,
99+
SSLWithPEMCertificateTest
100+
::testPrometheusProtobufMetrics))))
101+
.after(step(
102+
"tearDown()",
103+
withInstance(
104+
SSLWithPEMCertificateTest.class,
105+
SSLWithPEMCertificateTest::tearDown)))))
106+
.build();
107+
}
108+
109+
private SSLWithPEMCertificateTest(JmxExporterTestEnvironment environment) {
110+
this.environment = environment;
111+
}
112+
113+
public void setUp() throws Throwable {
114+
environment.setBaseUrl("https://localhost");
115+
network = Network.create();
116+
environment.initialize(network);
117+
}
118+
119+
public void tearDown() {
120+
try {
121+
environment.close();
122+
} finally {
123+
Network.close(network);
124+
}
125+
}
126+
127+
public void testHealthy() throws IOException {
128+
String url = environment.getUrl(JmxExporterPath.HEALTHY);
129+
HttpResponse httpResponse = HttpClient.sendRequest(url);
130+
assertHealthyResponse(httpResponse);
131+
}
132+
133+
public void testDefaultTextMetrics() throws IOException {
134+
String url = environment.getUrl(JmxExporterPath.METRICS);
135+
HttpResponse httpResponse = HttpClient.sendRequest(url);
136+
assertMetricsResponse(httpResponse, MetricsContentType.DEFAULT);
137+
}
138+
139+
public void testOpenMetricsTextMetrics() throws IOException {
140+
String url = environment.getUrl(JmxExporterPath.METRICS);
141+
HttpResponse httpResponse =
142+
HttpClient.sendRequest(url, HttpHeader.ACCEPT, MetricsContentType.OPEN_METRICS_TEXT_METRICS.toString());
143+
assertMetricsResponse(httpResponse, MetricsContentType.OPEN_METRICS_TEXT_METRICS);
144+
}
145+
146+
public void testPrometheusTextMetrics() throws IOException {
147+
String url = environment.getUrl(JmxExporterPath.METRICS);
148+
HttpResponse httpResponse =
149+
HttpClient.sendRequest(url, HttpHeader.ACCEPT, MetricsContentType.PROMETHEUS_TEXT_METRICS.toString());
150+
assertMetricsResponse(httpResponse, MetricsContentType.PROMETHEUS_TEXT_METRICS);
151+
}
152+
153+
public void testPrometheusProtobufMetrics() throws IOException {
154+
String url = environment.getUrl(JmxExporterPath.METRICS);
155+
HttpResponse httpResponse = HttpClient.sendRequest(
156+
url, HttpHeader.ACCEPT, MetricsContentType.PROMETHEUS_PROTOBUF_METRICS.toString());
157+
assertMetricsResponse(httpResponse, MetricsContentType.PROMETHEUS_PROTOBUF_METRICS);
158+
}
159+
160+
private void assertMetricsResponse(HttpResponse httpResponse, MetricsContentType metricsContentType) {
161+
assertMetricsContentType(httpResponse, metricsContentType);
162+
163+
Map<String, Collection<Metric>> metrics = parseMap(httpResponse);
164+
String mode = environment.getJmxExporterMode().name();
165+
String javaDockerImage = environment.getJavaDockerImage();
166+
167+
assertMetrics(SSLWithPEMCertificateTest.class, javaDockerImage, mode, metrics);
168+
}
169+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
java \
4+
-Xmx512M \
5+
-javaagent:/common/jmx_prometheus_javaagent.jar=8888:exporter.yaml \
6+
-jar /common/jmx_example_application.jar

0 commit comments

Comments
 (0)