|
| 1 | +/* |
| 2 | + * Copyright (C) 2023 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.HttpResponseAssertions.assertHttpMetricsResponse; |
| 20 | + |
| 21 | +import io.prometheus.jmx.test.AbstractTest; |
| 22 | +import io.prometheus.jmx.test.support.Mode; |
| 23 | +import io.prometheus.jmx.test.support.TestArgument; |
| 24 | +import io.prometheus.jmx.test.support.http.HttpHealthyRequest; |
| 25 | +import io.prometheus.jmx.test.support.http.HttpMetricsRequest; |
| 26 | +import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; |
| 27 | +import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; |
| 28 | +import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; |
| 29 | +import io.prometheus.jmx.test.support.http.HttpResponse; |
| 30 | +import io.prometheus.jmx.test.support.http.HttpResponseAssertions; |
| 31 | +import io.prometheus.jmx.test.support.metrics.DoubleValueMetricAssertion; |
| 32 | +import io.prometheus.jmx.test.support.metrics.Metric; |
| 33 | +import io.prometheus.jmx.test.support.metrics.MetricsParser; |
| 34 | +import java.util.Collection; |
| 35 | +import java.util.function.Consumer; |
| 36 | +import java.util.stream.Stream; |
| 37 | +import org.antublue.test.engine.api.TestEngine; |
| 38 | + |
| 39 | +public class RMIRegistrySSLDisabledTest extends AbstractTest implements Consumer<HttpResponse> { |
| 40 | + |
| 41 | + /** |
| 42 | + * Method to get the list of TestArguments |
| 43 | + * |
| 44 | + * @return the return value |
| 45 | + */ |
| 46 | + @TestEngine.ArgumentSupplier |
| 47 | + protected static Stream<TestArgument> arguments() { |
| 48 | + // Filter the arguments.. |
| 49 | + // |
| 50 | + // 1. only run the Standalone exporter |
| 51 | + // 2. filter out the GraalVM 1.8 JVM - exception is that SunJSSE is not found |
| 52 | + // 3. filter out all ibmjava* JVMs - exception is that SunJSSE is not found |
| 53 | + // |
| 54 | + return AbstractTest.arguments() |
| 55 | + .filter(testArgument -> testArgument.name().contains("Standalone")) |
| 56 | + .filter( |
| 57 | + testArgument1 -> |
| 58 | + !testArgument1.dockerImageName().contains("graalvm/jdk:java8")) |
| 59 | + .filter(testArgument1 -> !testArgument1.dockerImageName().contains("ibmjava")); |
| 60 | + } |
| 61 | + |
| 62 | + @TestEngine.Test |
| 63 | + public void testHealthy() { |
| 64 | + new HttpHealthyRequest() |
| 65 | + .send(testContext.httpClient()) |
| 66 | + .accept(HttpResponseAssertions::assertHttpHealthyResponse); |
| 67 | + } |
| 68 | + |
| 69 | + @TestEngine.Test |
| 70 | + public void testMetrics() { |
| 71 | + new HttpMetricsRequest().send(testContext.httpClient()).accept(this); |
| 72 | + } |
| 73 | + |
| 74 | + @TestEngine.Test |
| 75 | + public void testMetricsOpenMetricsFormat() { |
| 76 | + new HttpOpenMetricsRequest().send(testContext.httpClient()).accept(this); |
| 77 | + } |
| 78 | + |
| 79 | + @TestEngine.Test |
| 80 | + public void testMetricsPrometheusFormat() { |
| 81 | + new HttpPrometheusMetricsRequest().send(testContext.httpClient()).accept(this); |
| 82 | + } |
| 83 | + |
| 84 | + @TestEngine.Test |
| 85 | + public void testMetricsPrometheusProtobufFormat() { |
| 86 | + new HttpPrometheusProtobufMetricsRequest().send(testContext.httpClient()).accept(this); |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public void accept(HttpResponse httpResponse) { |
| 91 | + assertHttpMetricsResponse(httpResponse); |
| 92 | + |
| 93 | + Collection<Metric> metrics = MetricsParser.parse(httpResponse); |
| 94 | + |
| 95 | + String buildInfoName = |
| 96 | + testArgument.mode() == Mode.JavaAgent |
| 97 | + ? "jmx_prometheus_javaagent" |
| 98 | + : "jmx_prometheus_httpserver"; |
| 99 | + |
| 100 | + new DoubleValueMetricAssertion(metrics) |
| 101 | + .type("GAUGE") |
| 102 | + .name("jmx_exporter_build_info") |
| 103 | + .label("name", buildInfoName) |
| 104 | + .value(1d) |
| 105 | + .isPresent(); |
| 106 | + |
| 107 | + new DoubleValueMetricAssertion(metrics) |
| 108 | + .type("GAUGE") |
| 109 | + .name("jmx_scrape_error") |
| 110 | + .value(0d) |
| 111 | + .isPresent(); |
| 112 | + |
| 113 | + new DoubleValueMetricAssertion(metrics) |
| 114 | + .type("COUNTER") |
| 115 | + .name("jmx_config_reload_success_total") |
| 116 | + .value(0d) |
| 117 | + .isPresent(); |
| 118 | + |
| 119 | + new DoubleValueMetricAssertion(metrics) |
| 120 | + .type("GAUGE") |
| 121 | + .name("jvm_memory_used_bytes") |
| 122 | + .label("area", "nonheap") |
| 123 | + .isPresent(testArgument.mode() == Mode.JavaAgent); |
| 124 | + |
| 125 | + new DoubleValueMetricAssertion(metrics) |
| 126 | + .type("GAUGE") |
| 127 | + .name("jvm_memory_used_bytes") |
| 128 | + .label("area", "heap") |
| 129 | + .isPresent(testArgument.mode() == Mode.JavaAgent); |
| 130 | + |
| 131 | + new DoubleValueMetricAssertion(metrics) |
| 132 | + .type("GAUGE") |
| 133 | + .name("jvm_memory_used_bytes") |
| 134 | + .label("area", "nonheap") |
| 135 | + .isNotPresent(testArgument.mode() == Mode.Standalone); |
| 136 | + |
| 137 | + new DoubleValueMetricAssertion(metrics) |
| 138 | + .type("GAUGE") |
| 139 | + .name("jvm_memory_used_bytes") |
| 140 | + .label("area", "heap") |
| 141 | + .isNotPresent(testArgument.mode() == Mode.Standalone); |
| 142 | + |
| 143 | + new DoubleValueMetricAssertion(metrics) |
| 144 | + .type("UNTYPED") |
| 145 | + .name("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") |
| 146 | + .label("source", "/dev/sda1") |
| 147 | + .value(7.516192768E9d) |
| 148 | + .isPresent(); |
| 149 | + |
| 150 | + new DoubleValueMetricAssertion(metrics) |
| 151 | + .type("UNTYPED") |
| 152 | + .name("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") |
| 153 | + .label("source", "/dev/sda2") |
| 154 | + .value(0.8d) |
| 155 | + .isPresent(); |
| 156 | + } |
| 157 | +} |
0 commit comments