|
| 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 | + * http://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.rmi.ssl; |
| 18 | + |
| 19 | +import static io.prometheus.jmx.test.support.http.HttpResponse.assertHealthyResponse; |
| 20 | +import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; |
| 21 | +import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetricsContentType; |
| 22 | + |
| 23 | +import io.prometheus.jmx.test.support.environment.JmxExporterMode; |
| 24 | +import io.prometheus.jmx.test.support.environment.JmxExporterPath; |
| 25 | +import io.prometheus.jmx.test.support.environment.JmxExporterTestEnvironment; |
| 26 | +import io.prometheus.jmx.test.support.http.HttpClient; |
| 27 | +import io.prometheus.jmx.test.support.http.HttpHeader; |
| 28 | +import io.prometheus.jmx.test.support.http.HttpResponse; |
| 29 | +import io.prometheus.jmx.test.support.metrics.Metric; |
| 30 | +import io.prometheus.jmx.test.support.metrics.MetricsContentType; |
| 31 | +import io.prometheus.jmx.test.support.metrics.MetricsParser; |
| 32 | +import io.prometheus.jmx.test.support.util.TestSupport; |
| 33 | +import java.io.IOException; |
| 34 | +import java.util.ArrayList; |
| 35 | +import java.util.Collection; |
| 36 | +import java.util.List; |
| 37 | +import java.util.stream.Stream; |
| 38 | +import org.testcontainers.containers.Network; |
| 39 | +import org.verifyica.api.ArgumentContext; |
| 40 | +import org.verifyica.api.Trap; |
| 41 | +import org.verifyica.api.Verifyica; |
| 42 | + |
| 43 | +public class EnvironmentVariableRMISSLTest { |
| 44 | + |
| 45 | + @Verifyica.ArgumentSupplier(parallelism = Integer.MAX_VALUE) |
| 46 | + public static Stream<JmxExporterTestEnvironment> arguments() { |
| 47 | + // Filter the arguments.. |
| 48 | + // |
| 49 | + // 1. only run the Standalone exporter |
| 50 | + // 2. filter out the GraalVM 1.8 JVM - exception is that SunJSSE is not found |
| 51 | + // 3. filter out all ibmjava* JVMs - exception is that SunJSSE is not found |
| 52 | + // |
| 53 | + return JmxExporterTestEnvironment.createEnvironments() |
| 54 | + .filter( |
| 55 | + exporterTestEnvironment -> |
| 56 | + exporterTestEnvironment.getJmxExporterMode() |
| 57 | + == JmxExporterMode.Standalone) |
| 58 | + .filter( |
| 59 | + exporterTestEnvironment -> |
| 60 | + !exporterTestEnvironment |
| 61 | + .getJavaDockerImage() |
| 62 | + .contains("graalvm/jdk:java8")) |
| 63 | + .filter( |
| 64 | + exporterTestEnvironment -> |
| 65 | + !exporterTestEnvironment.getJavaDockerImage().contains("ibmjava")); |
| 66 | + } |
| 67 | + |
| 68 | + @Verifyica.BeforeAll |
| 69 | + public void beforeAll(ArgumentContext argumentContext) { |
| 70 | + Class<?> testClass = argumentContext.classContext().testClass(); |
| 71 | + Network network = TestSupport.getOrCreateNetwork(argumentContext); |
| 72 | + TestSupport.initializeExporterTestEnvironment(argumentContext, network, testClass); |
| 73 | + } |
| 74 | + |
| 75 | + @Verifyica.Test |
| 76 | + @Verifyica.Order(1) |
| 77 | + public void testHealthy(JmxExporterTestEnvironment jmxExporterTestEnvironment) |
| 78 | + throws IOException { |
| 79 | + String url = jmxExporterTestEnvironment.getUrl(JmxExporterPath.HEALTHY); |
| 80 | + |
| 81 | + HttpResponse httpResponse = HttpClient.sendRequest(url); |
| 82 | + |
| 83 | + assertHealthyResponse(httpResponse); |
| 84 | + } |
| 85 | + |
| 86 | + @Verifyica.Test |
| 87 | + public void testDefaultTextMetrics(JmxExporterTestEnvironment jmxExporterTestEnvironment) |
| 88 | + throws IOException { |
| 89 | + String url = jmxExporterTestEnvironment.getUrl(JmxExporterPath.METRICS); |
| 90 | + |
| 91 | + HttpResponse httpResponse = HttpClient.sendRequest(url); |
| 92 | + |
| 93 | + assertMetricsResponse(jmxExporterTestEnvironment, httpResponse, MetricsContentType.DEFAULT); |
| 94 | + } |
| 95 | + |
| 96 | + @Verifyica.Test |
| 97 | + public void testOpenMetricsTextMetrics(JmxExporterTestEnvironment jmxExporterTestEnvironment) |
| 98 | + throws IOException { |
| 99 | + String url = jmxExporterTestEnvironment.getUrl(JmxExporterPath.METRICS); |
| 100 | + |
| 101 | + HttpResponse httpResponse = |
| 102 | + HttpClient.sendRequest( |
| 103 | + url, |
| 104 | + HttpHeader.ACCEPT, |
| 105 | + MetricsContentType.OPEN_METRICS_TEXT_METRICS.toString()); |
| 106 | + |
| 107 | + assertMetricsResponse( |
| 108 | + jmxExporterTestEnvironment, |
| 109 | + httpResponse, |
| 110 | + MetricsContentType.OPEN_METRICS_TEXT_METRICS); |
| 111 | + } |
| 112 | + |
| 113 | + @Verifyica.Test |
| 114 | + public void testPrometheusTextMetrics(JmxExporterTestEnvironment jmxExporterTestEnvironment) |
| 115 | + throws IOException { |
| 116 | + String url = jmxExporterTestEnvironment.getUrl(JmxExporterPath.METRICS); |
| 117 | + |
| 118 | + HttpResponse httpResponse = |
| 119 | + HttpClient.sendRequest( |
| 120 | + url, |
| 121 | + HttpHeader.ACCEPT, |
| 122 | + MetricsContentType.PROMETHEUS_TEXT_METRICS.toString()); |
| 123 | + |
| 124 | + assertMetricsResponse( |
| 125 | + jmxExporterTestEnvironment, |
| 126 | + httpResponse, |
| 127 | + MetricsContentType.PROMETHEUS_TEXT_METRICS); |
| 128 | + } |
| 129 | + |
| 130 | + @Verifyica.Test |
| 131 | + public void testPrometheusProtobufMetrics(JmxExporterTestEnvironment jmxExporterTestEnvironment) |
| 132 | + throws IOException { |
| 133 | + String url = jmxExporterTestEnvironment.getUrl(JmxExporterPath.METRICS); |
| 134 | + |
| 135 | + HttpResponse httpResponse = |
| 136 | + HttpClient.sendRequest( |
| 137 | + url, |
| 138 | + HttpHeader.ACCEPT, |
| 139 | + MetricsContentType.PROMETHEUS_PROTOBUF_METRICS.toString()); |
| 140 | + |
| 141 | + assertMetricsResponse( |
| 142 | + jmxExporterTestEnvironment, |
| 143 | + httpResponse, |
| 144 | + MetricsContentType.PROMETHEUS_PROTOBUF_METRICS); |
| 145 | + } |
| 146 | + |
| 147 | + @Verifyica.AfterAll |
| 148 | + public void afterAll(ArgumentContext argumentContext) throws Throwable { |
| 149 | + List<Trap> traps = new ArrayList<>(); |
| 150 | + |
| 151 | + traps.add(new Trap(() -> TestSupport.destroyExporterTestEnvironment(argumentContext))); |
| 152 | + traps.add(new Trap(() -> TestSupport.destroyNetwork(argumentContext))); |
| 153 | + |
| 154 | + Trap.assertEmpty(traps); |
| 155 | + } |
| 156 | + |
| 157 | + private void assertMetricsResponse( |
| 158 | + JmxExporterTestEnvironment jmxExporterTestEnvironment, |
| 159 | + HttpResponse httpResponse, |
| 160 | + MetricsContentType metricsContentType) { |
| 161 | + assertMetricsContentType(httpResponse, metricsContentType); |
| 162 | + |
| 163 | + Collection<Metric> metrics = MetricsParser.parseCollection(httpResponse); |
| 164 | + |
| 165 | + boolean isJmxExporterModeJavaAgent = |
| 166 | + jmxExporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; |
| 167 | + |
| 168 | + String buildInfoName = |
| 169 | + TestSupport.getBuildInfoName(jmxExporterTestEnvironment.getJmxExporterMode()); |
| 170 | + |
| 171 | + assertMetric(metrics) |
| 172 | + .ofType(Metric.Type.GAUGE) |
| 173 | + .withName("jmx_exporter_build_info") |
| 174 | + .withLabel("name", buildInfoName) |
| 175 | + .withValue(1d) |
| 176 | + .isPresent(); |
| 177 | + |
| 178 | + assertMetric(metrics) |
| 179 | + .ofType(Metric.Type.GAUGE) |
| 180 | + .withName("jmx_scrape_error") |
| 181 | + .withValue(0d) |
| 182 | + .isPresent(); |
| 183 | + |
| 184 | + assertMetric(metrics) |
| 185 | + .ofType(Metric.Type.COUNTER) |
| 186 | + .withName("jmx_config_reload_success_total") |
| 187 | + .withValue(0d) |
| 188 | + .isPresent(); |
| 189 | + |
| 190 | + assertMetric(metrics) |
| 191 | + .ofType(Metric.Type.GAUGE) |
| 192 | + .withName("jvm_memory_used_bytes") |
| 193 | + .withLabel("area", "nonheap") |
| 194 | + .isPresentWhen(isJmxExporterModeJavaAgent); |
| 195 | + |
| 196 | + assertMetric(metrics) |
| 197 | + .ofType(Metric.Type.GAUGE) |
| 198 | + .withName("jvm_memory_used_bytes") |
| 199 | + .withLabel("area", "heap") |
| 200 | + .isPresentWhen(isJmxExporterModeJavaAgent); |
| 201 | + |
| 202 | + assertMetric(metrics) |
| 203 | + .ofType(Metric.Type.GAUGE) |
| 204 | + .withName("jvm_memory_used_bytes") |
| 205 | + .withLabel("area", "nonheap") |
| 206 | + .isPresentWhen(isJmxExporterModeJavaAgent); |
| 207 | + |
| 208 | + assertMetric(metrics) |
| 209 | + .ofType(Metric.Type.GAUGE) |
| 210 | + .withName("jvm_memory_used_bytes") |
| 211 | + .withLabel("area", "heap") |
| 212 | + .isPresentWhen(isJmxExporterModeJavaAgent); |
| 213 | + |
| 214 | + assertMetric(metrics) |
| 215 | + .ofType(Metric.Type.UNTYPED) |
| 216 | + .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") |
| 217 | + .withLabel("source", "/dev/sda1") |
| 218 | + .withValue(7.516192768E9d) |
| 219 | + .isPresent(); |
| 220 | + |
| 221 | + assertMetric(metrics) |
| 222 | + .ofType(Metric.Type.UNTYPED) |
| 223 | + .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") |
| 224 | + .withLabel("source", "/dev/sda2") |
| 225 | + .withValue(0.8d) |
| 226 | + .isPresent(); |
| 227 | + } |
| 228 | +} |
0 commit comments