diff --git a/.circleci/config.yml b/.circleci/config.yml index f563b708..b7d5e1d1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,7 +15,7 @@ jobs: - checkout - restore_cache: key: maven-dependencies-{{ checksum "pom.xml" }} - - run: ./integration_test_suite/docker-pull-images.smoke-test.sh + - run: ./integration_test_suite/pull-smoke-test-docker-images.sh - run: ./mvnw clean install - run: ./mvnw javadoc:jar - save_cache: diff --git a/.gitignore b/.gitignore index 80177aa4..fbdd40b0 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,3 @@ output.log stress-test.log test.sh test.log -.antublue-test-engine.properties diff --git a/MAINTAINER_NOTES.md b/MAINTAINER_NOTES.md index 72d9c850..2447b50f 100644 --- a/MAINTAINER_NOTES.md +++ b/MAINTAINER_NOTES.md @@ -57,19 +57,19 @@ Example ```shell /home/dhoard/Downloads/jmx_prometheus_javaagent-0.20.0.jar -/home/dhoard/Downloads/jmx_prometheus_httpserver-0.20.0.jar +/home/dhoard/Downloads/jmx_prometheus_standalone-0.20.0.jar ``` Command ```shell -./tools/patch-and-run-integration-test-suite.sh +./tools/patch-and-run-integration-test-suite.sh ``` Example ```shell -./tools/patch-and-run-integration-test-suite.sh /home/dhoard/Downloads/jmx_prometheus_javaagent-0.20.0.jar /home/dhoard/Downloads/jmx_prometheus_httpserver-0.20.0.jar +./tools/patch-and-run-integration-test-suite.sh /home/dhoard/Downloads/jmx_prometheus_javaagent-0.20.0.jar /home/dhoard/Downloads/jmx_prometheus_standalone-0.20.0.jar ``` ### Step 3 diff --git a/README.md b/README.md index 3da02dd8..346ef323 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,22 @@ +[![Build Status](https://circleci.com/gh/prometheus/jmx_exporter.svg?style=svg)](https://circleci.com/gh/prometheus/jmx_exporter) + # JMX Exporter -[![Build Status](https://circleci.com/gh/prometheus/jmx_exporter.svg?style=svg)](https://circleci.com/gh/prometheus/jmx_exporter) +JMX to Prometheus exporter: -JMX to Prometheus exporter: a collector that can configurable scrape and -expose MBeans of a JMX target. +A collector that can configurable scrape and expose MBeans of a JMX target. -This exporter is intended to be run as a Java Agent, exposing a HTTP server -and serving metrics of the local JVM. It can be also run as a standalone -HTTP server and scrape remote JMX targets, but this has various +This exporter is intended to be run as a Java Agent, exposing either +an HTTP endpoint or pushing Open Telemetry metrics of the local JVM. + +It can be also run as a standalone server and scrape remote JMX targets, but this has various disadvantages, such as being harder to configure and being unable to expose process metrics (e.g., memory and CPU usage). +In particular all the `jvm_*` metrics like `jvm_classes_loaded_total`, `jvm_threads_current`, +`jvm_threads_daemon` and `jvm_memory_bytes_used` won't be available when +using the standalone server. + **Running the exporter as a Java agent is strongly encouraged.** # Documentation diff --git a/collector/pom.xml b/collector/pom.xml index a4abdaab..35c971d1 100644 --- a/collector/pom.xml +++ b/collector/pom.xml @@ -48,6 +48,28 @@ + + com.diffplug.spotless + spotless-maven-plugin + 2.43.0 + + + + 1.22.0 + + true + + + + + + + apply + + compile + + + @@ -89,7 +111,6 @@ prometheus-metrics-instrumentation-jvm test - diff --git a/collector/src/main/java/io/prometheus/jmx/BuildInfoMetrics.java b/collector/src/main/java/io/prometheus/jmx/BuildInfoMetrics.java index a771202f..bd1716a3 100755 --- a/collector/src/main/java/io/prometheus/jmx/BuildInfoMetrics.java +++ b/collector/src/main/java/io/prometheus/jmx/BuildInfoMetrics.java @@ -31,7 +31,7 @@ * Metrics being exported: * *
- *   jmx_exporter_build_info{version="3.2.0",name="jmx_prometheus_httpserver",} 1.0
+ *   jmx_exporter_build_info{version="3.2.0",name="jmx_prometheus_standalone",} 1.0
  * 
*/ public class BuildInfoMetrics { diff --git a/collector/src/main/java/io/prometheus/jmx/JmxCollector.java b/collector/src/main/java/io/prometheus/jmx/JmxCollector.java index 450083da..ca0f03f4 100644 --- a/collector/src/main/java/io/prometheus/jmx/JmxCollector.java +++ b/collector/src/main/java/io/prometheus/jmx/JmxCollector.java @@ -181,7 +181,7 @@ private void exitOnConfigError() { LOGGER.log( SEVERE, "Configuration error: When running jmx_exporter in standalone mode (using" - + " jmx_prometheus_httpserver-*.jar) you must configure 'jmxUrl' or" + + " jmx_prometheus_standalone-*.jar) you must configure 'jmxUrl' or" + " 'hostPort'."); System.exit(-1); } diff --git a/docs/README.md b/docs/README.md index 464553fa..926a3219 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,17 +5,22 @@ JMX Exporter ===== -JMX to Prometheus exporter: a collector that can configurable scrape and -expose mBeans of a JMX target. +JMX to Prometheus exporter: -This exporter is intended to be run as a Java Agent, exposing a HTTP server -and serving metrics of the local JVM. It can be also run as a standalone -HTTP server and scrape remote JMX targets, but this has various +A collector that can configurable scrape and expose MBeans of a JMX target. + +This exporter is intended to be run as a Java Agent, exposing either +an HTTP endpoint or pushing Open Telemetry metrics of the local JVM. + +It can be also run as a standalone server and scrape remote JMX targets, but this has various disadvantages, such as being harder to configure and being unable to expose -process metrics (e.g., memory and CPU usage). In particular all the -`jvm_*` metrics like `jvm_classes_loaded_total`, `jvm_threads_current`, -`jvm_threads_daemon` and `jvm_memory_bytes_used` won't be availabe if -using the standalone http server. +process metrics (e.g., memory and CPU usage). + +In particular all the `jvm_*` metrics like `jvm_classes_loaded_total`, `jvm_threads_current`, +`jvm_threads_daemon` and `jvm_memory_bytes_used` won't be available when +using the standalone server. + +**Running the exporter as a Java agent is strongly encouraged.** ### **NOTES** @@ -52,21 +57,21 @@ rules: Example configurations can be found in the `example_configs/` directory. -## Running the Standalone HTTP Server +## Running the Standalone Server -- [jmx_prometheus_httpserver-1.0.1.jar](https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_httpserver/1.0.1/jmx_prometheus_httpserver-1.0.1.jar) +- [jmx_prometheus_standalone-1.0.1.jar](https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_standalone/1.0.1/jmx_prometheus_standalone-1.0.1.jar) -To run the standalone HTTP server, download one of the JARs and run: +To run the standalone server, download one of the JARs and run: ``` -java -jar jmx_prometheus_httpserver-1.0.1.jar 12345 config.yaml +java -jar jmx_prometheus_standalone-1.0.1.jar 12345 config.yaml ``` Metrics will now be accessible at [http://localhost:12345/metrics](http://localhost:12345/metrics). To bind the java agent to a specific IP change the port number to `host:port`. -The standalone HTTP server will read JMX remotely over the network. Therefore, you need to specify -either `hostPort` or `jmxUrl` in `config.yaml` to tell the HTTP server where the JMX beans can be accessed. +The standalone server will read JMX remotely over the network. Therefore, you need to specify +either `hostPort` or `jmxUrl` in `config.yaml` to tell the server where the JMX beans can be accessed. A minimal `config.yaml` looks like this: @@ -76,7 +81,7 @@ rules: - pattern: ".*" ``` -As stated above, it is recommended to run JMX exporter as a Java agent and not as a standalone HTTP server. +As stated above, it is recommended to run JMX exporter as a Java agent and not as a standalone server. **NOTES** @@ -332,7 +337,7 @@ httpServer: ## Integration Test Suite -The JMX exporter uses the [AntuBLUE Test Engine](https://github.com/antublue/test-engine) and [Testcontainers](https://www.testcontainers.org/) to run integration tests with different Java versions. +The JMX exporter project uses [Verifyica](https://github.com/antublue/verifyica) and [Testcontainers](https://www.testcontainers.org/) to run integration tests with different Java versions. You need to have Docker installed to run the integration test suite. diff --git a/example_configs/httpserver_sample_config.yml b/example_configs/standalone_sample_config.yml similarity index 100% rename from example_configs/httpserver_sample_config.yml rename to example_configs/standalone_sample_config.yml diff --git a/integration_test_suite/README.md b/integration_test_suite/README.md index e4403800..fb70544b 100644 --- a/integration_test_suite/README.md +++ b/integration_test_suite/README.md @@ -1,14 +1,12 @@ -Integration Test Suite ---- ---- +# Integration Test Suite -### Smoke test Docker images tested +### Smoke test Java Docker images tested -[Smoke test Docker images](https://github.com/prometheus/jmx_exporter/blob/main/integration_test_suite/integration_tests/src/test/resources/docker-image-names.smoke-test.txt) +[Smoke test Docker images](https://github.com/prometheus/jmx_exporter/blob/main/integration_test_suite/integration_tests/src/test/resources/smoke-test-java-docker-images.txt) -### Docker images tested (all) +### All Java Docker images tested (all) -[All Docker images](https://github.com/prometheus/jmx_exporter/blob/main/integration_test_suite/integration_tests/src/test/resources/docker-image-names.all.txt) +[All Docker images](https://github.com/prometheus/jmx_exporter/blob/main/integration_test_suite/integration_tests/src/test/resources/java-docker-images.txt) ### Running the integration test suite (smoke test Docker images) @@ -19,21 +17,21 @@ Integration Test Suite ### Run the integration test suite (all Docker images) ```shell -export DOCKER_IMAGE_NAMES=ALL +export JAVA_DOCKER_IMAGES=ALL ./mvnw clean verify ``` ### Run the integration test suite on a specific Docker image ```shell -export DOCKER_IMAGE_NAMES="" +export JAVA_DOCKER_IMAGES="" ./mvnw clean verify ``` Example: ```shell -export DOCKER_IMAGE_NAMES="azul/zulu-openjdk:17" +export JAVA_DOCKER_IMAGES="azul/zulu-openjdk:17" ./mvnw clean verify ``` @@ -44,15 +42,46 @@ Pulling Docker images (not required, but you may see request timeouts/pull failu Smoke test Docker images ```shell -./integration_test_suite/docker-pull-images.smoke-test.sh +./integration_test_suite/pull-smoke-test-java-docker-images.sh ``` All Docker images ```shell -./integration_test_suite/docker-pull-images.all.sh +./integration_test_suite/pull-java-docker-images.sh ``` ## Notes - You may need to set up Docker hub login to pull images + +# Docker networks + +By default, Docker is not configured to run a large number images simultaneously. + +You can increase Docker networks by creating a Docker network configuration file... + +``` +/etc/docker/daemon.json +``` + +... with the content... + +```yaml +{ + "default-address-pools": [ + { + "base": "172.16.0.0/16", + "size": 24 + }, + { + "base": "192.168.0.0/16", + "size": 24 + } + ] +} +``` + +## Notes + +- Docker will need to be restarted \ No newline at end of file diff --git a/integration_test_suite/integration_tests/pom.xml b/integration_test_suite/integration_tests/pom.xml index 355f2c09..3583b0b5 100644 --- a/integration_test_suite/integration_tests/pom.xml +++ b/integration_test_suite/integration_tests/pom.xml @@ -28,11 +28,7 @@ 11 UTF-8 UTF-8 - 7.0.0 - - - - + 0.0.6 @@ -62,11 +58,11 @@ - clean-resources - clean - - clean - + clean-resources + clean + + clean + @@ -79,14 +75,9 @@ - org.antublue - test-engine-maven-plugin - ${antublue.test.engine.version} - - - ${docker.image.names} - - + org.antublue.verifyica + maven-plugin + ${verifyica.version} verify @@ -96,14 +87,46 @@ + + com.diffplug.spotless + spotless-maven-plugin + 2.43.0 + + + + 1.22.0 + + true + + + + + + + apply + + compile + + + - org.antublue - test-engine-api - ${antublue.test.engine.version} + org.antublue.verifyica + api + ${verifyica.version} + + + org.antublue.verifyica + engine + ${verifyica.version} + + + io.prometheus.jmx + jmx_prometheus_common + ${project.version} io.prometheus @@ -128,7 +151,7 @@ org.testcontainers testcontainers - 1.19.8 + 1.20.0 com.squareup.okhttp3 @@ -141,10 +164,9 @@ 3.26.0 - org.antublue - test-engine - ${antublue.test.engine.version} - test + org.yaml + snakeyaml + 2.2 diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/DockerImageNames.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/JavaDockerImages.java similarity index 65% rename from integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/DockerImageNames.java rename to integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/JavaDockerImages.java index 5d1fa79c..4ba3e71b 100644 --- a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/DockerImageNames.java +++ b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/JavaDockerImages.java @@ -22,56 +22,57 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; -import java.util.List; +import java.util.Collections; import java.util.Locale; import java.util.Objects; import java.util.function.Predicate; -import java.util.stream.Stream; -/** Class to get Docker image names */ -public final class DockerImageNames { +/** Class to implement JavaDockerImages */ +public final class JavaDockerImages { - private static final String DOCKER_IMAGE_NAMES_CONFIGURATION = "docker.image.names"; + private static final String DOCKER_IMAGES_CONFIGURATION = "java.docker.images"; + + private static final String DOCKER_IMAGES_RESOURCE = "/java-docker-images.txt"; + + private static final String SMOKE_TEST_DOCKER_IMAGES_RESOURCE = + "/smoke-test-java-docker-images.txt"; - private static final String ALL_DOCKER_IMAGE_NAMES_RESOURCE = "/docker-image-names.all.txt"; private static String[] ALL_DOCKER_IMAGE_NAMES; - private static final String SMOKE_TEST_DOCKER_IMAGE_NAMES_RESOURCE = - "/docker-image-names.smoke-test.txt"; - private static String[] SMOKE_TEST_DOCKER_IMAGE_NAMES; + private static String[] SMOKE_TEST_DOCKER_IMAGES; /** Predicate to accept all Docker image names */ - public static final Predicate ALL_JAVA_VERSIONS = name -> true; + public static final Predicate ACCEPT_ALL = name -> true; /** Constructor */ - private DockerImageNames() { + private JavaDockerImages() { // DO NOTHING } /** - * Method to get Stream of all Docker image names + * Method to get Collection of all Docker image names * - * @return the Stream of Docker image names + * @return the Collection of Docker image names */ - public static Stream names() { - return names(ALL_JAVA_VERSIONS); + public static Collection names() { + return names(ACCEPT_ALL); } /** - * Method to get Stream of Docker image names filtered by a Predicate + * Method to get List of Docker image names filtered by a Predicate * * @param predicate predicate - * @return the Stream of Docker image names + * @return the List of Docker image names */ - public static Stream names(Predicate predicate) { + public static Collection names(Predicate predicate) { Objects.requireNonNull(predicate); - synchronized (DockerImageNames.class) { + synchronized (JavaDockerImages.class) { if (ALL_DOCKER_IMAGE_NAMES == null) { - ALL_DOCKER_IMAGE_NAMES = load(ALL_DOCKER_IMAGE_NAMES_RESOURCE); + ALL_DOCKER_IMAGE_NAMES = load(DOCKER_IMAGES_RESOURCE); } - if (SMOKE_TEST_DOCKER_IMAGE_NAMES == null) { - SMOKE_TEST_DOCKER_IMAGE_NAMES = load(SMOKE_TEST_DOCKER_IMAGE_NAMES_RESOURCE); + if (SMOKE_TEST_DOCKER_IMAGES == null) { + SMOKE_TEST_DOCKER_IMAGES = load(SMOKE_TEST_DOCKER_IMAGES_RESOURCE); } } @@ -79,9 +80,7 @@ public static Stream names(Predicate predicate) { String dockerImageNameValue = System.getenv( - DOCKER_IMAGE_NAMES_CONFIGURATION - .toUpperCase(Locale.ENGLISH) - .replace('.', '_')); + DOCKER_IMAGES_CONFIGURATION.toUpperCase(Locale.ENGLISH).replace('.', '_')); if (dockerImageNameValue != null) { dockerImageNameValue = dockerImageNameValue.trim(); @@ -91,7 +90,7 @@ public static Stream names(Predicate predicate) { } if (dockerImageNameValue == null) { - dockerImageNameValue = System.getProperty(DOCKER_IMAGE_NAMES_CONFIGURATION); + dockerImageNameValue = System.getProperty(DOCKER_IMAGES_CONFIGURATION); if (dockerImageNameValue != null) { if (dockerImageNameValue.isBlank()) { dockerImageNameValue = null; @@ -100,7 +99,7 @@ public static Stream names(Predicate predicate) { } if (dockerImageNameValue == null) { - dockerImageNames = SMOKE_TEST_DOCKER_IMAGE_NAMES; + dockerImageNames = SMOKE_TEST_DOCKER_IMAGES; } else if (dockerImageNameValue.equalsIgnoreCase("ALL")) { dockerImageNames = ALL_DOCKER_IMAGE_NAMES; } else { @@ -114,7 +113,7 @@ public static Stream names(Predicate predicate) { } } - return dockerImageNamesCollection.stream(); + return Collections.unmodifiableCollection(dockerImageNamesCollection); } /** @@ -124,14 +123,14 @@ public static Stream names(Predicate predicate) { * @return the String array of lines */ private static String[] load(String resource) { - List dockerImageNames = new ArrayList<>(); + Collection dockerImageNames = new ArrayList<>(); BufferedReader bufferedReader; try { bufferedReader = new BufferedReader( new InputStreamReader( - DockerImageNames.class.getResourceAsStream(resource), + JavaDockerImages.class.getResourceAsStream(resource), StandardCharsets.UTF_8)); while (true) { @@ -148,8 +147,7 @@ private static String[] load(String resource) { return dockerImageNames.toArray(new String[0]); } catch (IOException e) { - throw new RuntimeException( - "Exception reading resource " + ALL_DOCKER_IMAGE_NAMES_RESOURCE, e); + throw new RuntimeException("Exception reading resource " + DOCKER_IMAGES_RESOURCE, e); } } } diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/TestArguments.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/TestArguments.java deleted file mode 100644 index 8b66367b..00000000 --- a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/TestArguments.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2023 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 - * - * http://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.support; - -import org.antublue.test.engine.api.Argument; - -public class TestArguments implements Argument { - - private final String name; - private final String dockerImageName; - private final JmxExporterMode jmxExporterMode; - - private TestArguments(String name, String dockerImageName, JmxExporterMode jmxExporterMode) { - this.name = name; - this.dockerImageName = dockerImageName; - this.jmxExporterMode = jmxExporterMode; - } - - @Override - public String getName() { - return name; - } - - @Override - public TestArguments getPayload() { - return this; - } - - public String getDockerImageName() { - return dockerImageName; - } - - public JmxExporterMode getJmxExporterMode() { - return jmxExporterMode; - } - - @Override - public String toString() { - return String.format( - "TestArgument{name=[%s],dockerImageName=[%s],mode=[%s]}", - name, dockerImageName, jmxExporterMode); - } - - public static TestArguments of( - String name, String dockerImageName, JmxExporterMode jmxExporterMode) { - return new TestArguments(name, dockerImageName, jmxExporterMode); - } -} diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/TestEnvironment.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/TestEnvironment.java deleted file mode 100644 index d4b96215..00000000 --- a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/TestEnvironment.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (C) 2023 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 - * - * http://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.support; - -import io.prometheus.jmx.test.support.http.HttpClient; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; - -/** Class to a TestContext */ -public class TestEnvironment { - - private Network network; - private GenericContainer applicationContainer; - private GenericContainer exporterContainer; - private String baseUrl; - private HttpClient httpClient; - - /** Constructor */ - public TestEnvironment() { - // DO NOTHING - } - - /** - * Method to set the Network - * - * @param network network - * @return this - */ - public TestEnvironment setNetwork(Network network) { - this.network = network; - return this; - } - - /** - * Method to get the Network - * - * @return the Network - */ - public Network getNetwork() { - return network; - } - - /** - * Method to set the application container - * - * @param applicationContainer application container - * @return this - */ - public TestEnvironment setApplicationContainer(GenericContainer applicationContainer) { - this.applicationContainer = applicationContainer; - return this; - } - - /** - * Method to get the application container - * - * @return the application container - */ - public GenericContainer getApplicationContainer() { - return applicationContainer; - } - - /** - * Method to set the exporter container - * - * @param exporterContainer exporter container - * @return this - */ - public TestEnvironment setExporterContainer(GenericContainer exporterContainer) { - this.exporterContainer = exporterContainer; - return this; - } - - /** - * Method to get the exporter container - * - * @return the exporter container - */ - public GenericContainer getExporterContainer() { - return exporterContainer; - } - - /** - * Method to set the base URL - * - * @param baseUrl baseURL - * @return this - */ - public TestEnvironment setBaseUrl(String baseUrl) { - this.baseUrl = baseUrl; - return this; - } - - /** - * Method to get the base URL - * - * @return the base URL - */ - public String getBaseUrl() { - return baseUrl; - } - - /** - * Method to set the HttpClient - * - * @param httpClient httpClient - * @return this - */ - public TestEnvironment setHttpClient(HttpClient httpClient) { - this.httpClient = httpClient; - return this; - } - - /** - * Method to get the HttpClient - * - * @return the HttpClient - */ - public HttpClient getHttpClient() { - return httpClient; - } - - /** Method to reset the test state (containers) */ - public void reset() { - if (exporterContainer != null) { - exporterContainer.close(); - } - - if (applicationContainer != null) { - applicationContainer.close(); - } - - setApplicationContainer(null); - setExporterContainer(null); - setHttpClient(null); - } - - /** Method to dispose the test state (containers and network) */ - public void destroy() { - if (exporterContainer != null) { - exporterContainer.close(); - exporterContainer = null; - } - - if (applicationContainer != null) { - applicationContainer.close(); - applicationContainer = null; - } - - if (network != null) { - network.close(); - network = null; - } - - httpClient = null; - } -} diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpClient.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpClient.java index 8b56eadf..23505256 100644 --- a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpClient.java +++ b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpClient.java @@ -22,6 +22,7 @@ import java.time.Duration; import java.util.Base64; import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; @@ -43,6 +44,14 @@ public HttpClient(String baseUrl) { this.baseUrl = baseUrl; } + public HttpResponse send(HttpRequest httpRequest) { + return httpRequest.send(this); + } + + public void send(HttpRequest httpRequest, Consumer httpResponseConsumer) { + httpResponseConsumer.accept(httpRequest.send(this)); + } + public Request.Builder createRequest(String path) { return new Request.Builder().url(baseUrl + path); } diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpRequest.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpRequest.java index 786001af..080da069 100644 --- a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpRequest.java +++ b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpRequest.java @@ -16,16 +16,17 @@ package io.prometheus.jmx.test.support.http; +import java.util.function.Consumer; import okhttp3.Headers; -/** Base class for all tests */ -public abstract class HttpRequest { +/** Class to implement HttpRequest */ +public class HttpRequest { - protected HttpClient httpClient; protected Headers.Builder headersBuilder; protected String path; protected HttpCredentials httpCredentials; + /** Constructor */ public HttpRequest() { headersBuilder = new Headers.Builder(); } @@ -33,11 +34,11 @@ public HttpRequest() { /** * Constructor * - * @param httpClient httpClient + * @param path path */ - public HttpRequest(HttpClient httpClient) { - this.httpClient = httpClient; - this.headersBuilder = new Headers.Builder(); + public HttpRequest(String path) { + headersBuilder = new Headers.Builder(); + path(path); } /** @@ -81,7 +82,7 @@ public HttpRequest credentials(HttpCredentials httpCredentials) { } /** - * Method to execute the request + * Method to send the request * * @param httpClient httpClient * @return the response @@ -109,4 +110,14 @@ public HttpResponse send(HttpClient httpClient) { throw new RuntimeException(t); } } + + /** + * Method to send the request + * + * @param httpClient httpClient + * @param httpResponseConsumer httpResponseConsumer + */ + public void send(HttpClient httpClient, Consumer httpResponseConsumer) { + httpResponseConsumer.accept(send(httpClient)); + } } diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpResponse.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpResponse.java index 348d3710..7f1929d6 100644 --- a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpResponse.java +++ b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpResponse.java @@ -18,15 +18,25 @@ public HttpResponse(okhttp3.Response response) throws IOException { this.code = response.code(); this.headers = response.headers(); - ResponseBody responseBody = response.body(); - if (responseBody != null) { - body = new HttpResponseBody(responseBody.bytes()); - } else { - body = null; + try { + ResponseBody responseBody = response.body(); + if (responseBody != null) { + body = new HttpResponseBody(responseBody.bytes()); + } else { + body = null; + } + } finally { + if (response != null) { + try { + response.close(); + } catch (Throwable t) { + // DO NOTHING + } + } } } - public int code() { + public int statusCode() { return code; } diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpResponseAssertions.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpResponseAssertions.java index 6af309f4..307ef5d8 100644 --- a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpResponseAssertions.java +++ b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/http/HttpResponseAssertions.java @@ -9,7 +9,7 @@ private HttpResponseAssertions() { } public static void assertHttpResponseCode(HttpResponse httpResponse, int code) { - assertThat(httpResponse.code()).isEqualTo(code); + assertThat(httpResponse.statusCode()).isEqualTo(code); } public static void assertHttpResponseHasHeaders(HttpResponse httpResponse) { @@ -28,7 +28,7 @@ public static void assertHttpResponseHasBody(HttpResponse httpResponse) { public static void assertHttpHealthyResponse(HttpResponse httpResponse) { assertThat(httpResponse).isNotNull(); - assertThat(httpResponse.code()).isEqualTo(200); + assertThat(httpResponse.statusCode()).isEqualTo(200); assertThat(httpResponse.body()).isNotNull(); assertThat(httpResponse.body().string().length()).isGreaterThan(0); assertThat(httpResponse.body().string()).isEqualTo("Exporter is healthy.\n"); @@ -36,7 +36,7 @@ public static void assertHttpHealthyResponse(HttpResponse httpResponse) { public static void assertHttpMetricsResponse(HttpResponse httpResponse) { assertThat(httpResponse).isNotNull(); - assertThat(httpResponse.code()).isEqualTo(200); + assertThat(httpResponse.statusCode()).isEqualTo(200); assertHttpResponseHasHeaders(httpResponse); assertHttpResponseHasHeader(httpResponse, HttpHeader.CONTENT_TYPE); assertHttpResponseHasBody(httpResponse); diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/LabelsSubsetFilter.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/LabelsSubsetFilter.java deleted file mode 100644 index 85e17234..00000000 --- a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/LabelsSubsetFilter.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2023 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 - * - * http://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.support.metrics; - -import java.util.Map; -import java.util.TreeMap; -import java.util.function.Predicate; - -/** Class to filter to test if a Metric contains a subset of labels */ -public class LabelsSubsetFilter implements Predicate { - - private final TreeMap labels; - - /** - * Constructor - * - * @param labels labels - */ - public LabelsSubsetFilter(TreeMap labels) { - this.labels = labels; - } - - @Override - public boolean test(Metric metric) { - Map labels = metric.labels(); - return labels.entrySet().containsAll(this.labels.entrySet()); - } -} diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MapMetricAssertion.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MapMetricAssertion.java new file mode 100644 index 00000000..58c3d6a7 --- /dev/null +++ b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MapMetricAssertion.java @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2023 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 + * + * http://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.support.metrics; + +import java.util.Collection; +import java.util.Map; +import java.util.TreeMap; +import java.util.stream.Collectors; +import org.opentest4j.AssertionFailedError; + +/** Class to assert a MapMetricAssertion */ +public class MapMetricAssertion { + + private final Map> metrics; + private Metric.Type type; + private String name; + private String help; + private TreeMap labels; + private Double value; + + /** + * Constructor + * + * @param metrics metrics + */ + MapMetricAssertion(Map> metrics) { + if (metrics == null) { + throw new IllegalArgumentException("metrics is null"); + } + this.metrics = metrics; + } + + /** + * Method to set the type to match against + * + * @param type type + * @return this MetricAssertion + */ + public MapMetricAssertion ofType(Metric.Type type) { + if (type == null) { + throw new IllegalArgumentException("Type is null"); + } + this.type = type; + return this; + } + + /** + * Method to set the name to match against + * + * @param name name + * @return this MetricAssertion + */ + public MapMetricAssertion withName(String name) { + this.name = name; + return this; + } + + /** + * Method to set the help to match against + * + * @param help help + * @return this MetricAssertion + */ + public MapMetricAssertion help(String help) { + this.help = help; + return this; + } + + /** + * Method to add a label to match against + * + * @param name name + * @param value value + * @return this MetricAssertion + */ + public MapMetricAssertion withLabel(String name, String value) { + if (name == null || value == null) { + throw new IllegalArgumentException( + String.format("Label name [%s] or value [%s] is null", name, value)); + } + if (labels == null) { + labels = new TreeMap<>(); + } + labels.put(name, value); + return this; + } + + /** + * Method to set the value to match against + * + * @param value value + * @return this MetricAssertion + */ + public MapMetricAssertion withValue(Double value) { + this.value = value; + return this; + } + + /** + * Method to assert the Metric is present + * + * @return this MetricAssertion + */ + public MapMetricAssertion isPresent() { + return isPresentWhen(true); + } + + /** + * Method to assert the Metric is present + * + * @param condition condition + * @return this MetricAssertion + */ + public MapMetricAssertion isPresentWhen(boolean condition) { + Collection metrics = this.metrics.get(name); + + if (condition && metrics == null) { + throw new AssertionFailedError( + String.format( + "Metric type [%s] help [%s] name [%s] labels [%s] value [%f]" + + " matches multiple metrics", + type, help, name, labels, value)); + } else if (!condition && metrics != null) { + throw new AssertionFailedError( + String.format( + "Metric type [%s] help [%s] name [%s] labels [%s] value [%f] is" + + " present", + type, help, name, labels, value)); + } else if (!condition) { + return this; + } + + Collection subMetrics = + metrics.stream() + .filter(metric -> type == null || metric.type().equals(type)) + .filter(metric -> help == null || metric.help().equals(help)) + .filter( + metric -> + labels == null + || metric.labels() + .entrySet() + .containsAll(labels.entrySet())) + .filter(metric -> value == null || metric.value() == value) + .collect(Collectors.toList()); + + if (condition) { + if (subMetrics.size() > 1) { + throw new AssertionFailedError( + String.format( + "Metric type [%s] help [%s] name [%s] labels [%s] value [%f]" + + " matches multiple metrics", + type, help, name, labels, value)); + } else if (subMetrics.isEmpty()) { + throw new AssertionFailedError( + String.format( + "Metric type [%s] help [%s] name [%s] labels [%s] value [%f] is not" + + " present", + type, help, name, labels, value)); + } + } else { + if (!subMetrics.isEmpty()) { + throw new AssertionFailedError( + String.format( + "Metric type [%s] help [%s] name [%s] labels [%s] value [%f] is" + + " present", + type, help, name, labels, value)); + } + } + + return this; + } + + /** + * Method to assert the Metric is not present + * + * @return this MetricAssertion + */ + public MapMetricAssertion isNotPresent() { + return isPresentWhen(false); + } + + /** + * Method to assert the Metric is not present + * + * @param condition condition + * @return this MetricAssertion + */ + public MapMetricAssertion isNotPresentWhen(boolean condition) { + return isPresentWhen(!condition); + } + + /** + * Method to create a MetricAssertion + * + * @param metrics the collection of metrics + * @return a MetricAssertion + */ + public static MapMetricAssertion assertMetric(Map> metrics) { + return new MapMetricAssertion(metrics); + } +} diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/Metric.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/Metric.java index 825acddf..aaf2b967 100644 --- a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/Metric.java +++ b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/Metric.java @@ -23,12 +23,22 @@ /** Class to implement a Metric */ public class Metric { - private final String type; + private final Type type; private final String name; private final String help; private final TreeMap labels; private final double value; + /** Metric types */ + public enum Type { + /** Gauge */ + GAUGE, + /** Counter */ + COUNTER, + /** Untyped */ + UNTYPED + } + /** * Constructor * @@ -39,7 +49,7 @@ public class Metric { * @param value value */ public Metric( - String type, String help, String name, TreeMap labels, double value) { + Type type, String help, String name, TreeMap labels, double value) { this.type = type; this.help = help; this.name = name; @@ -52,7 +62,7 @@ public Metric( * * @return the Metric type */ - public String type() { + public Type type() { return type; } diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MetricAssertion.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MetricAssertion.java index 674bed03..42835cb7 100644 --- a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MetricAssertion.java +++ b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MetricAssertion.java @@ -17,26 +17,17 @@ package io.prometheus.jmx.test.support.metrics; import java.util.Collection; -import java.util.HashSet; import java.util.List; -import java.util.Set; +import java.util.Map; import java.util.TreeMap; import java.util.stream.Collectors; import org.opentest4j.AssertionFailedError; -/** Class to assert a DoubleValueMetric */ +/** Class to assert a MetricAssertion */ public class MetricAssertion { - private static final Set VALID_TYPES = new HashSet<>(); - - static { - VALID_TYPES.add("COUNTER"); - VALID_TYPES.add("GAUGE"); - VALID_TYPES.add("UNTYPED"); - } - private final Collection metrics; - private String type; + private Metric.Type type; private String name; private String help; private TreeMap labels; @@ -49,7 +40,7 @@ public class MetricAssertion { */ private MetricAssertion(Collection metrics) { if (metrics == null) { - throw new IllegalArgumentException("Collection is null"); + throw new IllegalArgumentException("metrics is null"); } this.metrics = metrics; } @@ -60,9 +51,9 @@ private MetricAssertion(Collection metrics) { * @param type type * @return this MetricAssertion */ - public MetricAssertion ofType(String type) { - if (type == null || !VALID_TYPES.contains(type)) { - throw new IllegalArgumentException(String.format("Type [%s] is null or invalid", type)); + public MetricAssertion ofType(Metric.Type type) { + if (type == null) { + throw new IllegalArgumentException("Type is null"); } this.type = type; return this; @@ -126,7 +117,7 @@ public MetricAssertion withValue(Double value) { * @return this MetricAssertion */ public MetricAssertion isPresent() { - return isPresent(true); + return isPresentWhen(true); } /** @@ -135,7 +126,7 @@ public MetricAssertion isPresent() { * @param condition condition * @return this MetricAssertion */ - public MetricAssertion isPresent(boolean condition) { + public MetricAssertion isPresentWhen(boolean condition) { List metrics = this.metrics.stream() .filter(metric -> type == null || metric.type().equals(type)) @@ -144,7 +135,9 @@ public MetricAssertion isPresent(boolean condition) { .filter( metric -> labels == null - || new LabelsSubsetFilter(labels).test(metric)) + || metric.labels() + .entrySet() + .containsAll(labels.entrySet())) .filter(metric -> value == null || metric.value() == value) .collect(Collectors.toList()); @@ -163,7 +156,7 @@ public MetricAssertion isPresent(boolean condition) { type, help, name, labels, value)); } } else { - if (metrics.size() > 0) { + if (!metrics.isEmpty()) { throw new AssertionFailedError( String.format( "Metric type [%s] help [%s] name [%s] labels [%s] value [%f] is" @@ -181,7 +174,7 @@ public MetricAssertion isPresent(boolean condition) { * @return this MetricAssertion */ public MetricAssertion isNotPresent() { - return isPresent(false); + return isPresentWhen(false); } /** @@ -190,8 +183,8 @@ public MetricAssertion isNotPresent() { * @param condition condition * @return this MetricAssertion */ - public MetricAssertion isNotPresent(boolean condition) { - return isPresent(!condition); + public MetricAssertion isNotPresentWhen(boolean condition) { + return isPresentWhen(!condition); } /** @@ -203,4 +196,14 @@ public MetricAssertion isNotPresent(boolean condition) { public static MetricAssertion assertMetric(Collection metrics) { return new MetricAssertion(metrics); } + + /** + * Method to create a MetricAssertion + * + * @param metrics the collection of metrics + * @return a MetricAssertion + */ + public static MapMetricAssertion assertMetric(Map> metrics) { + return new MapMetricAssertion(metrics); + } } diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MetricsParser.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MetricsParser.java index 71f4e3bc..b2da1909 100644 --- a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MetricsParser.java +++ b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MetricsParser.java @@ -30,8 +30,10 @@ import java.util.Collection; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.TreeMap; +import java.util.stream.Collectors; /** Class to parse Metrics from an HttpResponse */ public class MetricsParser { @@ -41,13 +43,26 @@ private MetricsParser() { // DO NOTHING } + /** + * Method to parse Metrics from an HttpResponse + * + * @param httpResponse httpResponse + * @return a Map of Metrics + */ + public static Map> parseMap(HttpResponse httpResponse) { + return parseCollection(httpResponse).stream() + .collect( + Collectors.groupingBy( + Metric::name, Collectors.toCollection(ArrayList::new))); + } + /** * Method to parse Metrics from an HttpResponse * * @param httpResponse httpResponse * @return a Collection of Metrics */ - public static Collection parse(HttpResponse httpResponse) { + public static Collection parseCollection(HttpResponse httpResponse) { if (Objects.requireNonNull(httpResponse.headers().get(HttpHeader.CONTENT_TYPE)) .contains(HttpContentType.PROTOBUF)) { return parseProtobufMetrics(httpResponse); @@ -79,7 +94,7 @@ private static Collection parseProtobufMetrics(HttpResponse httpResponse collection.add( new Metric( - "COUNTER", + Metric.Type.COUNTER, help, name, toLabels(metric.getLabelList()), @@ -93,7 +108,7 @@ private static Collection parseProtobufMetrics(HttpResponse httpResponse collection.add( new Metric( - "GAUGE", + Metric.Type.GAUGE, help, name, toLabels(metric.getLabelList()), @@ -107,7 +122,7 @@ private static Collection parseProtobufMetrics(HttpResponse httpResponse collection.add( new Metric( - "UNTYPED", + Metric.Type.UNTYPED, help, name, toLabels(metric.getLabelList()), @@ -199,11 +214,11 @@ private static Metric createMetric(String typeLine, String help, String metricLi double value = Double.parseDouble(metricLine.substring(metricLine.lastIndexOf(" "))); if (typeLine.equalsIgnoreCase("COUNTER")) { - return new Metric("COUNTER", help, name, labels, value); + return new Metric(Metric.Type.COUNTER, help, name, labels, value); } else if (typeLine.equalsIgnoreCase("GAUGE")) { - return new Metric("GAUGE", help, name, labels, value); + return new Metric(Metric.Type.GAUGE, help, name, labels, value); } else { - return new Metric("UNTYPED", help, name, labels, value); + return new Metric(Metric.Type.UNTYPED, help, name, labels, value); } } @@ -258,7 +273,7 @@ private static TreeMap toLabels(List labelPai return labels; } - /** Class to read a Reader line by line */ + /** Class to read a Reader line by line with the ability to push a line back to the Reader */ private static class LineReader implements AutoCloseable { private final LinkedList lineBuffer; diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/throttle/ExponentialBackoffThrottle.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/throttle/ExponentialBackoffThrottle.java new file mode 100644 index 00000000..152e8d70 --- /dev/null +++ b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/throttle/ExponentialBackoffThrottle.java @@ -0,0 +1,53 @@ +package io.prometheus.jmx.test.support.throttle; + +/** Class to implement ExponentialBackupThrottle */ +@SuppressWarnings("PMD.EmptyCatchBlock") +public class ExponentialBackoffThrottle implements Throttle { + + private final long maximumMilliseconds; + private long throttleMilliseconds; + + /** + * Constructor + * + * @param minimumMilliseconds minimumMilliseconds + * @param maximumMilliseconds maximumMilliseconds + */ + public ExponentialBackoffThrottle(long minimumMilliseconds, long maximumMilliseconds) { + if (minimumMilliseconds < 1) { + throw new IllegalArgumentException( + "minimumMilliseconds [" + minimumMilliseconds + "] is less than 1"); + } + + if (maximumMilliseconds < 1) { + throw new IllegalArgumentException( + "maximumMilliseconds [" + maximumMilliseconds + "] is less than 1"); + } + + if (minimumMilliseconds > maximumMilliseconds) { + throw new IllegalArgumentException( + "minimumMilliseconds [" + + minimumMilliseconds + + "] is greater than maximumMilliseconds [" + + maximumMilliseconds + + "]"); + } + + this.throttleMilliseconds = minimumMilliseconds; + this.maximumMilliseconds = maximumMilliseconds; + } + + @Override + public void throttle() { + try { + Thread.sleep(throttleMilliseconds); + } catch (InterruptedException e) { + // DO NOTHING + } + + throttleMilliseconds = throttleMilliseconds * 2; + if (throttleMilliseconds > maximumMilliseconds) { + throttleMilliseconds = maximumMilliseconds; + } + } +} diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/throttle/Throttle.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/throttle/Throttle.java new file mode 100644 index 00000000..a0fce163 --- /dev/null +++ b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/throttle/Throttle.java @@ -0,0 +1,8 @@ +package io.prometheus.jmx.test.support.throttle; + +/** Interface to implement Throttle */ +public interface Throttle { + + /** Method to throttle the current thread */ + void throttle(); +} diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/AutoIncrementingMBeanTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/AutoIncrementingMBeanTest.java index 0e64df3b..ca6cd794 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/AutoIncrementingMBeanTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/AutoIncrementingMBeanTest.java @@ -19,54 +19,60 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static org.assertj.core.api.Assertions.assertThat; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; +import io.prometheus.jmx.test.support.http.HttpClient; import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import org.antublue.test.engine.api.TestEngine; +import org.antublue.verifyica.api.ArgumentContext; +import org.antublue.verifyica.api.Verifyica; import org.testcontainers.shaded.com.google.common.util.concurrent.AtomicDouble; -public class AutoIncrementingMBeanTest extends AbstractTest { +public class AutoIncrementingMBeanTest extends MinimalTest { - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } + @Verifyica.Test + @Verifyica.Order(order = Integer.MAX_VALUE) + public void testAutoIncrementingMBean(ArgumentContext argumentContext) { + HttpClient httpClient = + argumentContext + .getTestArgument(ExporterTestEnvironment.class) + .getPayload() + .getHttpClient(); - @TestEngine.Test - public void testMetrics() { - double value1 = collect(); - double value2 = collect(); - double value3 = collect(); + // Collect the auto incrementing MBean values + double value1 = collect(httpClient); + double value2 = collect(httpClient); + double value3 = collect(httpClient); + // Assert that each collection is the previous value + 1 assertThat(value2).isGreaterThan(value1); assertThat(value2).isEqualTo(value1 + 1); - assertThat(value3).isGreaterThan(value2); assertThat(value3).isEqualTo(value2 + 1); } - private double collect() { + /** + * Method to collect a value from the auto incrementing MBean + * + * @return the auto incrementing MBean value + */ + private double collect(HttpClient httpClient) { final AtomicDouble value = new AtomicDouble(); - HttpResponse httpResponse = - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()); + HttpResponse httpResponse = new HttpPrometheusMetricsRequest().send(httpClient); assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Collection metrics = MetricsParser.parseCollection(httpResponse); metrics.stream() .filter(metric -> metric.name().startsWith("io_prometheus_jmx_autoIncrementing")) .map(Metric::value) .limit(1) .findFirst() - .ifPresent(d -> value.set(d)); + .ifPresent(value::set); return value.doubleValue(); } diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/BlacklistObjectNamesTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/BlacklistObjectNamesTest.java index 0cf726f9..e19e161c 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/BlacklistObjectNamesTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/BlacklistObjectNamesTest.java @@ -19,55 +19,23 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static org.assertj.core.api.Assertions.assertThat; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Locale; +import java.util.function.BiConsumer; -public class BlacklistObjectNamesTest extends AbstractTest implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class BlacklistObjectNamesTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Collection metrics = MetricsParser.parseCollection(httpResponse); /* * Assert that we don't have any metrics that start with ... @@ -75,6 +43,8 @@ public void accept(HttpResponse httpResponse) { * name = java_lang* */ metrics.forEach( - metric -> assertThat(metric.name().toLowerCase()).doesNotStartWith("java_lang")); + metric -> + assertThat(metric.name().toLowerCase(Locale.ENGLISH)) + .doesNotStartWith("java_lang")); } } diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/CompositeKeyDataTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/CompositeKeyDataTest.java index 29489e13..72488ee1 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/CompositeKeyDataTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/CompositeKeyDataTest.java @@ -19,65 +19,32 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.function.BiConsumer; -public class CompositeKeyDataTest extends AbstractTest implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class CompositeKeyDataTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Collection metrics = MetricsParser.parseCollection(httpResponse); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("org_exist_management_exist_ProcessReport_RunningQueries_id") .withLabel("key_id", "1") .withLabel("key_path", "/db/query1.xq") .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("org_exist_management_exist_ProcessReport_RunningQueries_id") .withLabel("key_id", "2") .withLabel("key_path", "/db/query2.xq") diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/DisableAutoExcludeObjectNameAttributesTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/DisableAutoExcludeObjectNameAttributesTest.java index 3fec3610..83c98bd2 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/DisableAutoExcludeObjectNameAttributesTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/DisableAutoExcludeObjectNameAttributesTest.java @@ -19,58 +19,24 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static org.assertj.core.api.Assertions.fail; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; import java.util.HashSet; import java.util.Set; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.function.BiConsumer; -public class DisableAutoExcludeObjectNameAttributesTest extends AbstractTest - implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class DisableAutoExcludeObjectNameAttributesTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Collection metrics = MetricsParser.parseCollection(httpResponse); Set excludeAttributeNameSet = new HashSet<>(); excludeAttributeNameSet.add("_ClassPath"); diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/ExcludeObjectNameAttributesTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/ExcludeObjectNameAttributesTest.java index a1676ca6..a546339d 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/ExcludeObjectNameAttributesTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/ExcludeObjectNameAttributesTest.java @@ -19,58 +19,24 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static org.assertj.core.api.Assertions.fail; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; import java.util.HashSet; import java.util.Set; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.function.BiConsumer; -public class ExcludeObjectNameAttributesTest extends AbstractTest - implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class ExcludeObjectNameAttributesTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Collection metrics = MetricsParser.parseCollection(httpResponse); Set excludeAttributeNameSet = new HashSet<>(); excludeAttributeNameSet.add("_ClassPath"); diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/ExcludeObjectNamesTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/ExcludeObjectNamesTest.java index 43e49937..4c190bee 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/ExcludeObjectNamesTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/ExcludeObjectNamesTest.java @@ -19,55 +19,23 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static org.assertj.core.api.Assertions.assertThat; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Locale; +import java.util.function.BiConsumer; -public class ExcludeObjectNamesTest extends AbstractTest implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class ExcludeObjectNamesTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Collection metrics = MetricsParser.parseCollection(httpResponse); /* * Assert that we don't have any metrics that start with ... @@ -75,6 +43,8 @@ public void accept(HttpResponse httpResponse) { * name = java_lang* */ metrics.forEach( - metric -> assertThat(metric.name().toLowerCase()).doesNotStartWith("java_lang")); + metric -> + assertThat(metric.name().toLowerCase(Locale.ENGLISH)) + .doesNotStartWith("java_lang")); } } diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/IncludeAndExcludeObjectNamesTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/IncludeAndExcludeObjectNamesTest.java index 6954c962..4e7853cf 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/IncludeAndExcludeObjectNamesTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/IncludeAndExcludeObjectNamesTest.java @@ -19,56 +19,23 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static org.assertj.core.api.Assertions.assertThat; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Locale; +import java.util.function.BiConsumer; -public class IncludeAndExcludeObjectNamesTest extends AbstractTest - implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class IncludeAndExcludeObjectNamesTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Collection metrics = MetricsParser.parseCollection(httpResponse); /* * Assert that we don't have any metrics that start with ... @@ -76,6 +43,8 @@ public void accept(HttpResponse httpResponse) { * name = java_lang* */ metrics.forEach( - metric -> assertThat(metric.name().toLowerCase()).doesNotStartWith("java_lang")); + metric -> + assertThat(metric.name().toLowerCase(Locale.ENGLISH)) + .doesNotStartWith("java_lang")); } } diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/IncludeObjectNamesTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/IncludeObjectNamesTest.java index 11d86b7b..31bdd0f8 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/IncludeObjectNamesTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/IncludeObjectNamesTest.java @@ -19,55 +19,23 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static org.assertj.core.api.Assertions.assertThat; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Locale; +import java.util.function.BiConsumer; -public class IncludeObjectNamesTest extends AbstractTest implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class IncludeObjectNamesTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Collection metrics = MetricsParser.parseCollection(httpResponse); /* * We have to filter metrics that start with ... @@ -81,11 +49,19 @@ public void accept(HttpResponse httpResponse) { * ... because they are registered directly and are not MBeans */ metrics.stream() - .filter(metric -> !metric.name().toLowerCase().startsWith("jmx_exporter")) - .filter(metric -> !metric.name().toLowerCase().startsWith("jmx_config")) - .filter(metric -> !metric.name().toLowerCase().startsWith("jmx_scrape")) - .filter(metric -> !metric.name().toLowerCase().startsWith("jvm_")) - .filter(metric -> !metric.name().toLowerCase().startsWith("process_")) + .filter( + metric -> + !metric.name() + .toLowerCase(Locale.ENGLISH) + .startsWith("jmx_exporter")) + .filter( + metric -> + !metric.name().toLowerCase(Locale.ENGLISH).startsWith("jmx_config")) + .filter( + metric -> + !metric.name().toLowerCase(Locale.ENGLISH).startsWith("jmx_scrape")) + .filter(metric -> !metric.name().toLowerCase(Locale.ENGLISH).startsWith("jvm_")) + .filter(metric -> !metric.name().toLowerCase(Locale.ENGLISH).startsWith("process_")) .forEach( metric -> { String name = metric.name(); diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/LowerCaseOutputAndLabelNamesTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/LowerCaseOutputAndLabelNamesTest.java index 792bb34b..71f9b4ad 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/LowerCaseOutputAndLabelNamesTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/LowerCaseOutputAndLabelNamesTest.java @@ -19,65 +19,35 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static org.assertj.core.api.Assertions.assertThat; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Locale; +import java.util.function.BiConsumer; -public class LowerCaseOutputAndLabelNamesTest extends AbstractTest - implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class LowerCaseOutputAndLabelNamesTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Collection metrics = MetricsParser.parseCollection(httpResponse); /* * Assert that all metrics have lower case names and lower case label names */ metrics.forEach( metric -> { - assertThat(metric.name()).isEqualTo(metric.name().toLowerCase()); + assertThat(metric.name()).isEqualTo(metric.name().toLowerCase(Locale.ENGLISH)); metric.labels() - .forEach((key, value) -> assertThat(key).isEqualTo(key.toLowerCase())); + .forEach( + (key, value) -> + assertThat(key) + .isEqualTo(key.toLowerCase(Locale.ENGLISH))); }); } } diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/LowerCaseOutputLabelNamesTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/LowerCaseOutputLabelNamesTest.java index 71e02956..b638239f 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/LowerCaseOutputLabelNamesTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/LowerCaseOutputLabelNamesTest.java @@ -19,63 +19,34 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static org.assertj.core.api.Assertions.assertThat; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Locale; +import java.util.function.BiConsumer; -public class LowerCaseOutputLabelNamesTest extends AbstractTest implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class LowerCaseOutputLabelNamesTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Collection metrics = MetricsParser.parseCollection(httpResponse); /* * Assert that all metrics have lower case label names */ metrics.forEach( - metric -> { - metric.labels() - .forEach((key, value) -> assertThat(key).isEqualTo(key.toLowerCase())); - }); + metric -> + metric.labels() + .forEach( + (key, value) -> + assertThat(key) + .isEqualTo( + key.toLowerCase(Locale.ENGLISH)))); } } diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/LowerCaseOutputNamesTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/LowerCaseOutputNamesTest.java index 02ec86a5..d91a025b 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/LowerCaseOutputNamesTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/LowerCaseOutputNamesTest.java @@ -19,59 +19,30 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static org.assertj.core.api.Assertions.assertThat; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Locale; +import java.util.function.BiConsumer; -public class LowerCaseOutputNamesTest extends AbstractTest implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class LowerCaseOutputNamesTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Collection metrics = MetricsParser.parseCollection(httpResponse); /* * Assert that all metrics have lower case names */ - metrics.forEach(metric -> assertThat(metric.name()).isEqualTo(metric.name().toLowerCase())); + metrics.forEach( + metric -> + assertThat(metric.name()) + .isEqualTo(metric.name().toLowerCase(Locale.ENGLISH))); } } diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/MinimalTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/MinimalTest.java index c72a7391..2ca89243 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/MinimalTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/MinimalTest.java @@ -19,135 +19,106 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Map; +import java.util.function.BiConsumer; -public class MinimalTest extends AbstractTest implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class MinimalTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName( "io_prometheus_jmx_test_PerformanceMetricsMBean_PerformanceMetrics_ActiveSessions") .withValue(2.0d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName( "io_prometheus_jmx_test_PerformanceMetricsMBean_PerformanceMetrics_Bootstraps") .withValue(4.0d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName( "io_prometheus_jmx_test_PerformanceMetricsMBean_PerformanceMetrics_BootstrapsDeferred") .withValue(6.0d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/OptionalValueMBeanTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/OptionalValueMBeanTest.java index 7bbc53a5..8e75f5ae 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/OptionalValueMBeanTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/OptionalValueMBeanTest.java @@ -19,121 +19,92 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Map; +import java.util.function.BiConsumer; -public class OptionalValueMBeanTest extends AbstractTest implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class OptionalValueMBeanTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("io_prometheus_jmx_optionalValue_Value") .withValue(345d); } diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/WhitelistAndBlacklistObjectNamesTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/WhitelistAndBlacklistObjectNamesTest.java index ff0fca3a..f969ae45 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/WhitelistAndBlacklistObjectNamesTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/WhitelistAndBlacklistObjectNamesTest.java @@ -19,56 +19,23 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static org.assertj.core.api.Assertions.assertThat; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Locale; +import java.util.function.BiConsumer; -public class WhitelistAndBlacklistObjectNamesTest extends AbstractTest - implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class WhitelistAndBlacklistObjectNamesTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Collection metrics = MetricsParser.parseCollection(httpResponse); /* * Assert that we don't have any metrics that start with ... @@ -76,6 +43,8 @@ public void accept(HttpResponse httpResponse) { * name = java_lang* */ metrics.forEach( - metric -> assertThat(metric.name().toLowerCase()).doesNotStartWith("java_lang")); + metric -> + assertThat(metric.name().toLowerCase(Locale.ENGLISH)) + .doesNotStartWith("java_lang")); } } diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/WhitelistObjectNamesTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/WhitelistObjectNamesTest.java index f4a9dcae..261851c0 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/WhitelistObjectNamesTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/WhitelistObjectNamesTest.java @@ -19,55 +19,23 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static org.assertj.core.api.Assertions.assertThat; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Locale; +import java.util.function.BiConsumer; -public class WhitelistObjectNamesTest extends AbstractTest implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class WhitelistObjectNamesTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Collection metrics = MetricsParser.parseCollection(httpResponse); /* * We have to filter metrics that start with ... @@ -81,11 +49,19 @@ public void accept(HttpResponse httpResponse) { * ... because they are registered directly and are not MBeans */ metrics.stream() - .filter(metric -> !metric.name().toLowerCase().startsWith("jmx_exporter")) - .filter(metric -> !metric.name().toLowerCase().startsWith("jmx_config")) - .filter(metric -> !metric.name().toLowerCase().startsWith("jmx_scrape")) - .filter(metric -> !metric.name().toLowerCase().startsWith("jvm_")) - .filter(metric -> !metric.name().toLowerCase().startsWith("process_")) + .filter( + metric -> + !metric.name() + .toLowerCase(Locale.ENGLISH) + .startsWith("jmx_exporter")) + .filter( + metric -> + !metric.name().toLowerCase(Locale.ENGLISH).startsWith("jmx_config")) + .filter( + metric -> + !metric.name().toLowerCase(Locale.ENGLISH).startsWith("jmx_scrape")) + .filter(metric -> !metric.name().toLowerCase(Locale.ENGLISH).startsWith("jvm_")) + .filter(metric -> !metric.name().toLowerCase(Locale.ENGLISH).startsWith("process_")) .forEach( metric -> { String name = metric.name(); diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/AbstractExporterTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/AbstractExporterTest.java new file mode 100644 index 00000000..e4c47a52 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/AbstractExporterTest.java @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2023 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 + * + * http://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.common; + +import io.prometheus.jmx.test.support.JavaDockerImages; +import io.prometheus.jmx.test.support.JmxExporterMode; +import io.prometheus.jmx.test.support.http.HttpHealthyRequest; +import io.prometheus.jmx.test.support.http.HttpMetricsRequest; +import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; +import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; +import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; +import io.prometheus.jmx.test.support.http.HttpResponse; +import io.prometheus.jmx.test.support.http.HttpResponseAssertions; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Optional; +import java.util.function.BiConsumer; +import java.util.stream.Stream; +import org.antublue.verifyica.api.ArgumentContext; +import org.antublue.verifyica.api.ClassContext; +import org.antublue.verifyica.api.Verifyica; +import org.testcontainers.containers.Network; + +public abstract class AbstractExporterTest + implements BiConsumer { + + public static final String NETWORK = "network"; + + /** + * Method to get the Stream of test environments + * + * @return the Stream of test environments + */ + @Verifyica.ArgumentSupplier + public static Stream arguments() { + Collection collection = new ArrayList<>(); + + JavaDockerImages.names() + .forEach( + dockerImageName -> { + for (JmxExporterMode jmxExporterMode : JmxExporterMode.values()) { + collection.add( + new ExporterTestEnvironment( + dockerImageName, jmxExporterMode)); + } + }); + + return collection.stream(); + } + + @Verifyica.Prepare + public static void prepare(ClassContext classContext) { + // Create a Network and get the id to force the network creation + Network network = Network.newNetwork(); + network.getId(); + + classContext.getStore().put(NETWORK, network); + } + + @Verifyica.BeforeAll + public void beforeAll(ArgumentContext argumentContext) { + Network network = argumentContext.getClassContext().getStore().get(NETWORK, Network.class); + Class testClass = argumentContext.getClassContext().getTestClass(); + + argumentContext + .getTestArgument(ExporterTestEnvironment.class) + .getPayload() + .initialize(testClass, network); + } + + @Verifyica.Test + public void testHealthy(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); + + new HttpHealthyRequest() + .send(exporterTestEnvironment.getHttpClient()) + .accept(HttpResponseAssertions::assertHttpHealthyResponse); + } + + @Verifyica.Test + public void testMetrics(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); + + accept( + exporterTestEnvironment, + new HttpMetricsRequest().send(exporterTestEnvironment.getHttpClient())); + } + + @Verifyica.Test + public void testMetricsOpenMetricsFormat(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); + + accept( + exporterTestEnvironment, + new HttpOpenMetricsRequest().send(exporterTestEnvironment.getHttpClient())); + } + + @Verifyica.Test + public void testMetricsPrometheusFormat(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); + + accept( + exporterTestEnvironment, + new HttpPrometheusMetricsRequest().send(exporterTestEnvironment.getHttpClient())); + } + + @Verifyica.Test + public void testMetricsPrometheusProtobufFormat(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); + + accept( + exporterTestEnvironment, + new HttpPrometheusProtobufMetricsRequest() + .send(exporterTestEnvironment.getHttpClient())); + } + + @Verifyica.AfterAll + public void afterAll(ArgumentContext argumentContext) { + Optional.ofNullable(argumentContext.getTestArgument(ExporterTestEnvironment.class)) + .ifPresent( + exporterTestEnvironmentArgument -> + exporterTestEnvironmentArgument.getPayload().destroy()); + } + + @Verifyica.Conclude + public static void conclude(ClassContext classContext) { + Optional.ofNullable(classContext.getStore().remove(NETWORK, Network.class)) + .ifPresent(Network::close); + } + + @Override + public abstract void accept( + ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse); +} diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/AuthenticationCredentials.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/AuthenticationCredentials.java new file mode 100644 index 00000000..07311764 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/AuthenticationCredentials.java @@ -0,0 +1,61 @@ +package io.prometheus.jmx.test.common; + +/** Class to implement AuthenticationTestCredentials */ +public class AuthenticationCredentials { + + private String username; + private String password; + private boolean isValid; + + /** + * Constructor + * + * @param username + * @param password + * @param isValid + */ + private AuthenticationCredentials(String username, String password, boolean isValid) { + this.username = username; + this.password = password; + this.isValid = isValid; + } + + /** + * Method to get the username + * + * @return the username + */ + public String getUsername() { + return username; + } + + /** + * Method to get the password + * + * @return the password + */ + public String getPassword() { + return password; + } + + /** + * Method to return if the credentials are valid + * + * @return true if the credentials are valid, else false + */ + public boolean isValid() { + return isValid; + } + + /** + * Method to create an AuthenticationTestCredentials + * + * @param username username + * @param password password + * @param isValid isValid + * @return an AuthenticationTestCredentials + */ + public static AuthenticationCredentials of(String username, String password, boolean isValid) { + return new AuthenticationCredentials(username, password, isValid); + } +} diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/AbstractTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/ExporterTestEnvironment.java similarity index 52% rename from integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/AbstractTest.java rename to integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/ExporterTestEnvironment.java index 92c5413e..1a5e6c73 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/AbstractTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/ExporterTestEnvironment.java @@ -1,152 +1,159 @@ -/* - * Copyright (C) 2023 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 - * - * http://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; +package io.prometheus.jmx.test.common; import com.github.dockerjava.api.model.Ulimit; -import io.prometheus.jmx.test.support.DockerImageNames; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.TestArguments; -import io.prometheus.jmx.test.support.TestEnvironment; import io.prometheus.jmx.test.support.http.HttpClient; import java.time.Duration; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Stream; -import org.antublue.test.engine.api.TestEngine; +import org.antublue.verifyica.api.Argument; import org.testcontainers.containers.BindMode; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.startupcheck.IsRunningStartupCheckStrategy; import org.testcontainers.containers.wait.strategy.Wait; -public abstract class AbstractTest { +/** Class to implement OpenTelemetryTestEnvironment */ +public class ExporterTestEnvironment implements Argument { - private static final String BASE_URL = "http://localhost"; - private static final long MEMORY_BYTES = 1073741824; // 1GB + private static final long MEMORY_BYTES = 1073741824; // 1 GB private static final long MEMORY_SWAP_BYTES = 2 * MEMORY_BYTES; + private static final String BASE_URL = "http://localhost"; - @TestEngine.Argument public TestArguments testArguments; + private final String javaDockerImage; + private final JmxExporterMode jmxExporterMode; - protected TestEnvironment testEnvironment; + private Class testClass; + private String baseUrl; + private Network network; + private GenericContainer standaloneApplicationContainer; + private GenericContainer javaAgentApplicationContainer; + private GenericContainer standaloneExporterContainer; + private HttpClient httpClient; /** - * Method to get the list of TestArguments + * Constructor * - * @return the return value + * @param javaDockerImage javaDockerImage + * @param jmxExporterMode jmxExporterMode */ - @TestEngine.ArgumentSupplier - public static Stream arguments() { - List testArguments = new ArrayList<>(); + public ExporterTestEnvironment(String javaDockerImage, JmxExporterMode jmxExporterMode) { + this.javaDockerImage = javaDockerImage; + this.jmxExporterMode = jmxExporterMode; + this.baseUrl = BASE_URL; + } - DockerImageNames.names() - .forEach( - dockerImageName -> { - for (JmxExporterMode jmxExporterMode : JmxExporterMode.values()) { - testArguments.add( - TestArguments.of( - dockerImageName + " / " + jmxExporterMode, - dockerImageName, - jmxExporterMode)); - } - }); + @Override + public String getName() { + return javaDockerImage + " / " + jmxExporterMode; + } - return testArguments.stream(); + @Override + public ExporterTestEnvironment getPayload() { + return this; } - @TestEngine.Prepare - public final void prepare() { - // Get the Network and get the id to force the network creation - Network network = Network.newNetwork(); - network.getId(); + /** + * Method to set the base URL + * + * @param baseUrl baseUrl + * @return the ExporterTestEnvironment + */ + public ExporterTestEnvironment setBaseUrl(String baseUrl) { + this.baseUrl = baseUrl; + return this; + } - testEnvironment = new TestEnvironment(); - testEnvironment.setNetwork(network); - testEnvironment.setBaseUrl(BASE_URL); + /** + * Method to get the Java Docker image name + * + * @return the Java Docker image name + */ + public String getJavaDockerImage() { + return javaDockerImage; } - @TestEngine.BeforeAll - public final void beforeAll() { - testEnvironment.reset(); + /** + * Method to get the JMX Exporter mode + * + * @return the JMX Exporter mode + */ + public JmxExporterMode getJmxExporterMode() { + return jmxExporterMode; + } - Network network = testEnvironment.getNetwork(); - String dockerImageName = testArguments.getDockerImageName(); - String testName = this.getClass().getName(); - String baseUrl = testEnvironment.getBaseUrl(); + /** + * Method to initialize the test environment + * + * @param network network + */ + public void initialize(Class testClass, Network network) { + this.testClass = testClass; + this.network = network; - switch (testArguments.getJmxExporterMode()) { + switch (jmxExporterMode) { case JavaAgent: { - GenericContainer applicationContainer = - createJavaAgentApplicationContainer(network, dockerImageName, testName); - applicationContainer.start(); - testEnvironment.setApplicationContainer(applicationContainer); + javaAgentApplicationContainer = createJavaAgentApplicationContainer(); + javaAgentApplicationContainer.start(); - HttpClient httpClient = createHttpClient(applicationContainer, baseUrl); - testEnvironment.setHttpClient(httpClient); + httpClient = createHttpClient(javaAgentApplicationContainer, baseUrl, 8888); break; } case Standalone: { - GenericContainer applicationContainer = - createStandaloneApplicationContainer( - network, dockerImageName, testName); - applicationContainer.start(); - testEnvironment.setApplicationContainer(applicationContainer); + standaloneApplicationContainer = createStandaloneApplicationContainer(); + standaloneApplicationContainer.start(); - GenericContainer exporterContainer = - createStandaloneExporterContainer(network, dockerImageName, testName); - exporterContainer.start(); - testEnvironment.setExporterContainer(exporterContainer); + standaloneExporterContainer = createStandaloneExporterContainer(); + standaloneExporterContainer.start(); - HttpClient httpClient = createHttpClient(exporterContainer, baseUrl); - testEnvironment.setHttpClient(httpClient); + httpClient = createHttpClient(standaloneExporterContainer, baseUrl, 8888); break; } } } - @TestEngine.AfterAll - public final void afterAll() { - testEnvironment.reset(); + /** + * Method to get an HttpClient for the test environment + * + * @return an HttpClient + */ + public HttpClient getHttpClient() { + return httpClient; } - @TestEngine.Conclude - public final void conclude() { - testEnvironment.destroy(); - testEnvironment = null; + /** Method to destroy the test environment */ + public void destroy() { + if (javaAgentApplicationContainer != null) { + javaAgentApplicationContainer.close(); + javaAgentApplicationContainer = null; + } + + if (standaloneExporterContainer != null) { + standaloneExporterContainer.close(); + standaloneExporterContainer = null; + } + + if (standaloneApplicationContainer != null) { + standaloneApplicationContainer.close(); + standaloneApplicationContainer = null; + } } /** * Method to create an application container * - * @param network network - * @param dockerImageName dockerImageName - * @param testName testName * @return the return value */ - private static GenericContainer createStandaloneApplicationContainer( - Network network, String dockerImageName, String testName) { - return new GenericContainer<>(dockerImageName) + private GenericContainer createJavaAgentApplicationContainer() { + return new GenericContainer<>(javaDockerImage) .waitingFor(Wait.forLogMessage(".*Running.*", 1)) .withClasspathResourceMapping("common", "/temp", BindMode.READ_ONLY) .withClasspathResourceMapping( - testName.replace(".", "/") + "/Standalone", "/temp", BindMode.READ_ONLY) + testClass.getName().replace(".", "/") + "/JavaAgent", + "/temp", + BindMode.READ_ONLY) .withCreateContainerCmdModifier( c -> c.getHostConfig() @@ -160,7 +167,7 @@ private static GenericContainer createStandaloneApplicationContainer( new Ulimit("nofile", 65536L, 65536L) })) .withCommand("/bin/sh application.sh") - .withExposedPorts(9999) + .withExposedPorts(8888) .withLogConsumer( outputFrame -> { String string = outputFrame.getUtf8StringWithoutLineEnding().trim(); @@ -176,20 +183,18 @@ private static GenericContainer createStandaloneApplicationContainer( } /** - * Method to create an exporter container + * Method to create an application container * - * @param network network - * @param dockerImageName dockerImageName - * @param testName testName * @return the return value */ - private static GenericContainer createStandaloneExporterContainer( - Network network, String dockerImageName, String testName) { - return new GenericContainer<>(dockerImageName) - .waitingFor(Wait.forListeningPort()) + private GenericContainer createStandaloneApplicationContainer() { + return new GenericContainer<>(javaDockerImage) + .waitingFor(Wait.forLogMessage(".*Running.*", 1)) .withClasspathResourceMapping("common", "/temp", BindMode.READ_ONLY) .withClasspathResourceMapping( - testName.replace(".", "/") + "/Standalone", "/temp", BindMode.READ_ONLY) + testClass.getName().replace(".", "/") + "/Standalone", + "/temp", + BindMode.READ_ONLY) .withCreateContainerCmdModifier( c -> c.getHostConfig() @@ -202,8 +207,8 @@ private static GenericContainer createStandaloneExporterContainer( new Ulimit[] { new Ulimit("nofile", 65536L, 65536L) })) - .withCommand("/bin/sh exporter.sh") - .withExposedPorts(8888) + .withCommand("/bin/sh application.sh") + .withExposedPorts(9999) .withLogConsumer( outputFrame -> { String string = outputFrame.getUtf8StringWithoutLineEnding().trim(); @@ -212,27 +217,26 @@ private static GenericContainer createStandaloneExporterContainer( } }) .withNetwork(network) - .withNetworkAliases("exporter") + .withNetworkAliases("application") .withStartupCheckStrategy(new IsRunningStartupCheckStrategy()) .withStartupTimeout(Duration.ofMillis(30000)) - .withWorkingDirectory("/temp"); + .withWorkingDirectory("/temp") + .waitingFor(Wait.forLogMessage(".*Running.*", 1)); } /** - * Method to create an application container + * Method to create an exporter container * - * @param network network - * @param dockerImageName dockerImageName - * @param testName testName * @return the return value */ - private static GenericContainer createJavaAgentApplicationContainer( - Network network, String dockerImageName, String testName) { - return new GenericContainer<>(dockerImageName) - .waitingFor(Wait.forLogMessage(".*Running.*", 1)) + private GenericContainer createStandaloneExporterContainer() { + return new GenericContainer<>(javaDockerImage) + .waitingFor(Wait.forListeningPort()) .withClasspathResourceMapping("common", "/temp", BindMode.READ_ONLY) .withClasspathResourceMapping( - testName.replace(".", "/") + "/JavaAgent", "/temp", BindMode.READ_ONLY) + testClass.getName().replace(".", "/") + "/Standalone", + "/temp", + BindMode.READ_ONLY) .withCreateContainerCmdModifier( c -> c.getHostConfig() @@ -245,7 +249,7 @@ private static GenericContainer createJavaAgentApplicationContainer( new Ulimit[] { new Ulimit("nofile", 65536L, 65536L) })) - .withCommand("/bin/sh application.sh") + .withCommand("/bin/sh exporter.sh") .withExposedPorts(8888) .withLogConsumer( outputFrame -> { @@ -255,21 +259,22 @@ private static GenericContainer createJavaAgentApplicationContainer( } }) .withNetwork(network) - .withNetworkAliases("application") + .withNetworkAliases("exporter") .withStartupCheckStrategy(new IsRunningStartupCheckStrategy()) .withStartupTimeout(Duration.ofMillis(30000)) - .withWorkingDirectory("/temp"); + .withWorkingDirectory("/temp") + .waitingFor(Wait.forLogMessage(".*Running.*", 1)); } /** - * Method to create an HttpClient + * Method to create a Prometheus HttpClient * * @param genericContainer genericContainer * @param baseUrl baseUrl * @return the return value */ private static HttpClient createHttpClient( - GenericContainer genericContainer, String baseUrl) { - return new HttpClient(baseUrl + ":" + genericContainer.getMappedPort(8888)); + GenericContainer genericContainer, String baseUrl, int mappedPort) { + return new HttpClient(baseUrl + ":" + genericContainer.getMappedPort(mappedPort)); } } diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/PBKDF2WithHmacExporterTestEnvironmentFilter.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/PBKDF2WithHmacExporterTestEnvironmentFilter.java new file mode 100644 index 00000000..9d21a172 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/PBKDF2WithHmacExporterTestEnvironmentFilter.java @@ -0,0 +1,33 @@ +package io.prometheus.jmx.test.common; + +import java.util.HashSet; +import java.util.Set; +import java.util.function.Predicate; + +/** Class to implement PBKDF2WithHmacTestArgumentFilter */ +public class PBKDF2WithHmacExporterTestEnvironmentFilter + implements Predicate { + + private final Set filteredDockerImages; + + /** Constructor */ + public PBKDF2WithHmacExporterTestEnvironmentFilter() { + // Filter out Docker image names that don't support PBKDF2 with HMAC + filteredDockerImages = new HashSet<>(); + filteredDockerImages.add("ibmjava:8"); + filteredDockerImages.add("ibmjava:8-jre"); + filteredDockerImages.add("ibmjava:8-sdk"); + filteredDockerImages.add("ibmjava:8-sfj"); + } + + /** + * Evaluates this predicate on the given argument. + * + * @param ExporterTestEnvironment the input argument + * @return {@code true} if the input argument matches the predicate, otherwise {@code false} + */ + @Override + public boolean test(ExporterTestEnvironment ExporterTestEnvironment) { + return !filteredDockerImages.contains(ExporterTestEnvironment.getJavaDockerImage()); + } +} diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/PKCS12KeyStoreExporterTestEnvironmentFilter.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/PKCS12KeyStoreExporterTestEnvironmentFilter.java new file mode 100644 index 00000000..a3d3ec74 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/common/PKCS12KeyStoreExporterTestEnvironmentFilter.java @@ -0,0 +1,35 @@ +package io.prometheus.jmx.test.common; + +import java.util.HashSet; +import java.util.Set; +import java.util.function.Predicate; + +/** Class to implement PKCS12KeyStoreExporterContextFilter */ +public class PKCS12KeyStoreExporterTestEnvironmentFilter + implements Predicate { + + private final Set filteredDockerImages; + + /** Constructor */ + public PKCS12KeyStoreExporterTestEnvironmentFilter() { + filteredDockerImages = new HashSet<>(); + filteredDockerImages.add("eclipse-temurin:8-alpine"); + filteredDockerImages.add("ghcr.io/graalvm/jdk:java8"); + filteredDockerImages.add("ibmjava:8"); + filteredDockerImages.add("ibmjava:8-jre"); + filteredDockerImages.add("ibmjava:8-sdk"); + filteredDockerImages.add("ibmjava:8-sfj"); + filteredDockerImages.add("ibmjava:11"); + } + + /** + * Evaluates this predicate on the given argument. + * + * @param ExporterTestEnvironment the input argument + * @return {@code true} if the input argument matches the predicate, otherwise {@code false} + */ + @Override + public boolean test(ExporterTestEnvironment ExporterTestEnvironment) { + return !filteredDockerImages.contains(ExporterTestEnvironment.getJavaDockerImage()); + } +} diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/CompleteHttpServerConfigurationTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/CompleteHttpServerConfigurationTest.java index 0e7e97d6..9df845f6 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/CompleteHttpServerConfigurationTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/CompleteHttpServerConfigurationTest.java @@ -20,9 +20,9 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpResponseCode; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; -import io.prometheus.jmx.test.AbstractTest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.TestArguments; import io.prometheus.jmx.test.support.http.HttpBasicAuthenticationCredentials; import io.prometheus.jmx.test.support.http.HttpHealthyRequest; import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; @@ -32,15 +32,18 @@ import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; +import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; +import java.util.function.BiConsumer; +import java.util.function.Function; import java.util.stream.Stream; -import org.antublue.test.engine.api.TestEngine; +import org.antublue.verifyica.api.ArgumentContext; +import org.antublue.verifyica.api.Verifyica; -public class CompleteHttpServerConfigurationTest extends AbstractTest - implements Consumer { +public class CompleteHttpServerConfigurationTest extends AbstractExporterTest + implements BiConsumer { - private final String BASE_URL = "https://localhost"; + private static final String BASE_URL = "https://localhost"; private final String VALID_USERNAME = "Prometheus"; @@ -53,30 +56,36 @@ public class CompleteHttpServerConfigurationTest extends AbstractTest new String[] {VALID_PASSWORD, "Secret", "bad", "", null}; /** - * Method to get the list of TestArguments + * Method to get the Stream of test environments * - * @return the return value + * @return the Stream of test environments */ - @TestEngine.ArgumentSupplier - public static Stream arguments() { + @Verifyica.ArgumentSupplier + public static Stream arguments() { // Filter eclipse-temurin:8 based Alpine images due to missing TLS cipher suites // https://github.com/adoptium/temurin-build/issues/3002 // https://bugs.openjdk.org/browse/JDK-8306037 - return AbstractTest.arguments() + return AbstractExporterTest.arguments() .filter( - testArgument -> - !testArgument - .getDockerImageName() - .contains("eclipse-temurin:8-alpine")); + exporterTestEnvironment -> + !exporterTestEnvironment + .getJavaDockerImage() + .contains("eclipse-temurin:8-alpine")) + .map( + new Function() { + @Override + public ExporterTestEnvironment apply( + ExporterTestEnvironment ExporterTestEnvironment) { + return ExporterTestEnvironment.setBaseUrl(BASE_URL); + } + }); } - @TestEngine.Prepare - public void setBaseUrl() { - testEnvironment.setBaseUrl(BASE_URL); - } + @Verifyica.Test + public void testHealthy(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); - @TestEngine.Test - public void testHealthy() { for (String username : TEST_USERNAMES) { for (String password : TEST_PASSWORDS) { final AtomicInteger code = new AtomicInteger(HttpResponse.UNAUTHORIZED); @@ -87,14 +96,17 @@ public void testHealthy() { new HttpHealthyRequest() .credentials(new HttpBasicAuthenticationCredentials(username, password)) - .send(testEnvironment.getHttpClient()) + .send(exporterTestEnvironment.getHttpClient()) .accept(response -> assertHttpResponseCode(response, code.get())); } } } - @TestEngine.Test - public void testMetrics() { + @Verifyica.Test + public void testMetrics(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); + for (String username : TEST_USERNAMES) { for (String password : TEST_PASSWORDS) { final AtomicInteger code = new AtomicInteger(HttpResponse.UNAUTHORIZED); @@ -105,20 +117,23 @@ public void testMetrics() { new HttpPrometheusMetricsRequest() .credentials(new HttpBasicAuthenticationCredentials(username, password)) - .send(testEnvironment.getHttpClient()) + .send(exporterTestEnvironment.getHttpClient()) .accept( response -> { assertHttpResponseCode(response, code.get()); - if (response.code() == HttpResponse.OK) { - accept(response); + if (response.statusCode() == HttpResponse.OK) { + accept(exporterTestEnvironment, response); } }); } } } - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { + @Verifyica.Test + public void testMetricsOpenMetricsFormat(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); + for (String username : TEST_USERNAMES) { for (String password : TEST_PASSWORDS) { final AtomicInteger code = new AtomicInteger(HttpResponse.UNAUTHORIZED); @@ -129,20 +144,23 @@ public void testMetricsOpenMetricsFormat() { new HttpOpenMetricsRequest() .credentials(new HttpBasicAuthenticationCredentials(username, password)) - .send(testEnvironment.getHttpClient()) + .send(exporterTestEnvironment.getHttpClient()) .accept( response -> { assertHttpResponseCode(response, code.get()); - if (response.code() == HttpResponse.OK) { - accept(response); + if (response.statusCode() == HttpResponse.OK) { + accept(exporterTestEnvironment, response); } }); } } } - @TestEngine.Test - public void testMetricsPrometheusFormat() { + @Verifyica.Test + public void testMetricsPrometheusFormat(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); + for (String username : TEST_USERNAMES) { for (String password : TEST_PASSWORDS) { final AtomicInteger code = new AtomicInteger(HttpResponse.UNAUTHORIZED); @@ -153,20 +171,23 @@ public void testMetricsPrometheusFormat() { new HttpPrometheusMetricsRequest() .credentials(new HttpBasicAuthenticationCredentials(username, password)) - .send(testEnvironment.getHttpClient()) + .send(exporterTestEnvironment.getHttpClient()) .accept( response -> { assertHttpResponseCode(response, code.get()); - if (response.code() == HttpResponse.OK) { - accept(response); + if (response.statusCode() == HttpResponse.OK) { + accept(exporterTestEnvironment, response); } }); } } } - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { + @Verifyica.Test + public void testMetricsPrometheusProtobufFormat(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); + for (String username : TEST_USERNAMES) { for (String password : TEST_PASSWORDS) { final AtomicInteger code = new AtomicInteger(HttpResponse.UNAUTHORIZED); @@ -177,12 +198,12 @@ public void testMetricsPrometheusProtobufFormat() { new HttpPrometheusProtobufMetricsRequest() .credentials(new HttpBasicAuthenticationCredentials(username, password)) - .send(testEnvironment.getHttpClient()) + .send(exporterTestEnvironment.getHttpClient()) .accept( response -> { assertHttpResponseCode(response, code.get()); - if (response.code() == HttpResponse.OK) { - accept(response); + if (response.statusCode() == HttpResponse.OK) { + accept(exporterTestEnvironment, response); } }); } @@ -190,68 +211,71 @@ public void testMetricsPrometheusProtobufFormat() { } @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/AbstractBasicAuthenticationTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/AbstractBasicAuthenticationTest.java index cf104916..8b6dd2d0 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/AbstractBasicAuthenticationTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/AbstractBasicAuthenticationTest.java @@ -16,15 +16,25 @@ package io.prometheus.jmx.test.http.authentication; -import io.prometheus.jmx.test.AbstractTest; -import io.prometheus.jmx.test.support.TestArguments; +import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpResponseCode; + +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.AuthenticationCredentials; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; +import io.prometheus.jmx.test.support.http.HttpBasicAuthenticationCredentials; +import io.prometheus.jmx.test.support.http.HttpHealthyRequest; +import io.prometheus.jmx.test.support.http.HttpMetricsRequest; +import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; +import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; +import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; +import io.prometheus.jmx.test.support.http.HttpResponse; import java.util.ArrayList; import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import java.util.function.Predicate; +import java.util.concurrent.atomic.AtomicInteger; +import org.antublue.verifyica.api.ArgumentContext; +import org.antublue.verifyica.api.Verifyica; -public abstract class AbstractBasicAuthenticationTest extends AbstractTest { +public abstract class AbstractBasicAuthenticationTest extends AbstractExporterTest { protected static final String VALID_USERNAME = "Prometheus"; @@ -35,112 +45,162 @@ public abstract class AbstractBasicAuthenticationTest extends AbstractTest { protected static final String[] INVALID_PASSWORDS = new String[] {"Secret", "bad", "", null}; - protected static final PBKDF2WithHmacTestArgumentFilter PBKDF2_WITH_MAC_TEST_ARGUMENT_FILTER = - new PBKDF2WithHmacTestArgumentFilter(); - - /** Class to implement a PBKDF2WithHmacTestArgumentFilter */ - protected static class PBKDF2WithHmacTestArgumentFilter implements Predicate { - - private final Set filteredDockerImages; - - /** Constructor */ - public PBKDF2WithHmacTestArgumentFilter() { - // Filter out Docker image names that don't support PBKDF2 with HMAC - filteredDockerImages = new HashSet<>(); - filteredDockerImages.add("ibmjava:8"); - filteredDockerImages.add("ibmjava:8-jre"); - filteredDockerImages.add("ibmjava:8-sdk"); - filteredDockerImages.add("ibmjava:8-sfj"); - } - - /** - * Evaluates this predicate on the given argument. - * - * @param testArguments the input argument - * @return {@code true} if the input argument matches the predicate, otherwise {@code false} - */ - @Override - public boolean test(TestArguments testArguments) { - return !filteredDockerImages.contains(testArguments.getDockerImageName()); - } - } - /** - * Method to create a Collection of AuthenticationTestCredentials + * Method to create a Collection of AuthenticationCredentials * - * @return a Collection of AuthenticationTestCredentials + * @return a Collection of AuthenticationCredentials */ - public static Collection getAuthenticationTestCredentials() { - Collection collection = new ArrayList<>(); - collection.add(AuthenticationTestCredentials.of(VALID_USERNAME, VALID_PASSWORD, true)); + public static Collection getAuthenticationCredentials() { + Collection collection = new ArrayList<>(); + collection.add(AuthenticationCredentials.of(VALID_USERNAME, VALID_PASSWORD, true)); for (String username : INVALID_USERNAMES) { for (String password : INVALID_PASSWORDS) { - collection.add(AuthenticationTestCredentials.of(username, password, false)); + collection.add(AuthenticationCredentials.of(username, password, false)); } } return collection; } - /** Class to implement AuthenticationTestCredentials */ - public static class AuthenticationTestCredentials { - - private String username; - private String password; - private boolean isValid; - - /** - * Constructor - * - * @param username - * @param password - * @param isValid - */ - private AuthenticationTestCredentials(String username, String password, boolean isValid) { - this.username = username; - this.password = password; - this.isValid = isValid; - } + @Verifyica.Test + public void testHealthy(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); + + getAuthenticationCredentials() + .forEach( + authenticationTestArguments -> { + final AtomicInteger code = + new AtomicInteger( + authenticationTestArguments.isValid() + ? HttpResponse.OK + : HttpResponse.UNAUTHORIZED); + new HttpHealthyRequest() + .credentials( + new HttpBasicAuthenticationCredentials( + authenticationTestArguments.getUsername(), + authenticationTestArguments.getPassword())) + .send(exporterTestEnvironment.getHttpClient()) + .accept( + response -> + assertHttpResponseCode(response, code.get())); + }); + } - /** - * Method to get the username - * - * @return the username - */ - public String getUsername() { - return username; - } + @Verifyica.Test + public void testMetrics(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); + + getAuthenticationCredentials() + .forEach( + authenticationCredentials -> { + final AtomicInteger code = + new AtomicInteger( + authenticationCredentials.isValid() + ? HttpResponse.OK + : HttpResponse.UNAUTHORIZED); + new HttpMetricsRequest() + .credentials( + new HttpBasicAuthenticationCredentials( + authenticationCredentials.getUsername(), + authenticationCredentials.getPassword())) + .send(exporterTestEnvironment.getHttpClient()) + .accept( + response -> { + assertHttpResponseCode(response, code.get()); + if (code.get() == HttpResponse.OK) { + accept(exporterTestEnvironment, response); + } + }); + }); + } - /** - * Method to get the password - * - * @return the password - */ - public String getPassword() { - return password; - } + @Verifyica.Test + public void testMetricsOpenMetricsFormat(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); + + getAuthenticationCredentials() + .forEach( + authenticationCredentials -> { + final AtomicInteger code = + new AtomicInteger( + authenticationCredentials.isValid() + ? HttpResponse.OK + : HttpResponse.UNAUTHORIZED); + new HttpOpenMetricsRequest() + .credentials( + new HttpBasicAuthenticationCredentials( + authenticationCredentials.getUsername(), + authenticationCredentials.getPassword())) + .send(exporterTestEnvironment.getHttpClient()) + .accept( + response -> { + assertHttpResponseCode(response, code.get()); + if (code.get() == HttpResponse.OK) { + accept(exporterTestEnvironment, response); + } + }); + }); + } - /** - * Method to return if the credentials are valid - * - * @return true if the credentials are valid, else false - */ - public boolean isValid() { - return isValid; - } + @Verifyica.Test + public void testMetricsPrometheusFormat(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); + + getAuthenticationCredentials() + .forEach( + authenticationCredentials -> { + final AtomicInteger code = + new AtomicInteger( + authenticationCredentials.isValid() + ? HttpResponse.OK + : HttpResponse.UNAUTHORIZED); + new HttpPrometheusMetricsRequest() + .credentials( + new HttpBasicAuthenticationCredentials( + authenticationCredentials.getUsername(), + authenticationCredentials.getPassword())) + .send(exporterTestEnvironment.getHttpClient()) + .accept( + response -> { + assertHttpResponseCode(response, code.get()); + if (code.get() == HttpResponse.OK) { + accept(exporterTestEnvironment, response); + } + }); + }); + } - /** - * Method to create an AuthenticationTestCredentials - * - * @param username username - * @param password password - * @param isValid isValid - * @return an AuthenticationTestCredentials - */ - public static AuthenticationTestCredentials of( - String username, String password, boolean isValid) { - return new AuthenticationTestCredentials(username, password, isValid); - } + @Verifyica.Test + public void testMetricsPrometheusProtobufFormat(ArgumentContext argumentContext) { + ExporterTestEnvironment exporterTestEnvironment = + argumentContext.getTestArgument(ExporterTestEnvironment.class).getPayload(); + + getAuthenticationCredentials() + .forEach( + authenticationCredentials -> { + final AtomicInteger code = + new AtomicInteger( + authenticationCredentials.isValid() + ? HttpResponse.OK + : HttpResponse.UNAUTHORIZED); + new HttpPrometheusProtobufMetricsRequest() + .credentials( + new HttpBasicAuthenticationCredentials( + authenticationCredentials.getUsername(), + authenticationCredentials.getPassword())) + .send(exporterTestEnvironment.getHttpClient()) + .accept( + response -> { + assertHttpResponseCode(response, code.get()); + if (code.get() == HttpResponse.OK) { + accept(exporterTestEnvironment, response); + } + }); + }); } } diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA1Test.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA1Test.java index 895b753e..d842918b 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA1Test.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA1Test.java @@ -17,229 +17,100 @@ package io.prometheus.jmx.test.http.authentication; import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; -import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpResponseCode; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; +import io.prometheus.jmx.test.common.PBKDF2WithHmacExporterTestEnvironmentFilter; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.TestArguments; -import io.prometheus.jmx.test.support.http.HttpBasicAuthenticationCredentials; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; +import java.util.Map; +import java.util.function.BiConsumer; import java.util.stream.Stream; -import org.antublue.test.engine.api.TestEngine; +import org.antublue.verifyica.api.Verifyica; public class BasicAuthenticationPBKDF2WithHmacSHA1Test extends AbstractBasicAuthenticationTest - implements Consumer { + implements BiConsumer { /** - * Method to get the list of TestArguments + * Method to get the Stream of test environments * - * @return the return value + * @return the Stream of test environments */ - @TestEngine.ArgumentSupplier - public static Stream arguments() { + @Verifyica.ArgumentSupplier + public static Stream arguments() { return AbstractBasicAuthenticationTest.arguments() - .filter(PBKDF2_WITH_MAC_TEST_ARGUMENT_FILTER); - } - - @TestEngine.Test - public void testHealthy() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpHealthyRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> - assertHttpResponseCode(response, code.get())); - }); - } - - @TestEngine.Test - public void testMetrics() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpOpenMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusProtobufMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); + .filter(new PBKDF2WithHmacExporterTestEnvironmentFilter()); } @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA256Test.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA256Test.java index 251f1cb5..bfc9c0b7 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA256Test.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA256Test.java @@ -17,229 +17,100 @@ package io.prometheus.jmx.test.http.authentication; import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; -import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpResponseCode; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; +import io.prometheus.jmx.test.common.PBKDF2WithHmacExporterTestEnvironmentFilter; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.TestArguments; -import io.prometheus.jmx.test.support.http.HttpBasicAuthenticationCredentials; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; +import java.util.Map; +import java.util.function.BiConsumer; import java.util.stream.Stream; -import org.antublue.test.engine.api.TestEngine; +import org.antublue.verifyica.api.Verifyica; public class BasicAuthenticationPBKDF2WithHmacSHA256Test extends AbstractBasicAuthenticationTest - implements Consumer { + implements BiConsumer { /** - * Method to get the list of TestArguments + * Method to get the Stream of test environments * - * @return the return value + * @return the Stream of test environments */ - @TestEngine.ArgumentSupplier - public static Stream arguments() { + @Verifyica.ArgumentSupplier + public static Stream arguments() { return AbstractBasicAuthenticationTest.arguments() - .filter(PBKDF2_WITH_MAC_TEST_ARGUMENT_FILTER); - } - - @TestEngine.Test - public void testHealthy() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpHealthyRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> - assertHttpResponseCode(response, code.get())); - }); - } - - @TestEngine.Test - public void testMetrics() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpOpenMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusProtobufMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); + .filter(new PBKDF2WithHmacExporterTestEnvironmentFilter()); } @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA512Test.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA512Test.java index 6143166d..d834d3a3 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA512Test.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA512Test.java @@ -17,229 +17,100 @@ package io.prometheus.jmx.test.http.authentication; import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; -import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpResponseCode; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; +import io.prometheus.jmx.test.common.PBKDF2WithHmacExporterTestEnvironmentFilter; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.TestArguments; -import io.prometheus.jmx.test.support.http.HttpBasicAuthenticationCredentials; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; +import java.util.Map; +import java.util.function.BiConsumer; import java.util.stream.Stream; -import org.antublue.test.engine.api.TestEngine; +import org.antublue.verifyica.api.Verifyica; public class BasicAuthenticationPBKDF2WithHmacSHA512Test extends AbstractBasicAuthenticationTest - implements Consumer { + implements BiConsumer { /** - * Method to get the list of TestArguments + * Method to get the Stream of test environments * - * @return the return value + * @return the Stream of test environments */ - @TestEngine.ArgumentSupplier - public static Stream arguments() { + @Verifyica.ArgumentSupplier + public static Stream arguments() { return AbstractBasicAuthenticationTest.arguments() - .filter(PBKDF2_WITH_MAC_TEST_ARGUMENT_FILTER); - } - - @TestEngine.Test - public void testHealthy() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpHealthyRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> - assertHttpResponseCode(response, code.get())); - }); - } - - @TestEngine.Test - public void testMetrics() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpOpenMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusProtobufMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); + .filter(new PBKDF2WithHmacExporterTestEnvironmentFilter()); } @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPlaintextTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPlaintextTest.java index d8c886ac..5994de39 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPlaintextTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPlaintextTest.java @@ -17,216 +17,86 @@ package io.prometheus.jmx.test.http.authentication; import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; -import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpResponseCode; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.http.HttpBasicAuthenticationCredentials; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Map; +import java.util.function.BiConsumer; public class BasicAuthenticationPlaintextTest extends AbstractBasicAuthenticationTest - implements Consumer { - - @TestEngine.Test - public void testHealthy() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpHealthyRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> - assertHttpResponseCode(response, code.get())); - }); - } - - @TestEngine.Test - public void testMetrics() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpOpenMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusProtobufMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA1Test.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA1Test.java index 3bcc5ba9..e5c7605e 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA1Test.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA1Test.java @@ -17,216 +17,86 @@ package io.prometheus.jmx.test.http.authentication; import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; -import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpResponseCode; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.http.HttpBasicAuthenticationCredentials; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Map; +import java.util.function.BiConsumer; public class BasicAuthenticationSHA1Test extends AbstractBasicAuthenticationTest - implements Consumer { - - @TestEngine.Test - public void testHealthy() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpHealthyRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> - assertHttpResponseCode(response, code.get())); - }); - } - - @TestEngine.Test - public void testMetrics() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpOpenMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusProtobufMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA256Test.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA256Test.java index 965acfbd..5223e3b9 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA256Test.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA256Test.java @@ -17,216 +17,86 @@ package io.prometheus.jmx.test.http.authentication; import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; -import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpResponseCode; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.http.HttpBasicAuthenticationCredentials; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Map; +import java.util.function.BiConsumer; public class BasicAuthenticationSHA256Test extends AbstractBasicAuthenticationTest - implements Consumer { - - @TestEngine.Test - public void testHealthy() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpHealthyRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> - assertHttpResponseCode(response, code.get())); - }); - } - - @TestEngine.Test - public void testMetrics() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpOpenMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusProtobufMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA512Test.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA512Test.java index a29561df..918b634a 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA512Test.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA512Test.java @@ -17,216 +17,86 @@ package io.prometheus.jmx.test.http.authentication; import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; -import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpResponseCode; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.http.HttpBasicAuthenticationCredentials; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Map; +import java.util.function.BiConsumer; public class BasicAuthenticationSHA512Test extends AbstractBasicAuthenticationTest - implements Consumer { - - @TestEngine.Test - public void testHealthy() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpHealthyRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> - assertHttpResponseCode(response, code.get())); - }); - } - - @TestEngine.Test - public void testMetrics() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpOpenMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusProtobufMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/AbstractSSLTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/AbstractSSLTest.java new file mode 100644 index 00000000..15b4ca13 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/AbstractSSLTest.java @@ -0,0 +1,23 @@ +package io.prometheus.jmx.test.http.ssl; + +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; +import io.prometheus.jmx.test.http.authentication.AbstractBasicAuthenticationTest; +import java.util.stream.Stream; +import org.antublue.verifyica.api.Verifyica; + +public abstract class AbstractSSLTest extends AbstractExporterTest { + + private static final String BASE_URL = "https://localhost"; + + /** + * Method to get the Stream of test environments + * + * @return the Stream of test environments + */ + @Verifyica.ArgumentSupplier + public static Stream arguments() { + return AbstractBasicAuthenticationTest.arguments() + .map(exporterTestEnvironment -> exporterTestEnvironment.setBaseUrl(BASE_URL)); + } +} diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLAndBasicAuthenticationPBKDF2WithHmacSHA512Test.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLAndBasicAuthenticationPBKDF2WithHmacSHA512Test.java index 67f7b83d..4cefa77c 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLAndBasicAuthenticationPBKDF2WithHmacSHA512Test.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLAndBasicAuthenticationPBKDF2WithHmacSHA512Test.java @@ -17,242 +17,108 @@ package io.prometheus.jmx.test.http.ssl; import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; -import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpResponseCode; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.http.authentication.AbstractBasicAuthenticationTest; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.TestArguments; -import io.prometheus.jmx.test.support.http.HttpBasicAuthenticationCredentials; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; +import java.util.Map; +import java.util.function.BiConsumer; import java.util.stream.Stream; -import org.antublue.test.engine.api.TestEngine; +import org.antublue.verifyica.api.Verifyica; public class SSLAndBasicAuthenticationPBKDF2WithHmacSHA512Test - extends AbstractBasicAuthenticationTest implements Consumer { - - private static final String BASE_URL = "https://localhost"; + extends AbstractBasicAuthenticationTest + implements BiConsumer { /** - * Method to get the list of TestArguments + * Method to get the Stream of test environments * - * @return the return value + * @return the Stream of test environments */ - @TestEngine.ArgumentSupplier - public static Stream arguments() { - return AbstractBasicAuthenticationTest.arguments() - .filter(PBKDF2_WITH_MAC_TEST_ARGUMENT_FILTER) + @Verifyica.ArgumentSupplier + public static Stream arguments() { + // Filter eclipse-temurin:8 based Alpine images due to missing TLS cipher suites + // https://github.com/adoptium/temurin-build/issues/3002 + // https://bugs.openjdk.org/browse/JDK-8306037 + return AbstractSSLTest.arguments() .filter( - testArgument -> - !testArgument - .getDockerImageName() + exporterTestEnvironment -> + !exporterTestEnvironment + .getJavaDockerImage() .contains("eclipse-temurin:8-alpine")); } - @TestEngine.Prepare - public void setBaseUrl() { - testEnvironment.setBaseUrl(BASE_URL); - } - - @TestEngine.Test - public void testHealthy() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpHealthyRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> - assertHttpResponseCode(response, code.get())); - }); - } - - @TestEngine.Test - public void testMetrics() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpOpenMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - getAuthenticationTestCredentials() - .forEach( - authenticationTestArguments -> { - final AtomicInteger code = - new AtomicInteger( - authenticationTestArguments.isValid() - ? HttpResponse.OK - : HttpResponse.UNAUTHORIZED); - new HttpPrometheusProtobufMetricsRequest() - .credentials( - new HttpBasicAuthenticationCredentials( - authenticationTestArguments.getUsername(), - authenticationTestArguments.getPassword())) - .send(testEnvironment.getHttpClient()) - .accept( - response -> { - assertHttpResponseCode(response, code.get()); - if (code.get() == HttpResponse.OK) { - accept(response); - } - }); - }); - } - @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreMultipleCertificatesTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreMultipleCertificatesTest.java index 2d96fcd6..6de304e3 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreMultipleCertificatesTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreMultipleCertificatesTest.java @@ -19,142 +19,104 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; -import io.prometheus.jmx.test.AbstractTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.TestArguments; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; +import java.util.Map; +import java.util.function.BiConsumer; import java.util.stream.Stream; -import org.antublue.test.engine.api.TestEngine; +import org.antublue.verifyica.api.Verifyica; -public class SSLWithJKSKeyStoreMultipleCertificatesTest extends AbstractTest - implements Consumer { - - private static final String BASE_URL = "https://localhost"; +public class SSLWithJKSKeyStoreMultipleCertificatesTest extends AbstractSSLTest + implements BiConsumer { /** - * Method to get the list of TestArguments + * Method to get the Stream of test environments * - * @return the return value + * @return the Stream of test environments */ - @TestEngine.ArgumentSupplier - public static Stream arguments() { + @Verifyica.ArgumentSupplier + public static Stream arguments() { // Filter eclipse-temurin:8 based Alpine images due to missing TLS cipher suites // https://github.com/adoptium/temurin-build/issues/3002 - return AbstractTest.arguments() + // https://bugs.openjdk.org/browse/JDK-8306037 + return AbstractSSLTest.arguments() .filter( - testArgument -> - !testArgument - .getDockerImageName() + exporterTestEnvironment -> + !exporterTestEnvironment + .getJavaDockerImage() .contains("eclipse-temurin:8-alpine")); } - @TestEngine.Prepare - public void setBaseUrl() { - testEnvironment.setBaseUrl(BASE_URL); - } - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } - @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest.java index b08a80c3..c9d3c6a7 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest.java @@ -19,141 +19,104 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; -import io.prometheus.jmx.test.AbstractTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.TestArguments; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; +import java.util.Map; +import java.util.function.BiConsumer; import java.util.stream.Stream; -import org.antublue.test.engine.api.TestEngine; +import org.antublue.verifyica.api.Verifyica; -public class SSLWithJKSKeyStoreTest extends AbstractTest implements Consumer { - - private static final String BASE_URL = "https://localhost"; +public class SSLWithJKSKeyStoreTest extends AbstractSSLTest + implements BiConsumer { /** - * Method to get the list of TestArguments + * Method to get the Stream of test environments * - * @return the return value + * @return the Stream of test environments */ - @TestEngine.ArgumentSupplier - public static Stream arguments() { + @Verifyica.ArgumentSupplier + public static Stream arguments() { // Filter eclipse-temurin:8 based Alpine images due to missing TLS cipher suites // https://github.com/adoptium/temurin-build/issues/3002 - return AbstractTest.arguments() + // https://bugs.openjdk.org/browse/JDK-8306037 + return AbstractSSLTest.arguments() .filter( - testArgument -> - !testArgument - .getDockerImageName() + exporterTestEnvironment -> + !exporterTestEnvironment + .getJavaDockerImage() .contains("eclipse-temurin:8-alpine")); } - @TestEngine.Prepare - public void setBaseUrl() { - testEnvironment.setBaseUrl(BASE_URL); - } - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } - @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest2.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest2.java index dbd8c850..bd341438 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest2.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest2.java @@ -19,141 +19,104 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; -import io.prometheus.jmx.test.AbstractTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.TestArguments; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; +import java.util.Map; +import java.util.function.BiConsumer; import java.util.stream.Stream; -import org.antublue.test.engine.api.TestEngine; +import org.antublue.verifyica.api.Verifyica; -public class SSLWithJKSKeyStoreTest2 extends AbstractTest implements Consumer { - - private static final String BASE_URL = "https://localhost"; +public class SSLWithJKSKeyStoreTest2 extends AbstractSSLTest + implements BiConsumer { /** - * Method to get the list of TestArguments + * Method to get the Stream of test environments * - * @return the return value + * @return the Stream of test environments */ - @TestEngine.ArgumentSupplier - public static Stream arguments() { + @Verifyica.ArgumentSupplier + public static Stream arguments() { // Filter eclipse-temurin:8 based Alpine images due to missing TLS cipher suites // https://github.com/adoptium/temurin-build/issues/3002 - return AbstractTest.arguments() + // https://bugs.openjdk.org/browse/JDK-8306037 + return AbstractSSLTest.arguments() .filter( - testArgument -> - !testArgument - .getDockerImageName() + exporterTestEnvironment -> + !exporterTestEnvironment + .getJavaDockerImage() .contains("eclipse-temurin:8-alpine")); } - @TestEngine.Prepare - public void setBaseUrl() { - testEnvironment.setBaseUrl(BASE_URL); - } - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } - @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreMultipleCertificatesTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreMultipleCertificatesTest.java index 26d7c0a6..c8fbe606 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreMultipleCertificatesTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreMultipleCertificatesTest.java @@ -19,170 +19,100 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; -import io.prometheus.jmx.test.AbstractTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; +import io.prometheus.jmx.test.common.PKCS12KeyStoreExporterTestEnvironmentFilter; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.TestArguments; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Predicate; +import java.util.Map; +import java.util.function.BiConsumer; import java.util.stream.Stream; -import org.antublue.test.engine.api.TestEngine; - -public class SSLWithPKCS12KeyStoreMultipleCertificatesTest extends AbstractTest - implements Consumer { - - private static final String BASE_URL = "https://localhost"; - - protected static final Predicate PKCS12_KEYSTORE_TEST_ARGUMENT_FILTER = - new PKCS12KeyStoreTestArgumentFilter(); - - private static class PKCS12KeyStoreTestArgumentFilter implements Predicate { - - private final Set filteredDockerImages; - - public PKCS12KeyStoreTestArgumentFilter() { - filteredDockerImages = new HashSet<>(); - filteredDockerImages.add("eclipse-temurin:8-alpine"); - filteredDockerImages.add("ghcr.io/graalvm/jdk:java8"); - filteredDockerImages.add("ibmjava:8"); - filteredDockerImages.add("ibmjava:8-jre"); - filteredDockerImages.add("ibmjava:8-sdk"); - filteredDockerImages.add("ibmjava:8-sfj"); - filteredDockerImages.add("ibmjava:11"); - } - - /** - * Evaluates this predicate on the given argument. - * - * @param testArguments the input argument - * @return {@code true} if the input argument matches the predicate, otherwise {@code false} - */ - @Override - public boolean test(TestArguments testArguments) { - return !filteredDockerImages.contains(testArguments.getDockerImageName()); - } - } +import org.antublue.verifyica.api.Verifyica; + +public class SSLWithPKCS12KeyStoreMultipleCertificatesTest extends AbstractSSLTest + implements BiConsumer { /** - * Method to get the list of TestArguments + * Method to get the Stream of test environments * - * @return the return value + * @return the Stream of test environments */ - @TestEngine.ArgumentSupplier - public static Stream arguments() { + @Verifyica.ArgumentSupplier + public static Stream arguments() { // Filter Java versions that don't support the PKCS12 keystore // format or don't support the required TLS cipher suites - return AbstractTest.arguments().filter(PKCS12_KEYSTORE_TEST_ARGUMENT_FILTER); - } - - @TestEngine.Prepare - public void setBaseUrl() { - testEnvironment.setBaseUrl(BASE_URL); - } - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); + return AbstractSSLTest.arguments() + .filter(new PKCS12KeyStoreExporterTestEnvironmentFilter()); } @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest.java index 52ab9c72..e05c64af 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest.java @@ -19,169 +19,100 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; -import io.prometheus.jmx.test.AbstractTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; +import io.prometheus.jmx.test.common.PKCS12KeyStoreExporterTestEnvironmentFilter; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.TestArguments; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Predicate; +import java.util.Map; +import java.util.function.BiConsumer; import java.util.stream.Stream; -import org.antublue.test.engine.api.TestEngine; - -public class SSLWithPKCS12KeyStoreTest extends AbstractTest implements Consumer { - - private static final String BASE_URL = "https://localhost"; - - protected static final Predicate PKCS12_KEYSTORE_TEST_ARGUMENT_FILTER = - new PKCS12KeyStoreTestArgumentFilter(); - - private static class PKCS12KeyStoreTestArgumentFilter implements Predicate { - - private final Set filteredDockerImages; - - public PKCS12KeyStoreTestArgumentFilter() { - filteredDockerImages = new HashSet<>(); - filteredDockerImages.add("eclipse-temurin:8-alpine"); - filteredDockerImages.add("ghcr.io/graalvm/jdk:java8"); - filteredDockerImages.add("ibmjava:8"); - filteredDockerImages.add("ibmjava:8-jre"); - filteredDockerImages.add("ibmjava:8-sdk"); - filteredDockerImages.add("ibmjava:8-sfj"); - filteredDockerImages.add("ibmjava:11"); - } - - /** - * Evaluates this predicate on the given argument. - * - * @param testArguments the input argument - * @return {@code true} if the input argument matches the predicate, otherwise {@code false} - */ - @Override - public boolean test(TestArguments testArguments) { - return !filteredDockerImages.contains(testArguments.getDockerImageName()); - } - } +import org.antublue.verifyica.api.Verifyica; + +public class SSLWithPKCS12KeyStoreTest extends AbstractSSLTest + implements BiConsumer { /** - * Method to get the list of TestArguments + * Method to get the Stream of test environments * - * @return the return value + * @return the Stream of test environments */ - @TestEngine.ArgumentSupplier - public static Stream arguments() { + @Verifyica.ArgumentSupplier + public static Stream arguments() { // Filter Java versions that don't support the PKCS12 keystore // format or don't support the required TLS cipher suites - return AbstractTest.arguments().filter(PKCS12_KEYSTORE_TEST_ARGUMENT_FILTER); - } - - @TestEngine.Prepare - public void setBaseUrl() { - testEnvironment.setBaseUrl(BASE_URL); - } - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); + return AbstractSSLTest.arguments() + .filter(new PKCS12KeyStoreExporterTestEnvironmentFilter()); } @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest2.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest2.java index 06813989..2ba94715 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest2.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest2.java @@ -19,169 +19,100 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; -import io.prometheus.jmx.test.AbstractTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; +import io.prometheus.jmx.test.common.PKCS12KeyStoreExporterTestEnvironmentFilter; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.TestArguments; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Predicate; +import java.util.Map; +import java.util.function.BiConsumer; import java.util.stream.Stream; -import org.antublue.test.engine.api.TestEngine; - -public class SSLWithPKCS12KeyStoreTest2 extends AbstractTest implements Consumer { - - private static final String BASE_URL = "https://localhost"; - - protected static final Predicate PKCS12_KEYSTORE_TEST_ARGUMENT_FILTER = - new PKCS12KeyStoreTestArgumentFilter(); - - private static class PKCS12KeyStoreTestArgumentFilter implements Predicate { - - private final Set filteredDockerImages; - - public PKCS12KeyStoreTestArgumentFilter() { - filteredDockerImages = new HashSet<>(); - filteredDockerImages.add("eclipse-temurin:8-alpine"); - filteredDockerImages.add("ghcr.io/graalvm/jdk:java8"); - filteredDockerImages.add("ibmjava:8"); - filteredDockerImages.add("ibmjava:8-jre"); - filteredDockerImages.add("ibmjava:8-sdk"); - filteredDockerImages.add("ibmjava:8-sfj"); - filteredDockerImages.add("ibmjava:11"); - } - - /** - * Evaluates this predicate on the given argument. - * - * @param testArguments the input argument - * @return {@code true} if the input argument matches the predicate, otherwise {@code false} - */ - @Override - public boolean test(TestArguments testArguments) { - return !filteredDockerImages.contains(testArguments.getDockerImageName()); - } - } +import org.antublue.verifyica.api.Verifyica; + +public class SSLWithPKCS12KeyStoreTest2 extends AbstractSSLTest + implements BiConsumer { /** - * Method to get the list of TestArguments + * Method to get the Stream of test environments * - * @return the return value + * @return the Stream of test environments */ - @TestEngine.ArgumentSupplier - public static Stream arguments() { + @Verifyica.ArgumentSupplier + public static Stream arguments() { // Filter Java versions that don't support the PKCS12 keystore // format or don't support the required TLS cipher suites - return AbstractTest.arguments().filter(PKCS12_KEYSTORE_TEST_ARGUMENT_FILTER); - } - - @TestEngine.Prepare - public void setBaseUrl() { - testEnvironment.setBaseUrl(BASE_URL); - } - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); + return AbstractSSLTest.arguments() + .filter(new PKCS12KeyStoreExporterTestEnvironmentFilter()); } @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/threads/ThreadsConfigurationTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/threads/ThreadsConfigurationTest.java index 55aeb840..786c45cd 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/threads/ThreadsConfigurationTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/http/threads/ThreadsConfigurationTest.java @@ -19,115 +19,85 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; -import io.prometheus.jmx.test.AbstractTest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; -import org.antublue.test.engine.api.TestEngine; +import java.util.Map; +import java.util.function.BiConsumer; -public class ThreadsConfigurationTest extends AbstractTest implements Consumer { - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); - } +public class ThreadsConfigurationTest extends AbstractExporterTest + implements BiConsumer { @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/ExpectedMetricsNames.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/ExpectedMetricsNames.java new file mode 100644 index 00000000..b8e63f5a --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/ExpectedMetricsNames.java @@ -0,0 +1,201 @@ +package io.prometheus.jmx.test.opentelemetry; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + +/** Class to implement ExpectedMetricsNames */ +public class ExpectedMetricsNames { + + private static final Collection METRIC_NAMES; + + static { + Collection metricNames = new ArrayList<>(); + + metricNames.add("io_prometheus_jmx_autoIncrementing_Value"); + + // These metric doesn't exist for Java 11+ + // metricNames.add("io_prometheus_jmx_optionalValue_Value"); + + metricNames.add("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_avail"); + metricNames.add("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_pcent"); + metricNames.add("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size"); + metricNames.add("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_used"); + metricNames.add("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_avail"); + metricNames.add("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent"); + metricNames.add("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_size"); + metricNames.add("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_used"); + metricNames.add( + "io_prometheus_jmx_test_PerformanceMetricsMBean_PerformanceMetrics_ActiveSessions"); + metricNames.add( + "io_prometheus_jmx_test_PerformanceMetricsMBean_PerformanceMetrics_Bootstraps"); + metricNames.add( + "io_prometheus_jmx_test_PerformanceMetricsMBean_PerformanceMetrics_BootstrapsDeferred"); + metricNames.add("java_lang_ClassLoading_LoadedClassCount"); + metricNames.add("java_lang_ClassLoading_TotalLoadedClassCount"); + metricNames.add("java_lang_ClassLoading_UnloadedClassCount"); + metricNames.add("java_lang_ClassLoading_Verbose"); + metricNames.add("java_lang_Compilation_CompilationTimeMonitoringSupported"); + metricNames.add("java_lang_Compilation_TotalCompilationTime"); + + // These metrics don't exist for Java 11+ + + /* + metricNames.add("java_lang_GarbageCollector_CollectionCount"); + metricNames.add("java_lang_GarbageCollector_CollectionTime"); + metricNames.add("java_lang_GarbageCollector_LastGcInfo_GcThreadCount"); + metricNames.add("java_lang_GarbageCollector_LastGcInfo_duration"); + metricNames.add("java_lang_GarbageCollector_LastGcInfo_endTime"); + metricNames.add("java_lang_GarbageCollector_LastGcInfo_id"); + metricNames.add("java_lang_GarbageCollector_LastGcInfo_memoryUsageAfterGc_committed"); + metricNames.add("java_lang_GarbageCollector_LastGcInfo_memoryUsageAfterGc_init"); + metricNames.add("java_lang_GarbageCollector_LastGcInfo_memoryUsageAfterGc_max"); + metricNames.add("java_lang_GarbageCollector_LastGcInfo_memoryUsageAfterGc_used"); + metricNames.add("java_lang_GarbageCollector_LastGcInfo_memoryUsageBeforeGc_committed"); + metricNames.add("java_lang_GarbageCollector_LastGcInfo_memoryUsageBeforeGc_init"); + metricNames.add("java_lang_GarbageCollector_LastGcInfo_memoryUsageBeforeGc_max"); + metricNames.add("java_lang_GarbageCollector_LastGcInfo_memoryUsageBeforeGc_used"); + metricNames.add("java_lang_GarbageCollector_LastGcInfo_startTime"); + metricNames.add("java_lang_GarbageCollector_Valid"); + metricNames.add("java_lang_MemoryManager_Valid"); + metricNames.add("java_lang_MemoryPool_CollectionUsageThreshold"); + metricNames.add("java_lang_MemoryPool_CollectionUsageThresholdCount"); + metricNames.add("java_lang_MemoryPool_CollectionUsageThresholdExceeded"); + metricNames.add("java_lang_MemoryPool_CollectionUsageThresholdSupported"); + metricNames.add("java_lang_MemoryPool_CollectionUsage_committed"); + metricNames.add("java_lang_MemoryPool_CollectionUsage_init"); + metricNames.add("java_lang_MemoryPool_CollectionUsage_max"); + metricNames.add("java_lang_MemoryPool_CollectionUsage_used"); + metricNames.add("java_lang_MemoryPool_PeakUsage_committed"); + metricNames.add("java_lang_MemoryPool_PeakUsage_init"); + metricNames.add("java_lang_MemoryPool_PeakUsage_max"); + metricNames.add("java_lang_MemoryPool_PeakUsage_used"); + metricNames.add("java_lang_MemoryPool_UsageThreshold"); + metricNames.add("java_lang_MemoryPool_UsageThresholdCount"); + metricNames.add("java_lang_MemoryPool_UsageThresholdExceeded"); + metricNames.add("java_lang_MemoryPool_UsageThresholdSupported"); + metricNames.add("java_lang_MemoryPool_Usage_committed"); + metricNames.add("java_lang_MemoryPool_Usage_init"); + metricNames.add("java_lang_MemoryPool_Usage_max"); + metricNames.add("java_lang_MemoryPool_Usage_used"); + metricNames.add("java_lang_MemoryPool_Valid"); + metricNames.add("java_lang_Memory_HeapMemoryUsage_committed"); + metricNames.add("java_lang_Memory_HeapMemoryUsage_init"); + metricNames.add("java_lang_Memory_HeapMemoryUsage_max"); + metricNames.add("java_lang_Memory_HeapMemoryUsage_used"); + metricNames.add("java_lang_Memory_NonHeapMemoryUsage_committed"); + metricNames.add("java_lang_Memory_NonHeapMemoryUsage_init"); + metricNames.add("java_lang_Memory_NonHeapMemoryUsage_max"); + metricNames.add("java_lang_Memory_NonHeapMemoryUsage_used"); + metricNames.add("java_lang_Memory_ObjectPendingFinalizationCount"); + metricNames.add("java_lang_Memory_Verbose"); + */ + + metricNames.add("java_lang_OperatingSystem_AvailableProcessors"); + metricNames.add("java_lang_OperatingSystem_CommittedVirtualMemorySize"); + metricNames.add("java_lang_OperatingSystem_FreePhysicalMemorySize"); + metricNames.add("java_lang_OperatingSystem_FreeSwapSpaceSize"); + metricNames.add("java_lang_OperatingSystem_MaxFileDescriptorCount"); + metricNames.add("java_lang_OperatingSystem_OpenFileDescriptorCount"); + metricNames.add("java_lang_OperatingSystem_ProcessCpuLoad"); + metricNames.add("java_lang_OperatingSystem_ProcessCpuTime"); + metricNames.add("java_lang_OperatingSystem_SystemCpuLoad"); + metricNames.add("java_lang_OperatingSystem_SystemLoadAverage"); + metricNames.add("java_lang_OperatingSystem_TotalPhysicalMemorySize"); + metricNames.add("java_lang_OperatingSystem_TotalSwapSpaceSize"); + metricNames.add("java_lang_Runtime_BootClassPathSupported"); + metricNames.add("java_lang_Runtime_StartTime"); + metricNames.add("java_lang_Runtime_Uptime"); + + // These metrics don't exist for ibmjava + + /*metricNames.add("java_lang_Threading_CurrentThreadAllocatedBytes"); + metricNames.add("java_lang_Threading_CurrentThreadCpuTime"); + metricNames.add("java_lang_Threading_CurrentThreadCpuTimeSupported"); + metricNames.add("java_lang_Threading_CurrentThreadUserTime"); + metricNames.add("java_lang_Threading_DaemonThreadCount"); + metricNames.add("java_lang_Threading_ObjectMonitorUsageSupported"); + metricNames.add("java_lang_Threading_PeakThreadCount"); + metricNames.add("java_lang_Threading_SynchronizerUsageSupported"); + metricNames.add("java_lang_Threading_ThreadAllocatedMemoryEnabled"); + metricNames.add("java_lang_Threading_ThreadAllocatedMemorySupported"); + metricNames.add("java_lang_Threading_ThreadContentionMonitoringEnabled"); + metricNames.add("java_lang_Threading_ThreadContentionMonitoringSupported"); + metricNames.add("java_lang_Threading_ThreadCount"); + metricNames.add("java_lang_Threading_ThreadCpuTimeEnabled"); + metricNames.add("java_lang_Threading_ThreadCpuTimeSupported"); + metricNames.add("java_lang_Threading_TotalStartedThreadCount"); + */ + + // These metrics don't exist for Java 11+ + + /* + metricNames.add("java_nio_BufferPool_Count"); + metricNames.add("java_nio_BufferPool_MemoryUsed"); + metricNames.add("java_nio_BufferPool_TotalCapacity"); + */ + + metricNames.add("jmx_config_reload_failure_total"); + metricNames.add("jmx_config_reload_success_total"); + metricNames.add("jmx_exporter_build"); + metricNames.add("jmx_scrape_cached_beans"); + metricNames.add("jmx_scrape_duration_seconds"); + metricNames.add("jmx_scrape_error"); + metricNames.add("jvm_buffer_pool_capacity_bytes"); + metricNames.add("jvm_buffer_pool_used_buffers"); + metricNames.add("jvm_buffer_pool_used_bytes"); + metricNames.add("jvm_classes_currently_loaded"); + metricNames.add("jvm_classes_loaded_total"); + metricNames.add("jvm_classes_unloaded_total"); + metricNames.add("jvm_compilation_time_seconds_total"); + metricNames.add("jvm_gc_collection_seconds_count"); + metricNames.add("jvm_gc_collection_seconds_sum"); + metricNames.add("jvm_memory_committed_bytes"); + metricNames.add("jvm_memory_init_bytes"); + metricNames.add("jvm_memory_max_bytes"); + metricNames.add("jvm_memory_objects_pending_finalization"); + metricNames.add("jvm_memory_pool_allocated_bytes_total"); + metricNames.add("jvm_memory_pool_collection_committed_bytes"); + metricNames.add("jvm_memory_pool_collection_init_bytes"); + metricNames.add("jvm_memory_pool_collection_max_bytes"); + metricNames.add("jvm_memory_pool_collection_used_bytes"); + metricNames.add("jvm_memory_pool_committed_bytes"); + metricNames.add("jvm_memory_pool_init_bytes"); + metricNames.add("jvm_memory_pool_max_bytes"); + metricNames.add("jvm_memory_pool_used_bytes"); + metricNames.add("jvm_memory_used_bytes"); + metricNames.add("jvm_runtime"); + metricNames.add("jvm_threads_current"); + metricNames.add("jvm_threads_daemon"); + metricNames.add("jvm_threads_deadlocked"); + metricNames.add("jvm_threads_deadlocked_monitor"); + metricNames.add("jvm_threads_peak"); + metricNames.add("jvm_threads_started_total"); + metricNames.add("jvm_threads_state"); + metricNames.add("org_exist_management_exist_ProcessReport_RunningQueries_elapsedTime"); + metricNames.add("org_exist_management_exist_ProcessReport_RunningQueries_id"); + metricNames.add("org_exist_management_exist_ProcessReport_RunningQueries_startedAtTime"); + metricNames.add("process_cpu_seconds_total"); + metricNames.add("process_max_fds"); + metricNames.add("process_open_fds"); + metricNames.add("process_resident_memory_bytes"); + metricNames.add("process_start_time_seconds"); + metricNames.add("process_virtual_memory_bytes"); + + METRIC_NAMES = Collections.unmodifiableCollection(metricNames); + } + + /** Constructor */ + private ExpectedMetricsNames() { + // DO NOTHING + } + + /** + * Method to get metrics names + * + * @return a List of metrics names + */ + public static Collection getMetricsNames() { + return METRIC_NAMES; + } +} diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest.java new file mode 100644 index 00000000..b8466941 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest.java @@ -0,0 +1,216 @@ +package io.prometheus.jmx.test.opentelemetry; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.prometheus.jmx.test.support.JavaDockerImages; +import io.prometheus.jmx.test.support.JmxExporterMode; +import io.prometheus.jmx.test.support.http.HttpRequest; +import io.prometheus.jmx.test.support.http.HttpResponse; +import io.prometheus.jmx.test.support.throttle.ExponentialBackoffThrottle; +import io.prometheus.jmx.test.support.throttle.Throttle; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Stream; +import org.antublue.verifyica.api.ArgumentContext; +import org.antublue.verifyica.api.Verifyica; +import org.junit.jupiter.api.Assertions; +import org.testcontainers.containers.Network; +import org.testcontainers.shaded.org.yaml.snakeyaml.Yaml; + +/** Class to implement OpenTelemetryTest */ +public class OpenTelemetryTest { + + public static final String NETWORK = "network"; + + /** + * Method to get the Stream of test environments + * + * @return the Stream of test environments + */ + @Verifyica.ArgumentSupplier(parallelism = 2) + public static Stream arguments() { + Collection openTelemetryTestEnvironments = new ArrayList<>(); + + PrometheusDockerImages.names() + .forEach( + prometheusDockerImage -> + JavaDockerImages.names() + .forEach( + javaDockerImageName -> { + for (JmxExporterMode jmxExporterMode : + JmxExporterMode.values()) { + openTelemetryTestEnvironments.add( + new OpenTelemetryTestEnvironment( + prometheusDockerImage, + javaDockerImageName, + jmxExporterMode)); + } + })); + + return openTelemetryTestEnvironments.stream(); + } + + @Verifyica.BeforeAll + public void beforeAll(ArgumentContext argumentContext) { + // Create a Network and get the id to force the network creation + Network network = Network.newNetwork(); + network.getId(); + + argumentContext.getStore().put(NETWORK, network); + + Class testClass = argumentContext.getClassContext().getTestClass(); + + OpenTelemetryTestEnvironment openTelemetryTestEnvironment = + argumentContext.getTestArgument(OpenTelemetryTestEnvironment.class).getPayload(); + + openTelemetryTestEnvironment.initialize(testClass, network); + } + + /** Method to test that Prometheus is up */ + @Verifyica.Test + @Verifyica.Order(order = 0) + public void testIsPrometheusUp(ArgumentContext argumentContext) { + OpenTelemetryTestEnvironment openTelemetryTestEnvironment = + argumentContext.getTestArgument(OpenTelemetryTestEnvironment.class).getPayload(); + + Throttle throttle = new ExponentialBackoffThrottle(100, 5000); + AtomicBoolean success = new AtomicBoolean(); + + for (int i = 0; i < 10; i++) { + sendPrometheusQuery(openTelemetryTestEnvironment, "up") + .accept( + httpResponse -> { + assertThat(httpResponse).isNotNull(); + + if (httpResponse.statusCode() != 200) { + return; + } + + assertThat(httpResponse.body()).isNotNull(); + assertThat(httpResponse.body().string()).isNotNull(); + + Map map = + new Yaml().load(httpResponse.body().string()); + + String status = (String) map.get("status"); + assertThat(status).isEqualTo("success"); + + success.set(true); + }); + + if (success.get()) { + break; + } + + throttle.throttle(); + } + + if (!success.get()) { + Assertions.fail("Prometheus is not up"); + } + } + + /** Method to test that metrics exist in Prometheus */ + @Verifyica.Test + public void testPrometheusHasMetrics(ArgumentContext argumentContext) { + OpenTelemetryTestEnvironment openTelemetryTestEnvironment = + argumentContext.getTestArgument(OpenTelemetryTestEnvironment.class).getPayload(); + + boolean isJmxExporterModeJavaStandalone = + openTelemetryTestEnvironment.getJmxExporterMode() == JmxExporterMode.Standalone; + + ExpectedMetricsNames.getMetricsNames().stream() + .filter( + metricName -> + !isJmxExporterModeJavaStandalone + || (!metricName.startsWith("jvm_") + && !metricName.startsWith("process_"))) + .forEach( + metricName -> { + Double value = + getPrometheusMetric(openTelemetryTestEnvironment, metricName); + assertThat(value).as("metricName [%s]", metricName).isNotNull(); + assertThat(value).as("metricName [%s]", metricName).isEqualTo(1); + }); + } + + @Verifyica.AfterAll + public void afterAll(ArgumentContext argumentContext) { + Optional.ofNullable(argumentContext.getTestArgument(OpenTelemetryTestEnvironment.class)) + .ifPresent( + openTelemetryTestEnvironmentArgument -> + openTelemetryTestEnvironmentArgument.getPayload().destroy()); + + Optional.ofNullable(argumentContext.getStore().remove(NETWORK, Network.class)) + .ifPresent(Network::close); + } + + /** + * Method to get a Prometheus metric + * + * @param openTelemetryTestEnvironment openTelemetryTestEnvironment + * @param metricName metricName + * @return the metric value, or null if it doesn't exist + */ + protected Double getPrometheusMetric( + OpenTelemetryTestEnvironment openTelemetryTestEnvironment, String metricName) { + Throttle throttle = new ExponentialBackoffThrottle(100, 5000); + AtomicReference value = new AtomicReference<>(); + + for (int i = 0; i < 10; i++) { + sendPrometheusQuery(openTelemetryTestEnvironment, metricName) + .accept( + httpResponse -> { + assertThat(httpResponse).isNotNull(); + assertThat(httpResponse.statusCode()).isEqualTo(200); + assertThat(httpResponse.body()).isNotNull(); + assertThat(httpResponse.body().string()).isNotNull(); + + // TODO parse response and return value + if (httpResponse.body().string().contains(metricName)) { + value.set(1.0); + } + }); + + if (value.get() != null) { + break; + } + + throttle.throttle(); + } + + return value.get(); + } + + /** + * Method to send a Prometheus query + * + * @param openTelemetryTestEnvironment openTelemetryTestEnvironment + * @param query query + * @return an HttpResponse + */ + protected HttpResponse sendPrometheusQuery( + OpenTelemetryTestEnvironment openTelemetryTestEnvironment, String query) { + return sendRequest( + openTelemetryTestEnvironment, + "/api/v1/query?query=" + URLEncoder.encode(query, StandardCharsets.UTF_8)); + } + + /** + * Method to send a Http GET request + * + * @param openTelemetryTestEnvironment openTelemetryTestEnvironment + * @param path path + * @return an HttpResponse + */ + protected HttpResponse sendRequest( + OpenTelemetryTestEnvironment openTelemetryTestEnvironment, String path) { + return openTelemetryTestEnvironment.getPrometheusHttpClient().send(new HttpRequest(path)); + } +} diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTestEnvironment.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTestEnvironment.java new file mode 100644 index 00000000..ee542fd1 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTestEnvironment.java @@ -0,0 +1,414 @@ +package io.prometheus.jmx.test.opentelemetry; + +import com.github.dockerjava.api.model.Ulimit; +import io.prometheus.jmx.common.util.ResourceSupport; +import io.prometheus.jmx.test.support.JmxExporterMode; +import io.prometheus.jmx.test.support.http.HttpClient; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; +import org.antublue.verifyica.api.Argument; +import org.testcontainers.containers.BindMode; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.startupcheck.IsRunningStartupCheckStrategy; +import org.testcontainers.containers.wait.strategy.Wait; + +/** Class to implement OpenTelemetryTestEnvironment */ +public class OpenTelemetryTestEnvironment implements Argument { + + private static final long MEMORY_BYTES = 1073741824; // 1 GB + private static final long MEMORY_SWAP_BYTES = 2 * MEMORY_BYTES; + private static final String BASE_URL = "http://localhost"; + + private final String prometheusDockerImage; + private final String javaDockerImage; + private final JmxExporterMode jmxExporterMode; + + private Class testClass; + private Network network; + private GenericContainer prometheusContainer; + private GenericContainer standaloneApplicationContainer; + private GenericContainer javaAgentApplicationContainer; + private GenericContainer standaloneExporterContainer; + private HttpClient httpClient; + + /** + * Constructor + * + * @param prometheusDockerImage prometheusDockerImage + * @param javaDockerImage javaDockerImage + * @param jmxExporterMode jmxExporterMode + */ + public OpenTelemetryTestEnvironment( + String prometheusDockerImage, String javaDockerImage, JmxExporterMode jmxExporterMode) { + this.prometheusDockerImage = prometheusDockerImage; + this.javaDockerImage = javaDockerImage; + this.jmxExporterMode = jmxExporterMode; + } + + @Override + public String getName() { + return prometheusDockerImage + " / " + javaDockerImage + " / " + jmxExporterMode; + } + + @Override + public OpenTelemetryTestEnvironment getPayload() { + return this; + } + + /** + * Method to get the Prometheus Docker image name + * + * @return the Prometheus Docker image name + */ + public String getPrometheusDockerImage() { + return prometheusDockerImage; + } + + /** + * Method to get the Java Docker image name + * + * @return the Java Docker image name + */ + public String getJavaDockerImage() { + return javaDockerImage; + } + + /** + * Method to get the JMX Exporter mode + * + * @return the JMX Exporter mode + */ + public JmxExporterMode getJmxExporterMode() { + return jmxExporterMode; + } + + /** + * Method to initialize the test environment + * + * @param network network + */ + public void initialize(Class testClass, Network network) { + this.testClass = testClass; + this.network = network; + + switch (jmxExporterMode) { + case JavaAgent: + { + prometheusContainer = createPrometheusContainer(); + prometheusContainer.start(); + + javaAgentApplicationContainer = createJavaAgentApplicationContainer(); + javaAgentApplicationContainer.start(); + + break; + } + case Standalone: + { + prometheusContainer = createPrometheusContainer(); + prometheusContainer.start(); + + standaloneApplicationContainer = createStandaloneApplicationContainer(); + standaloneApplicationContainer.start(); + + standaloneExporterContainer = createStandaloneExporterContainer(); + standaloneExporterContainer.start(); + + break; + } + } + + if (standaloneApplicationContainer != null && !standaloneApplicationContainer.isRunning()) { + throw new IllegalStateException("standalone exporter container is not running"); + } + + if (standaloneApplicationContainer != null && !standaloneApplicationContainer.isRunning()) { + throw new IllegalStateException("standalone exporter container is not running"); + } + + if (prometheusContainer != null && !prometheusContainer.isRunning()) { + throw new IllegalStateException("standalone exporter container is not running"); + } + + httpClient = createPrometheusHttpClient(prometheusContainer, BASE_URL, 9090); + } + + /** + * Method to get an HttpClient for the test environment + * + * @return an HttpClient + */ + public HttpClient getPrometheusHttpClient() { + return httpClient; + } + + /** Method to destroy the test environment */ + public void destroy() { + if (javaAgentApplicationContainer != null) { + javaAgentApplicationContainer.close(); + javaAgentApplicationContainer = null; + } + + if (standaloneExporterContainer != null) { + standaloneExporterContainer.close(); + standaloneExporterContainer = null; + } + + if (standaloneApplicationContainer != null) { + standaloneApplicationContainer.close(); + standaloneApplicationContainer = null; + } + + if (prometheusContainer != null) { + prometheusContainer.close(); + prometheusContainer = null; + } + } + + /** + * Method to create a Prometheus container + * + * @return the return value + */ + private GenericContainer createPrometheusContainer() { + List commands = new ArrayList<>(); + + commands.add("--config.file=/etc/prometheus/prometheus.yaml"); + commands.add("--storage.tsdb.path=/prometheus"); + commands.add("--web.console.libraries=/usr/share/prometheus/console_libraries"); + commands.add("--web.console.templates=/usr/share/prometheus/consoles"); + commands.add("--enable-feature=otlp-write-receiver"); + + String webYml = + "/" + testClass.getName().replace(".", "/") + "/" + jmxExporterMode + "/web.yaml"; + + boolean hasWebYaml = hasResource(webYml); + + if (hasWebYaml) { + commands.add("--web.config.file=/etc/prometheus/web.yaml"); + } + + GenericContainer genericContainer = + new GenericContainer<>(prometheusDockerImage) + .withClasspathResourceMapping( + testClass.getName().replace(".", "/") + + "/" + + jmxExporterMode + + "/prometheus.yaml", + "/etc/prometheus/prometheus.yaml", + BindMode.READ_ONLY) + .withWorkingDirectory("/prometheus") + .withCommand(commands.toArray(new String[0])) + .withCreateContainerCmdModifier( + c -> + c.getHostConfig() + .withMemory(MEMORY_BYTES) + .withMemorySwap(MEMORY_SWAP_BYTES)) + .withCreateContainerCmdModifier( + c -> + c.getHostConfig() + .withUlimits( + new Ulimit[] { + new Ulimit("nofile", 65536L, 65536L) + })) + .withExposedPorts(9090) + .withLogConsumer( + outputFrame -> { + String string = + outputFrame.getUtf8StringWithoutLineEnding().trim(); + if (!string.isBlank()) { + System.out.println(string); + } + }) + .withNetwork(network) + .withNetworkAliases("prometheus") + .withStartupCheckStrategy(new IsRunningStartupCheckStrategy()) + .withStartupTimeout(Duration.ofMillis(30000)) + .waitingFor( + Wait.forLogMessage( + ".*Server is ready to receive web requests.*", 1)); + + if (hasWebYaml) { + genericContainer.withClasspathResourceMapping( + webYml, "/etc/prometheus/web.yaml", BindMode.READ_ONLY); + } + + return genericContainer; + } + + /** + * Method to create an application container + * + * @return the return value + */ + private GenericContainer createJavaAgentApplicationContainer() { + return new GenericContainer<>(javaDockerImage) + .waitingFor(Wait.forLogMessage(".*Running.*", 1)) + .withClasspathResourceMapping("common", "/temp", BindMode.READ_ONLY) + .withClasspathResourceMapping( + testClass.getName().replace(".", "/") + "/JavaAgent", + "/temp", + BindMode.READ_ONLY) + .withCreateContainerCmdModifier( + c -> + c.getHostConfig() + .withMemory(MEMORY_BYTES) + .withMemorySwap(MEMORY_SWAP_BYTES)) + .withCreateContainerCmdModifier( + c -> + c.getHostConfig() + .withUlimits( + new Ulimit[] { + new Ulimit("nofile", 65536L, 65536L) + })) + .withCommand("/bin/sh application.sh") + .withExposedPorts(8888) + .withLogConsumer( + outputFrame -> { + String string = outputFrame.getUtf8StringWithoutLineEnding().trim(); + if (!string.isBlank()) { + System.out.println(string); + } + }) + .withNetwork(network) + .withNetworkAliases("application") + .withStartupCheckStrategy(new IsRunningStartupCheckStrategy()) + .withStartupTimeout(Duration.ofMillis(30000)) + .withWorkingDirectory("/temp"); + } + + /** + * Method to create an application container + * + * @return the return value + */ + private GenericContainer createStandaloneApplicationContainer() { + return new GenericContainer<>(javaDockerImage) + .waitingFor(Wait.forLogMessage(".*Running.*", 1)) + .withClasspathResourceMapping("common", "/temp", BindMode.READ_ONLY) + .withClasspathResourceMapping( + testClass.getName().replace(".", "/") + "/Standalone", + "/temp", + BindMode.READ_ONLY) + .withCreateContainerCmdModifier( + c -> + c.getHostConfig() + .withMemory(MEMORY_BYTES) + .withMemorySwap(MEMORY_SWAP_BYTES)) + .withCreateContainerCmdModifier( + c -> + c.getHostConfig() + .withUlimits( + new Ulimit[] { + new Ulimit("nofile", 65536L, 65536L) + })) + .withCommand("/bin/sh application.sh") + .withExposedPorts(9999) + .withLogConsumer( + outputFrame -> { + String string = outputFrame.getUtf8StringWithoutLineEnding().trim(); + if (!string.isBlank()) { + System.out.println(string); + } + }) + .withNetwork(network) + .withNetworkAliases("application") + .withStartupCheckStrategy(new IsRunningStartupCheckStrategy()) + .withStartupTimeout(Duration.ofMillis(30000)) + .withWorkingDirectory("/temp") + .waitingFor(Wait.forLogMessage(".*Running.*", 1)); + } + + /** + * Method to create an exporter container + * + * @return the return value + */ + private GenericContainer createStandaloneExporterContainer() { + return new GenericContainer<>(javaDockerImage) + .waitingFor(Wait.forListeningPort()) + .withClasspathResourceMapping("common", "/temp", BindMode.READ_ONLY) + .withClasspathResourceMapping( + testClass.getName().replace(".", "/") + "/Standalone", + "/temp", + BindMode.READ_ONLY) + .withCreateContainerCmdModifier( + c -> + c.getHostConfig() + .withMemory(MEMORY_BYTES) + .withMemorySwap(MEMORY_SWAP_BYTES)) + .withCreateContainerCmdModifier( + c -> + c.getHostConfig() + .withUlimits( + new Ulimit[] { + new Ulimit("nofile", 65536L, 65536L) + })) + .withCommand("/bin/sh exporter.sh") + .withLogConsumer( + outputFrame -> { + String string = outputFrame.getUtf8StringWithoutLineEnding().trim(); + if (!string.isBlank()) { + System.out.println(string); + } + }) + .withNetwork(network) + .withNetworkAliases("exporter") + .withStartupCheckStrategy(new IsRunningStartupCheckStrategy()) + .withStartupTimeout(Duration.ofMillis(30000)) + .withWorkingDirectory("/temp") + .waitingFor(Wait.forLogMessage(".*Running.*", 1)); + } + + /** + * Method to create a Prometheus HttpClient + * + * @param genericContainer genericContainer + * @param baseUrl baseUrl + * @return the return value + */ + private static HttpClient createPrometheusHttpClient( + GenericContainer genericContainer, String baseUrl, int mappedPort) { + return new HttpClient(baseUrl + ":" + genericContainer.getMappedPort(mappedPort)); + } + + /** + * Method to determine if a resource exists + * + * @param resource resource + * @return true if the resource exists, else false + */ + private static boolean hasResource(String resource) { + boolean hasResource = false; + + if (!resource.startsWith("/")) { + resource = "/" + resource; + } + + InputStream inputStream = ResourceSupport.class.getResourceAsStream(resource); + if (inputStream != null) { + try (BufferedReader bufferedReader = + new BufferedReader( + new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { + while (true) { + String line = bufferedReader.readLine(); + if (line == null) { + break; + } + + hasResource = true; + break; + } + } catch (Throwable t) { + // DO NOTHING + } + } + + return hasResource; + } +} diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/PrometheusDockerImages.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/PrometheusDockerImages.java new file mode 100644 index 00000000..fa43020f --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/PrometheusDockerImages.java @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2023 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 + * + * http://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.opentelemetry; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Locale; +import java.util.Objects; +import java.util.function.Predicate; + +/** Class to implement PrometheusDockerImages */ +public final class PrometheusDockerImages { + + private static final String DOCKER_IMAGES_CONFIGURATION = "prometheus.docker.images"; + + private static final String DOCKER_IMAGES_RESOURCE = "/prometheus-docker-images.txt"; + + private static final String SMOKE_TEST_DOCKER_IMAGES_RESOURCE = + "/smoke-test-prometheus-docker-images.txt"; + + private static String[] ALL_DOCKER_IMAGE_NAMES; + + private static String[] SMOKE_TEST_DOCKER_IMAGES; + + /** Predicate to accept all Docker image names */ + public static final Predicate ACCEPT_ALL = name -> true; + + /** Constructor */ + private PrometheusDockerImages() { + // DO NOTHING + } + + /** + * Method to get Collection of all Docker image names + * + * @return the Collection of Docker image names + */ + public static Collection names() { + return names(ACCEPT_ALL); + } + + /** + * Method to get List of Docker image names filtered by a Predicate + * + * @param predicate predicate + * @return the List of Docker image names + */ + public static Collection names(Predicate predicate) { + Objects.requireNonNull(predicate); + + synchronized (PrometheusDockerImages.class) { + if (ALL_DOCKER_IMAGE_NAMES == null) { + ALL_DOCKER_IMAGE_NAMES = load(DOCKER_IMAGES_RESOURCE); + } + if (SMOKE_TEST_DOCKER_IMAGES == null) { + SMOKE_TEST_DOCKER_IMAGES = load(SMOKE_TEST_DOCKER_IMAGES_RESOURCE); + } + } + + String[] dockerImageNames; + + String dockerImageNameValue = + System.getenv( + DOCKER_IMAGES_CONFIGURATION.toUpperCase(Locale.ENGLISH).replace('.', '_')); + + if (dockerImageNameValue != null) { + dockerImageNameValue = dockerImageNameValue.trim(); + if (dockerImageNameValue.isBlank()) { + dockerImageNameValue = null; + } + } + + if (dockerImageNameValue == null) { + dockerImageNameValue = System.getProperty(DOCKER_IMAGES_CONFIGURATION); + if (dockerImageNameValue != null) { + if (dockerImageNameValue.isBlank()) { + dockerImageNameValue = null; + } + } + } + + if (dockerImageNameValue == null) { + dockerImageNames = SMOKE_TEST_DOCKER_IMAGES; + } else if (dockerImageNameValue.equalsIgnoreCase("ALL")) { + dockerImageNames = ALL_DOCKER_IMAGE_NAMES; + } else { + dockerImageNames = dockerImageNameValue.split("\\s+"); + } + + Collection dockerImageNamesCollection = new ArrayList<>(); + for (String dockerImageName : dockerImageNames) { + if (predicate.test(dockerImageName)) { + dockerImageNamesCollection.add(dockerImageName); + } + } + + return Collections.unmodifiableCollection(dockerImageNamesCollection); + } + + /** + * Method to load the list of Docker image names from a resource + * + * @param resource resource + * @return the String array of lines + */ + private static String[] load(String resource) { + Collection dockerImageNames = new ArrayList<>(); + BufferedReader bufferedReader; + + try { + bufferedReader = + new BufferedReader( + new InputStreamReader( + PrometheusDockerImages.class.getResourceAsStream(resource), + StandardCharsets.UTF_8)); + + while (true) { + String line = bufferedReader.readLine(); + + if (line == null) { + break; + } + + if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { + dockerImageNames.add(line.trim()); + } + } + + return dockerImageNames.toArray(new String[0]); + } catch (IOException e) { + throw new RuntimeException("Exception reading resource " + DOCKER_IMAGES_RESOURCE, e); + } + } +} diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest.java new file mode 100644 index 00000000..8b55da0d --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest.java @@ -0,0 +1,234 @@ +package io.prometheus.jmx.test.opentelemetry.authentication; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.prometheus.jmx.test.opentelemetry.ExpectedMetricsNames; +import io.prometheus.jmx.test.opentelemetry.OpenTelemetryTestEnvironment; +import io.prometheus.jmx.test.opentelemetry.PrometheusDockerImages; +import io.prometheus.jmx.test.support.JavaDockerImages; +import io.prometheus.jmx.test.support.JmxExporterMode; +import io.prometheus.jmx.test.support.http.HttpBasicAuthenticationCredentials; +import io.prometheus.jmx.test.support.http.HttpRequest; +import io.prometheus.jmx.test.support.http.HttpResponse; +import io.prometheus.jmx.test.support.throttle.ExponentialBackoffThrottle; +import io.prometheus.jmx.test.support.throttle.Throttle; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Stream; +import org.antublue.verifyica.api.ArgumentContext; +import org.antublue.verifyica.api.Verifyica; +import org.junit.jupiter.api.Assertions; +import org.testcontainers.containers.Network; +import org.testcontainers.shaded.org.yaml.snakeyaml.Yaml; + +/** Class to implement OpenTelemetryBasicAuthenticationTest */ +public class OpenTelemetryBasicAuthenticationTest { + + private static final String NETWORK = "network"; + private static final String VALID_USER = "Prometheus"; + private static final String VALUE_PASSWORD = "secret"; + + /** + * Method to get the Stream of test environments + * + * @return the Stream of test environments + */ + @Verifyica.ArgumentSupplier(parallelism = 2) + public static Stream arguments() { + Collection openTelemetryTestEnvironments = new ArrayList<>(); + + PrometheusDockerImages.names() + .forEach( + prometheusDockerImage -> + JavaDockerImages.names() + .forEach( + javaDockerImageName -> { + for (JmxExporterMode jmxExporterMode : + JmxExporterMode.values()) { + openTelemetryTestEnvironments.add( + new OpenTelemetryTestEnvironment( + prometheusDockerImage, + javaDockerImageName, + jmxExporterMode)); + } + })); + + return openTelemetryTestEnvironments.stream(); + } + + @Verifyica.BeforeAll + public void beforeAll(ArgumentContext argumentContext) { + // Create a Network and get the id to force the network creation + Network network = Network.newNetwork(); + network.getId(); + + argumentContext.getStore().put(NETWORK, network); + + Class testClass = argumentContext.getClassContext().getTestClass(); + + OpenTelemetryTestEnvironment openTelemetryTestEnvironment = + argumentContext.getTestArgument(OpenTelemetryTestEnvironment.class).getPayload(); + + openTelemetryTestEnvironment.initialize(testClass, network); + } + + /** + * Method to test that Prometheus is up + * + * @param argumentContext argumentContext + */ + @Verifyica.Test + @Verifyica.Order(order = 0) + public void testIsPrometheusUp(ArgumentContext argumentContext) { + OpenTelemetryTestEnvironment openTelemetryTestEnvironment = + argumentContext.getTestArgument(OpenTelemetryTestEnvironment.class).getPayload(); + + Throttle throttle = new ExponentialBackoffThrottle(100, 5000); + AtomicBoolean success = new AtomicBoolean(); + + for (int i = 0; i < 10; i++) { + sendPrometheusQuery(openTelemetryTestEnvironment, "up") + .accept( + httpResponse -> { + assertThat(httpResponse).isNotNull(); + + if (httpResponse.statusCode() != 200) { + return; + } + + assertThat(httpResponse.body()).isNotNull(); + assertThat(httpResponse.body().string()).isNotNull(); + + Map map = + new Yaml().load(httpResponse.body().string()); + + String status = (String) map.get("status"); + assertThat(status).isEqualTo("success"); + + success.set(true); + }); + + if (success.get()) { + break; + } + + throttle.throttle(); + } + + if (!success.get()) { + Assertions.fail("Prometheus is not up"); + } + } + + /** + * Method to test that metrics exist in Prometheus + * + * @param argumentContext argumentContext + */ + @Verifyica.Test + public void testPrometheusHasMetrics(ArgumentContext argumentContext) { + OpenTelemetryTestEnvironment openTelemetryTestEnvironment = + argumentContext.getTestArgument(OpenTelemetryTestEnvironment.class).getPayload(); + + ExpectedMetricsNames.getMetricsNames().stream() + .filter( + metricName -> + (openTelemetryTestEnvironment.getJmxExporterMode() + != JmxExporterMode.Standalone + || !metricName.startsWith("jvm_")) + && !metricName.startsWith("process_")) + .forEach( + metricName -> { + Double value = + getPrometheusMetric(openTelemetryTestEnvironment, metricName); + assertThat(value).as("metricName [%s]", metricName).isNotNull(); + assertThat(value).as("metricName [%s]", metricName).isEqualTo(1); + }); + } + + @Verifyica.AfterAll + public void afterAll(ArgumentContext argumentContext) { + Optional.ofNullable(argumentContext.getTestArgument(OpenTelemetryTestEnvironment.class)) + .ifPresent( + openTelemetryTestEnvironmentArgument -> + openTelemetryTestEnvironmentArgument.getPayload().destroy()); + + Optional.ofNullable(argumentContext.getStore().remove(NETWORK, Network.class)) + .ifPresent(Network::close); + } + + /** + * Method to get a Prometheus metric + * + * @param openTelemetryTestEnvironment openTelemetryTestEnvironment + * @param metricName metricName + * @return the metric value, or null if it doesn't exist + */ + protected Double getPrometheusMetric( + OpenTelemetryTestEnvironment openTelemetryTestEnvironment, String metricName) { + Throttle throttle = new ExponentialBackoffThrottle(100, 5000); + AtomicReference value = new AtomicReference<>(); + + for (int i = 0; i < 10; i++) { + sendPrometheusQuery(openTelemetryTestEnvironment, metricName) + .accept( + httpResponse -> { + assertThat(httpResponse).isNotNull(); + assertThat(httpResponse.statusCode()).isEqualTo(200); + assertThat(httpResponse.body()).isNotNull(); + assertThat(httpResponse.body().string()).isNotNull(); + + // TODO parse response and return value + if (httpResponse.body().string().contains(metricName)) { + value.set(1.0); + } + }); + + if (value.get() != null) { + break; + } + + throttle.throttle(); + } + + return value.get(); + } + + /** + * Method to send a Prometheus query + * + * @param openTelemetryTestEnvironment openTelemetryTestEnvironment + * @param query query + * @return an HttpResponse + */ + protected HttpResponse sendPrometheusQuery( + OpenTelemetryTestEnvironment openTelemetryTestEnvironment, String query) { + return sendRequest( + openTelemetryTestEnvironment, + "/api/v1/query?query=" + URLEncoder.encode(query, StandardCharsets.UTF_8)); + } + + /** + * Method to send a Http GET request + * + * @param openTelemetryTestEnvironment openTelemetryTestEnvironment + * @param path path + * @return an HttpResponse + */ + protected HttpResponse sendRequest( + OpenTelemetryTestEnvironment openTelemetryTestEnvironment, String path) { + return openTelemetryTestEnvironment + .getPrometheusHttpClient() + .send( + new HttpRequest(path) + .credentials( + new HttpBasicAuthenticationCredentials( + VALID_USER, VALUE_PASSWORD))); + } +} diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/rmi/ssl/MinimalRMISSLTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/rmi/ssl/MinimalRMISSLTest.java index 34643ea9..0a9043f5 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/rmi/ssl/MinimalRMISSLTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/rmi/ssl/MinimalRMISSLTest.java @@ -19,138 +19,114 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; -import io.prometheus.jmx.test.AbstractTest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.TestArguments; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; +import java.util.Map; +import java.util.function.BiConsumer; import java.util.stream.Stream; -import org.antublue.test.engine.api.TestEngine; +import org.antublue.verifyica.api.Verifyica; -public class MinimalRMISSLTest extends AbstractTest implements Consumer { +public class MinimalRMISSLTest extends AbstractExporterTest + implements BiConsumer { /** - * Method to get the list of TestArguments + * Method to get the Stream of test environments * - * @return the return value + * @return the Stream of test environments */ - @TestEngine.ArgumentSupplier - public static Stream arguments() { + @Verifyica.ArgumentSupplier + public static Stream arguments() { // Filter the arguments.. // // 1. only run the Standalone exporter // 2. filter out the GraalVM 1.8 JVM - exception is that SunJSSE is not found // 3. filter out all ibmjava* JVMs - exception is that SunJSSE is not found // - return AbstractTest.arguments() - .filter(testArgument -> testArgument.getName().contains("Standalone")) + return AbstractExporterTest.arguments() .filter( - testArgument1 -> - !testArgument1.getDockerImageName().contains("graalvm/jdk:java8")) - .filter(testArgument1 -> !testArgument1.getDockerImageName().contains("ibmjava")); - } - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); + exporterTestEnvironment -> + exporterTestEnvironment.getName().contains("Standalone")) + .filter( + exporterTestEnvironment -> + !exporterTestEnvironment + .getJavaDockerImage() + .contains("graalvm/jdk:java8")) + .filter( + exporterTestEnvironment -> + !exporterTestEnvironment.getJavaDockerImage().contains("ibmjava")); } @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/rmi/ssl/RMIRegistrySSLDisabledTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/rmi/ssl/RMIRegistrySSLDisabledTest.java index fc995b6d..9e9b8397 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/rmi/ssl/RMIRegistrySSLDisabledTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/rmi/ssl/RMIRegistrySSLDisabledTest.java @@ -19,138 +19,114 @@ import static io.prometheus.jmx.test.support.http.HttpResponseAssertions.assertHttpMetricsResponse; import static io.prometheus.jmx.test.support.metrics.MetricAssertion.assertMetric; -import io.prometheus.jmx.test.AbstractTest; +import io.prometheus.jmx.test.common.AbstractExporterTest; +import io.prometheus.jmx.test.common.ExporterTestEnvironment; import io.prometheus.jmx.test.support.JmxExporterMode; -import io.prometheus.jmx.test.support.TestArguments; -import io.prometheus.jmx.test.support.http.HttpHealthyRequest; -import io.prometheus.jmx.test.support.http.HttpMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpOpenMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusMetricsRequest; -import io.prometheus.jmx.test.support.http.HttpPrometheusProtobufMetricsRequest; import io.prometheus.jmx.test.support.http.HttpResponse; -import io.prometheus.jmx.test.support.http.HttpResponseAssertions; import io.prometheus.jmx.test.support.metrics.Metric; import io.prometheus.jmx.test.support.metrics.MetricsParser; import java.util.Collection; -import java.util.function.Consumer; +import java.util.Map; +import java.util.function.BiConsumer; import java.util.stream.Stream; -import org.antublue.test.engine.api.TestEngine; +import org.antublue.verifyica.api.Verifyica; -public class RMIRegistrySSLDisabledTest extends AbstractTest implements Consumer { +public class RMIRegistrySSLDisabledTest extends AbstractExporterTest + implements BiConsumer { /** - * Method to get the list of TestArguments + * Method to get the Stream of test environments * - * @return the return value + * @return the Stream of test environments */ - @TestEngine.ArgumentSupplier - public static Stream arguments() { + @Verifyica.ArgumentSupplier + public static Stream arguments() { // Filter the arguments.. // // 1. only run the Standalone exporter // 2. filter out the GraalVM 1.8 JVM - exception is that SunJSSE is not found // 3. filter out all ibmjava* JVMs - exception is that SunJSSE is not found // - return AbstractTest.arguments() - .filter(testArgument -> testArgument.getName().contains("Standalone")) + return AbstractExporterTest.arguments() .filter( - testArgument1 -> - !testArgument1.getDockerImageName().contains("graalvm/jdk:java8")) - .filter(testArgument1 -> !testArgument1.getDockerImageName().contains("ibmjava")); - } - - @TestEngine.Test - public void testHealthy() { - new HttpHealthyRequest() - .send(testEnvironment.getHttpClient()) - .accept(HttpResponseAssertions::assertHttpHealthyResponse); - } - - @TestEngine.Test - public void testMetrics() { - new HttpMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsOpenMetricsFormat() { - new HttpOpenMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusFormat() { - new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient()).accept(this); - } - - @TestEngine.Test - public void testMetricsPrometheusProtobufFormat() { - new HttpPrometheusProtobufMetricsRequest() - .send(testEnvironment.getHttpClient()) - .accept(this); + exporterTestEnvironment -> + exporterTestEnvironment.getName().contains("Standalone")) + .filter( + exporterTestEnvironment -> + !exporterTestEnvironment + .getJavaDockerImage() + .contains("graalvm/jdk:java8")) + .filter( + exporterTestEnvironment -> + !exporterTestEnvironment.getJavaDockerImage().contains("ibmjava")); } @Override - public void accept(HttpResponse httpResponse) { + public void accept(ExporterTestEnvironment exporterTestEnvironment, HttpResponse httpResponse) { assertHttpMetricsResponse(httpResponse); - Collection metrics = MetricsParser.parse(httpResponse); + Map> metrics = MetricsParser.parseMap(httpResponse); + + boolean isJmxExporterModeJavaAgent = + exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent; String buildInfoName = - testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent + isJmxExporterModeJavaAgent ? "jmx_prometheus_javaagent" - : "jmx_prometheus_httpserver"; + : "jmx_prometheus_standalone"; assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_exporter_build_info") .withLabel("name", buildInfoName) .withValue(1d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jmx_scrape_error") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("COUNTER") + .ofType(Metric.Type.COUNTER) .withName("jmx_config_reload_success_total") .withValue(0d) .isPresent(); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isPresent(testArguments.getJmxExporterMode() == JmxExporterMode.JavaAgent); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "nonheap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("GAUGE") + .ofType(Metric.Type.GAUGE) .withName("jvm_memory_used_bytes") .withLabel("area", "heap") - .isNotPresent(testArguments.getJmxExporterMode() == JmxExporterMode.Standalone); + .isPresentWhen(isJmxExporterModeJavaAgent); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") .withLabel("source", "/dev/sda1") .withValue(7.516192768E9d) .isPresent(); assertMetric(metrics) - .ofType("UNTYPED") + .ofType(Metric.Type.UNTYPED) .withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") .withLabel("source", "/dev/sda2") .withValue(0.8d) diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/AutoIncrementingMBeanTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/AutoIncrementingMBeanTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/AutoIncrementingMBeanTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/AutoIncrementingMBeanTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/BlacklistObjectNamesTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/BlacklistObjectNamesTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/BlacklistObjectNamesTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/BlacklistObjectNamesTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/CompositeKeyDataTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/CompositeKeyDataTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/CompositeKeyDataTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/CompositeKeyDataTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/DisableAutoExcludeObjectNameAttributesTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/DisableAutoExcludeObjectNameAttributesTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/DisableAutoExcludeObjectNameAttributesTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/DisableAutoExcludeObjectNameAttributesTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/ExcludeObjectNameAttributesTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/ExcludeObjectNameAttributesTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/ExcludeObjectNameAttributesTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/ExcludeObjectNameAttributesTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/ExcludeObjectNamesTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/ExcludeObjectNamesTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/ExcludeObjectNamesTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/ExcludeObjectNamesTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/IncludeAndExcludeObjectNamesTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/IncludeAndExcludeObjectNamesTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/IncludeAndExcludeObjectNamesTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/IncludeAndExcludeObjectNamesTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/IncludeObjectNamesTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/IncludeObjectNamesTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/IncludeObjectNamesTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/IncludeObjectNamesTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/LowerCaseOutputAndLabelNamesTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/LowerCaseOutputAndLabelNamesTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/LowerCaseOutputAndLabelNamesTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/LowerCaseOutputAndLabelNamesTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/LowerCaseOutputLabelNamesTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/LowerCaseOutputLabelNamesTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/LowerCaseOutputLabelNamesTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/LowerCaseOutputLabelNamesTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/LowerCaseOutputNamesTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/LowerCaseOutputNamesTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/LowerCaseOutputNamesTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/LowerCaseOutputNamesTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/MinimalTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/MinimalTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/MinimalTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/MinimalTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/OptionalValueMBeanTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/OptionalValueMBeanTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/OptionalValueMBeanTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/OptionalValueMBeanTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/WhitelistAndBlacklistObjectNamesTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/WhitelistAndBlacklistObjectNamesTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/WhitelistAndBlacklistObjectNamesTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/WhitelistAndBlacklistObjectNamesTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/WhitelistObjectNamesTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/WhitelistObjectNamesTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/WhitelistObjectNamesTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/WhitelistObjectNamesTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/CompleteHttpServerConfigurationTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/CompleteHttpServerConfigurationTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/CompleteHttpServerConfigurationTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/CompleteHttpServerConfigurationTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA1Test/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA1Test/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA1Test/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA1Test/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA256Test/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA256Test/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA256Test/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA256Test/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA512Test/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA512Test/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA512Test/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPBKDF2WithHmacSHA512Test/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPlaintextTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPlaintextTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPlaintextTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationPlaintextTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA1Test/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA1Test/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA1Test/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA1Test/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA256Test/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA256Test/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA256Test/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA256Test/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA512Test/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA512Test/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA512Test/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/authentication/BasicAuthenticationSHA512Test/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLAndBasicAuthenticationPBKDF2WithHmacSHA512Test/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLAndBasicAuthenticationPBKDF2WithHmacSHA512Test/Standalone/exporter.sh index 30d75027..1a8f7542 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLAndBasicAuthenticationPBKDF2WithHmacSHA512Test/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLAndBasicAuthenticationPBKDF2WithHmacSHA512Test/Standalone/exporter.sh @@ -4,4 +4,4 @@ java \ -Xmx512M \ -Djavax.net.ssl.keyStore=localhost.jks \ -Djavax.net.ssl.keyStorePassword=changeit \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreMultipleCertificatesTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreMultipleCertificatesTest/Standalone/exporter.sh index 30d75027..1a8f7542 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreMultipleCertificatesTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreMultipleCertificatesTest/Standalone/exporter.sh @@ -4,4 +4,4 @@ java \ -Xmx512M \ -Djavax.net.ssl.keyStore=localhost.jks \ -Djavax.net.ssl.keyStorePassword=changeit \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest/Standalone/exporter.sh index 30d75027..1a8f7542 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest/Standalone/exporter.sh @@ -4,4 +4,4 @@ java \ -Xmx512M \ -Djavax.net.ssl.keyStore=localhost.jks \ -Djavax.net.ssl.keyStorePassword=changeit \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest2/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest2/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest2/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithJKSKeyStoreTest2/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreMultipleCertificatesTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreMultipleCertificatesTest/Standalone/exporter.sh index 678c7c2f..b89329fc 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreMultipleCertificatesTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreMultipleCertificatesTest/Standalone/exporter.sh @@ -4,4 +4,4 @@ java \ -Xmx512M \ -Djavax.net.ssl.keyStore=localhost.pkcs12 \ -Djavax.net.ssl.keyStorePassword=changeit \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest/Standalone/exporter.sh index 678c7c2f..b89329fc 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest/Standalone/exporter.sh @@ -4,4 +4,4 @@ java \ -Xmx512M \ -Djavax.net.ssl.keyStore=localhost.pkcs12 \ -Djavax.net.ssl.keyStorePassword=changeit \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest2/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest2/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest2/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/ssl/SSLWithPKCS12KeyStoreTest2/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/threads/ThreadsConfigurationTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/threads/ThreadsConfigurationTest/Standalone/exporter.sh index a04f3b63..e05198da 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/threads/ThreadsConfigurationTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/http/threads/ThreadsConfigurationTest/Standalone/exporter.sh @@ -2,4 +2,4 @@ java \ -Xmx512M \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/JavaAgent/application.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/JavaAgent/application.sh new file mode 100644 index 00000000..da8a6a08 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/JavaAgent/application.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +java \ + -Xmx512M \ + -javaagent:jmx_prometheus_javaagent.jar=exporter.yaml \ + -jar jmx_example_application.jar \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/JavaAgent/exporter.yaml b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/JavaAgent/exporter.yaml new file mode 100644 index 00000000..46567227 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/JavaAgent/exporter.yaml @@ -0,0 +1,6 @@ +openTelemetry: + endpoint: http://prometheus:9090/api/v1/otlp + protocol: http/protobuf + interval: 1 +rules: + - pattern: ".*" \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/JavaAgent/prometheus.yaml b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/JavaAgent/prometheus.yaml new file mode 100644 index 00000000..5b174f8e --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/JavaAgent/prometheus.yaml @@ -0,0 +1,4 @@ +global: + scrape_interval: 15s # Default scrape interval, not used since there are no scrape targets + +scrape_configs: [] # Empty scrape_configs means no targets to scrape \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/Standalone/application.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/Standalone/application.sh new file mode 100644 index 00000000..80c2b344 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/Standalone/application.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +java \ + -Xmx512M \ + -Dcom.sun.management.jmxremote=true \ + -Dcom.sun.management.jmxremote.authenticate=false \ + -Dcom.sun.management.jmxremote.local.only=false \ + -Dcom.sun.management.jmxremote.port=9999 \ + -Dcom.sun.management.jmxremote.registry.ssl=false \ + -Dcom.sun.management.jmxremote.rmi.port=9999 \ + -Dcom.sun.management.jmxremote.ssl.need.client.auth=false \ + -Dcom.sun.management.jmxremote.ssl=false \ + -jar jmx_example_application.jar \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/Standalone/exporter.sh new file mode 100644 index 00000000..919076de --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/Standalone/exporter.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +java \ + -Xmx512M \ + -jar jmx_prometheus_standalone.jar exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/Standalone/exporter.yaml b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/Standalone/exporter.yaml new file mode 100644 index 00000000..5f35cee0 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/Standalone/exporter.yaml @@ -0,0 +1,7 @@ +openTelemetry: + endpoint: http://prometheus:9090/api/v1/otlp + protocol: http/protobuf + interval: 1 +hostPort: application:9999 +rules: + - pattern: ".*" \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/Standalone/prometheus.yaml b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/Standalone/prometheus.yaml new file mode 100644 index 00000000..5b174f8e --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/OpenTelemetryTest/Standalone/prometheus.yaml @@ -0,0 +1,4 @@ +global: + scrape_interval: 15s # Default scrape interval, not used since there are no scrape targets + +scrape_configs: [] # Empty scrape_configs means no targets to scrape \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/JavaAgent/application.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/JavaAgent/application.sh new file mode 100644 index 00000000..da8a6a08 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/JavaAgent/application.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +java \ + -Xmx512M \ + -javaagent:jmx_prometheus_javaagent.jar=exporter.yaml \ + -jar jmx_example_application.jar \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/JavaAgent/exporter.yaml b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/JavaAgent/exporter.yaml new file mode 100644 index 00000000..dea4916f --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/JavaAgent/exporter.yaml @@ -0,0 +1,8 @@ +openTelemetry: + endpoint: http://prometheus:9090/api/v1/otlp + protocol: http/protobuf + interval: 1 + headers: + Authorization: "Basic UHJvbWV0aGV1czpzZWNyZXQ=" +rules: + - pattern: ".*" \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/JavaAgent/prometheus.yaml b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/JavaAgent/prometheus.yaml new file mode 100644 index 00000000..5b174f8e --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/JavaAgent/prometheus.yaml @@ -0,0 +1,4 @@ +global: + scrape_interval: 15s # Default scrape interval, not used since there are no scrape targets + +scrape_configs: [] # Empty scrape_configs means no targets to scrape \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/JavaAgent/web.yaml b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/JavaAgent/web.yaml new file mode 100644 index 00000000..1aecd62a --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/JavaAgent/web.yaml @@ -0,0 +1,2 @@ +basic_auth_users: + Prometheus: $2y$10$ocnnaD337.WxiugU0ho92eBkX4Eq7/ZntVgwhgwlW5m2EvnOC9n62 \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/application.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/application.sh new file mode 100644 index 00000000..80c2b344 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/application.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +java \ + -Xmx512M \ + -Dcom.sun.management.jmxremote=true \ + -Dcom.sun.management.jmxremote.authenticate=false \ + -Dcom.sun.management.jmxremote.local.only=false \ + -Dcom.sun.management.jmxremote.port=9999 \ + -Dcom.sun.management.jmxremote.registry.ssl=false \ + -Dcom.sun.management.jmxremote.rmi.port=9999 \ + -Dcom.sun.management.jmxremote.ssl.need.client.auth=false \ + -Dcom.sun.management.jmxremote.ssl=false \ + -jar jmx_example_application.jar \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/exporter.sh new file mode 100644 index 00000000..919076de --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/exporter.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +java \ + -Xmx512M \ + -jar jmx_prometheus_standalone.jar exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/exporter.yaml b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/exporter.yaml new file mode 100644 index 00000000..ddc06c96 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/exporter.yaml @@ -0,0 +1,9 @@ +openTelemetry: + endpoint: http://prometheus:9090/api/v1/otlp + protocol: http/protobuf + interval: 1 + headers: + Authorization: "Basic UHJvbWV0aGV1czpzZWNyZXQ=" +hostPort: application:9999 +rules: + - pattern: ".*" \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/prometheus.yaml b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/prometheus.yaml new file mode 100644 index 00000000..5b174f8e --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/prometheus.yaml @@ -0,0 +1,4 @@ +global: + scrape_interval: 15s # Default scrape interval, not used since there are no scrape targets + +scrape_configs: [] # Empty scrape_configs means no targets to scrape \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/web.yaml b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/web.yaml new file mode 100644 index 00000000..1aecd62a --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/opentelemetry/authentication/OpenTelemetryBasicAuthenticationTest/Standalone/web.yaml @@ -0,0 +1,2 @@ +basic_auth_users: + Prometheus: $2y$10$ocnnaD337.WxiugU0ho92eBkX4Eq7/ZntVgwhgwlW5m2EvnOC9n62 \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/rmi/ssl/MinimalRMISSLTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/rmi/ssl/MinimalRMISSLTest/Standalone/exporter.sh index c931894d..b7a975fa 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/rmi/ssl/MinimalRMISSLTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/rmi/ssl/MinimalRMISSLTest/Standalone/exporter.sh @@ -8,4 +8,4 @@ java \ -Djavax.net.ssl.trustStore=localhost.pkcs12 \ -Djavax.net.ssl.trustStorePassword=changeit \ -Djavax.net.ssl.trustStoreType=pkcs12 \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/rmi/ssl/RMIRegistrySSLDisabledTest/Standalone/exporter.sh b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/rmi/ssl/RMIRegistrySSLDisabledTest/Standalone/exporter.sh index 55e42317..0828cecd 100644 --- a/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/rmi/ssl/RMIRegistrySSLDisabledTest/Standalone/exporter.sh +++ b/integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/rmi/ssl/RMIRegistrySSLDisabledTest/Standalone/exporter.sh @@ -10,4 +10,4 @@ java \ -Djavax.net.ssl.trustStore=localhost.pkcs12 \ -Djavax.net.ssl.trustStorePassword=changeit \ -Djavax.net.ssl.trustStoreType=pkcs12 \ - -jar jmx_prometheus_httpserver.jar 8888 exporter.yaml \ No newline at end of file + -jar jmx_prometheus_standalone.jar 8888 exporter.yaml \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/docker-image-names.all.txt b/integration_test_suite/integration_tests/src/test/resources/java-docker-images.txt similarity index 98% rename from integration_test_suite/integration_tests/src/test/resources/docker-image-names.all.txt rename to integration_test_suite/integration_tests/src/test/resources/java-docker-images.txt index 3653b614..f446e289 100644 --- a/integration_test_suite/integration_tests/src/test/resources/docker-image-names.all.txt +++ b/integration_test_suite/integration_tests/src/test/resources/java-docker-images.txt @@ -70,6 +70,8 @@ openjdk:11 openjdk:17 openjdk:21 openjdk:22 +openjdk:23 +openjdk:24 registry.access.redhat.com/ubi8/openjdk-8-runtime:latest registry.access.redhat.com/ubi8/openjdk-11-runtime:latest registry.access.redhat.com/ubi8/openjdk-17-runtime:latest @@ -80,4 +82,4 @@ registry.access.redhat.com/ubi9/openjdk-21-runtime:latest sapmachine:11 sapmachine:17 sapmachine:21 -sapmachine:22 +sapmachine:22 \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/prometheus-docker-images.txt b/integration_test_suite/integration_tests/src/test/resources/prometheus-docker-images.txt new file mode 100644 index 00000000..4f0b28b8 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/prometheus-docker-images.txt @@ -0,0 +1,7 @@ +prom/prometheus:v2.47.2 +prom/prometheus:v2.48.1 +prom/prometheus:v2.49.1 +prom/prometheus:v2.50.1 +prom/prometheus:v2.51.2 +prom/prometheus:v2.52.0 +prom/prometheus:v2.53.1 \ No newline at end of file diff --git a/integration_test_suite/integration_tests/src/test/resources/docker-image-names.smoke-test.txt b/integration_test_suite/integration_tests/src/test/resources/smoke-test-java-docker-images.txt similarity index 100% rename from integration_test_suite/integration_tests/src/test/resources/docker-image-names.smoke-test.txt rename to integration_test_suite/integration_tests/src/test/resources/smoke-test-java-docker-images.txt diff --git a/integration_test_suite/integration_tests/src/test/resources/smoke-test-prometheus-docker-images.txt b/integration_test_suite/integration_tests/src/test/resources/smoke-test-prometheus-docker-images.txt new file mode 100644 index 00000000..6cfaa5a0 --- /dev/null +++ b/integration_test_suite/integration_tests/src/test/resources/smoke-test-prometheus-docker-images.txt @@ -0,0 +1 @@ +prom/prometheus:v2.53.1 \ No newline at end of file diff --git a/integration_test_suite/jmx_example_application/pom.xml b/integration_test_suite/jmx_example_application/pom.xml index bbd389bf..32b1dd47 100644 --- a/integration_test_suite/jmx_example_application/pom.xml +++ b/integration_test_suite/jmx_example_application/pom.xml @@ -50,6 +50,7 @@ com.diffplug.spotless spotless-maven-plugin + 2.43.0 @@ -62,7 +63,7 @@ - check + apply compile diff --git a/integration_test_suite/pull-docker-images.sh b/integration_test_suite/pull-docker-images.sh new file mode 100755 index 00000000..49bcce7f --- /dev/null +++ b/integration_test_suite/pull-docker-images.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +PWD="$PWD" +function exit_trap() { + cd "${PWD}" + echo $? +} +trap exit_trap EXIT +SCRIPT_DIRECTORY=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) +cd "${SCRIPT_DIRECTORY}" + +function check_exit_code() { + if [ "$?" != "0" ]; + then + echo "Failed to pull Docker image ${1}"; + exit $? + fi +} + +./pull-java-docker-images.sh +./pull-prometheus-docker-images.sh \ No newline at end of file diff --git a/integration_test_suite/docker-pull-images.all.sh b/integration_test_suite/pull-java-docker-images.sh similarity index 79% rename from integration_test_suite/docker-pull-images.all.sh rename to integration_test_suite/pull-java-docker-images.sh index 1464ce1f..b7c90fd0 100755 --- a/integration_test_suite/docker-pull-images.all.sh +++ b/integration_test_suite/pull-java-docker-images.sh @@ -17,7 +17,7 @@ function check_exit_code() { fi } -grep -v '^#' integration_tests/src/test/resources/docker-image-names.all.txt | while read -r LINE; +grep -v '^#' integration_tests/src/test/resources/java-docker-images.txt | while read -r LINE; do docker pull "${LINE}" check_exit_code "${LINE}" diff --git a/integration_test_suite/docker-pull-images.smoke-test.sh b/integration_test_suite/pull-prometheus-docker-images.sh similarity index 78% rename from integration_test_suite/docker-pull-images.smoke-test.sh rename to integration_test_suite/pull-prometheus-docker-images.sh index 5f25e001..586363ce 100755 --- a/integration_test_suite/docker-pull-images.smoke-test.sh +++ b/integration_test_suite/pull-prometheus-docker-images.sh @@ -17,7 +17,7 @@ function check_exit_code() { fi } -grep -v '^#' integration_tests/src/test/resources/docker-image-names.smoke-test.txt | while read -r LINE; +grep -v '^#' integration_tests/src/test/resources/prometheus-docker-images.txt | while read -r LINE; do docker pull "${LINE}" check_exit_code "${LINE}" diff --git a/integration_test_suite/pull-smoke-test-docker-images.sh b/integration_test_suite/pull-smoke-test-docker-images.sh new file mode 100755 index 00000000..a6b0f105 --- /dev/null +++ b/integration_test_suite/pull-smoke-test-docker-images.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +PWD="$PWD" +function exit_trap() { + cd "${PWD}" + echo $? +} +trap exit_trap EXIT +SCRIPT_DIRECTORY=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) +cd "${SCRIPT_DIRECTORY}" + +function check_exit_code() { + if [ "$?" != "0" ]; + then + echo "Failed to pull Docker image ${1}"; + exit $? + fi +} + +./pull-smoke-test-java-docker-images.sh +./pull-smoke-test-prometheus-docker-images.sh \ No newline at end of file diff --git a/integration_test_suite/pull-smoke-test-java-docker-images.sh b/integration_test_suite/pull-smoke-test-java-docker-images.sh new file mode 100755 index 00000000..27a44de7 --- /dev/null +++ b/integration_test_suite/pull-smoke-test-java-docker-images.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +PWD="$PWD" +function exit_trap() { + cd "${PWD}" + echo $? +} +trap exit_trap EXIT +SCRIPT_DIRECTORY=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) +cd "${SCRIPT_DIRECTORY}" + +function check_exit_code() { + if [ "$?" != "0" ]; + then + echo "Failed to pull Docker image ${1}"; + exit $? + fi +} + +grep -v '^#' integration_tests/src/test/resources/smoke-test-java-docker-images.txt | while read -r LINE; +do + docker pull "${LINE}" + check_exit_code "${LINE}" +done diff --git a/integration_test_suite/pull-smoke-test-prometheus-docker-images.sh b/integration_test_suite/pull-smoke-test-prometheus-docker-images.sh new file mode 100755 index 00000000..fec23a4f --- /dev/null +++ b/integration_test_suite/pull-smoke-test-prometheus-docker-images.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +PWD="$PWD" +function exit_trap() { + cd "${PWD}" + echo $? +} +trap exit_trap EXIT +SCRIPT_DIRECTORY=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) +cd "${SCRIPT_DIRECTORY}" + +function check_exit_code() { + if [ "$?" != "0" ]; + then + echo "Failed to pull Docker image ${1}"; + exit $? + fi +} + +grep -v '^#' integration_tests/src/test/resources/smoke-test-prometheus-docker-images.txt | while read -r LINE; +do + docker pull "${LINE}" + check_exit_code "${LINE}" +done diff --git a/jmx_prometheus_common/pom.xml b/jmx_prometheus_common/pom.xml index 95c242ae..57ef7903 100644 --- a/jmx_prometheus_common/pom.xml +++ b/jmx_prometheus_common/pom.xml @@ -8,7 +8,6 @@ 1.x.x - io.prometheus.jmx jmx_prometheus_common Prometheus JMX Exporter - Common @@ -56,7 +55,7 @@ - check + apply compile @@ -78,6 +77,10 @@ io.prometheus prometheus-metrics-exporter-httpserver + + io.prometheus + prometheus-metrics-exporter-opentelemetry + io.prometheus.jmx collector diff --git a/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/configuration/ConvertToMap.java b/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/configuration/ConvertToMap.java new file mode 100644 index 00000000..913ad1ef --- /dev/null +++ b/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/configuration/ConvertToMap.java @@ -0,0 +1,41 @@ +package io.prometheus.jmx.common.configuration; + +import io.prometheus.jmx.common.util.Precondition; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Supplier; + +/** + * Class to convert an Object to a Map, throwing a RuntimeException from the Supplier if there is a + * ClassCastException + */ +@SuppressWarnings("unchecked") +public class ConvertToMap implements Function> { + + private final Supplier supplier; + + /** + * Constructor + * + * @param supplier supplier + */ + public ConvertToMap(Supplier supplier) { + Precondition.notNull(supplier); + this.supplier = supplier; + } + + @Override + public Map apply(Object o) { + try { + Map result = new LinkedHashMap<>(); + Map map = (Map) o; + + map.forEach((o1, o2) -> result.put(o1.toString(), o2.toString())); + + return result; + } catch (Throwable t) { + throw supplier.get(); + } + } +} diff --git a/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/configuration/ValidateIsURL.java b/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/configuration/ValidateIsURL.java new file mode 100644 index 00000000..6a7416d4 --- /dev/null +++ b/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/configuration/ValidateIsURL.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2023 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 + * + * http://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.common.configuration; + +import io.prometheus.jmx.common.util.Precondition; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.function.Function; +import java.util.function.Supplier; + +/** + * Class to validate a String is not blank, throwing a RuntimeException from the Supplier if there + * is a ClassCastException + */ +public class ValidateIsURL implements Function { + + private final Supplier supplier; + + /** + * Constructor + * + * @param supplier supplier + */ + public ValidateIsURL(Supplier supplier) { + Precondition.notNull(supplier); + this.supplier = supplier; + } + + /** + * Method to apply a function + * + * @param value value + * @return the return value + */ + @Override + public String apply(String value) { + if (value.trim().isEmpty()) { + throw supplier.get(); + } + + try { + new URL(value); + return value; + } catch (MalformedURLException e) { + throw supplier.get(); + } + } +} diff --git a/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/http/HTTPServerFactory.java b/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/http/HTTPServerFactory.java index db967d07..11b2e4d5 100644 --- a/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/http/HTTPServerFactory.java +++ b/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/http/HTTPServerFactory.java @@ -88,7 +88,7 @@ public class HTTPServerFactory { private YamlMapAccessor rootYamlMapAccessor; /** Constructor */ - public HTTPServerFactory() { + private HTTPServerFactory() { // DO NOTHING } @@ -108,6 +108,21 @@ public HTTPServer createHTTPServer( PrometheusRegistry prometheusRegistry, File exporterYamlFile) throws IOException { + if (inetAddress == null) { + throw new IllegalArgumentException("inetAddress is null"); + } + + if (port < 1 || port > 65535) { + throw new IllegalArgumentException("post is out of range [1 - 65535]"); + } + + if (prometheusRegistry == null) { + throw new IllegalArgumentException("prometheusRegistry is null"); + } + + if (exporterYamlFile == null) { + throw new IllegalArgumentException("exporterYamlFile is null"); + } HTTPServer.Builder httpServerBuilder = HTTPServer.builder() @@ -123,6 +138,15 @@ public HTTPServer createHTTPServer( return httpServerBuilder.buildAndStart(); } + /** + * Method to get an instance of the HTTPServerFactory + * + * @return the HTTPServerFactory + */ + public static HTTPServerFactory getInstance() { + return SingletonHolder.SINGLETON; + } + /** * Method to create a MapAccessor for accessing YAML configuration * @@ -639,4 +663,11 @@ public void rejectedExecution(Runnable runnable, ThreadPoolExecutor threadPoolEx } } } + + /** Class to hold the singleton */ + private static class SingletonHolder { + + /** The singleton */ + public static final HTTPServerFactory SINGLETON = new HTTPServerFactory(); + } } diff --git a/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/opentelemetry/OpenTelemetryExporterFactory.java b/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/opentelemetry/OpenTelemetryExporterFactory.java new file mode 100644 index 00000000..838c9142 --- /dev/null +++ b/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/opentelemetry/OpenTelemetryExporterFactory.java @@ -0,0 +1,193 @@ +package io.prometheus.jmx.common.opentelemetry; + +import static java.lang.String.format; + +import io.prometheus.jmx.common.configuration.ConvertToInteger; +import io.prometheus.jmx.common.configuration.ConvertToMap; +import io.prometheus.jmx.common.configuration.ConvertToMapAccessor; +import io.prometheus.jmx.common.configuration.ConvertToString; +import io.prometheus.jmx.common.configuration.ValidateIntegerInRange; +import io.prometheus.jmx.common.configuration.ValidateIsURL; +import io.prometheus.jmx.common.configuration.ValidateStringIsNotBlank; +import io.prometheus.jmx.common.http.ConfigurationException; +import io.prometheus.jmx.common.yaml.YamlMapAccessor; +import io.prometheus.metrics.exporter.opentelemetry.OpenTelemetryExporter; +import io.prometheus.metrics.model.registry.PrometheusRegistry; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.util.Map; +import org.yaml.snakeyaml.Yaml; + +/** Class to implement OpenTelemetryExporterFactory */ +public class OpenTelemetryExporterFactory { + + private static final int NO_INTERVAL = -1; + + /** Constructor */ + private OpenTelemetryExporterFactory() { + // DO NOTHING + } + + /** + * Method to create an OpenTelemetryExporter using the supplied arguments + * + * @param prometheusRegistry prometheusRegistry + * @param exporterYamlFile exporterYamlFile + * @return OpenTelemetryExporter OpenTelemetryExporter + * @throws ConfigurationException ConfigurationException + */ + public OpenTelemetryExporter createOpenTelemetryExporter( + PrometheusRegistry prometheusRegistry, File exporterYamlFile) + throws ConfigurationException { + if (exporterYamlFile == null) { + throw new IllegalArgumentException("exporterYamlFile is null"); + } + + OpenTelemetryExporter openTelemetryExporter = null; + + try { + try (Reader reader = new FileReader(exporterYamlFile)) { + Map yamlMap = new Yaml().load(reader); + YamlMapAccessor rootYamlMapAccessor = new YamlMapAccessor(yamlMap); + + if (rootYamlMapAccessor.containsPath("/openTelemetry")) { + YamlMapAccessor openTelemetryYamlMapAccessor = + rootYamlMapAccessor + .get("/openTelemetry") + .map( + new ConvertToMapAccessor( + ConfigurationException.supplier( + "Invalid configuration for" + + " /openTelemetry"))) + .orElse(new YamlMapAccessor()); + + String endpoint = + openTelemetryYamlMapAccessor + .get("/endpoint") + .map( + new ConvertToString( + ConfigurationException.supplier( + "Invalid configuration for" + + " /openTelemetry/endpoint" + + " must be a string"))) + .map( + new ValidateStringIsNotBlank( + ConfigurationException.supplier( + "Invalid configuration for" + + " /openTelemetry/endpoint" + + " must not be blank"))) + .map( + new ValidateIsURL( + ConfigurationException.supplier( + "Invalid configuration for" + + " /openTelemetry/endpoint" + + " must be a URL"))) + .orElse(null); + + String protocol = + openTelemetryYamlMapAccessor + .get("/protocol") + .map( + new ConvertToString( + ConfigurationException.supplier( + "Invalid configuration for" + + " /openTelemetry/protocol" + + " must be a string"))) + .map( + new ValidateStringIsNotBlank( + ConfigurationException.supplier( + "Invalid configuration for" + + " /openTelemetry/protocol" + + " must not be blank"))) + .orElse(null); + + int interval = + openTelemetryYamlMapAccessor + .get("/interval") + .map( + new ConvertToInteger( + ConfigurationException.supplier( + "Invalid configuration for" + + " /openTelemetry/interval" + + " must be an integer"))) + .map( + new ValidateIntegerInRange( + 1, + Integer.MAX_VALUE, + ConfigurationException.supplier( + "Invalid configuration for" + + " /openTelemetry/interval must be" + + " an integer greater than 0"))) + .orElse(NO_INTERVAL); + + Map headers = + openTelemetryYamlMapAccessor + .get("/headers") + .map( + new ConvertToMap( + ConfigurationException.supplier( + "Invalid configuration for" + + " /openTelemetry/headers" + + " must be a map"))) + .orElse(null); + + OpenTelemetryExporter.Builder openTelemetryExporterBuilder = + OpenTelemetryExporter.builder(); + + openTelemetryExporterBuilder.registry(prometheusRegistry); + + if (endpoint != null) { + openTelemetryExporterBuilder.endpoint(endpoint); + } + + if (protocol != null) { + openTelemetryExporterBuilder.protocol(protocol); + } + + if (interval != NO_INTERVAL) { + openTelemetryExporterBuilder.intervalSeconds(interval); + } + + if (headers != null) { + headers.forEach( + (name, value) -> { + if (name != null + && !name.trim().isEmpty() + && value != null + && !value.trim().isEmpty()) { + openTelemetryExporterBuilder.header( + name.trim(), value.trim()); + } + }); + } + + openTelemetryExporter = openTelemetryExporterBuilder.buildAndStart(); + } + } + } catch (IOException e) { + throw new ConfigurationException( + format("Exception loading file [%s]", exporterYamlFile), e); + } + + return openTelemetryExporter; + } + + /** + * Method to get an instance of the OpenTelemetryExporterFactory + * + * @return the OpenTelemetryExporterFactory + */ + public static OpenTelemetryExporterFactory getInstance() { + return SingletonHolder.SINGLETON; + } + + /** Class to hold the singleton */ + private static class SingletonHolder { + + /** The singleton */ + public static final OpenTelemetryExporterFactory SINGLETON = + new OpenTelemetryExporterFactory(); + } +} diff --git a/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/util/ResourceSupport.java b/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/util/ResourceSupport.java new file mode 100644 index 00000000..b0dc44df --- /dev/null +++ b/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/util/ResourceSupport.java @@ -0,0 +1,49 @@ +package io.prometheus.jmx.common.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; + +/** Class to implement ResourceSupport */ +public class ResourceSupport { + + /** Constructor */ + private ResourceSupport() { + // DO NOTHING + } + + public static String load(String resource) throws IOException { + Precondition.notNull(resource, "resource is null"); + + if (!resource.startsWith("/")) { + resource = "/" + resource; + } + + StringBuilder stringBuilder = new StringBuilder(); + + InputStream inputStream = ResourceSupport.class.getResourceAsStream(resource); + if (inputStream == null) { + throw new IOException("Resource [" + resource + "] not found"); + } + + try (BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { + while (true) { + String line = bufferedReader.readLine(); + if (line == null) { + break; + } + + if (stringBuilder.length() > 0) { + stringBuilder.append(System.lineSeparator()); + } + + stringBuilder.append(line); + } + } + + return stringBuilder.toString(); + } +} diff --git a/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/yaml/YamlMapAccessor.java b/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/yaml/YamlMapAccessor.java index db1ef151..a23a17b8 100644 --- a/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/yaml/YamlMapAccessor.java +++ b/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/yaml/YamlMapAccessor.java @@ -21,12 +21,18 @@ import java.util.Optional; import java.util.function.Supplier; import java.util.regex.Pattern; +import org.yaml.snakeyaml.Yaml; /** Class to implement a MapAccessor to work with nested Maps / values */ @SuppressWarnings("unchecked") public class YamlMapAccessor { - private final Map map; + private Map map; + + /** Constructor */ + public YamlMapAccessor() { + map = new LinkedHashMap<>(); + } /** * Constructor @@ -41,6 +47,23 @@ public YamlMapAccessor(Map map) { this.map = map; } + public YamlMapAccessor load(Object object) { + if (object == null) { + throw new IllegalArgumentException("object is null"); + } + + try { + if (object instanceof String) { + this.map = new Yaml().load((String) object); + } else { + this.map = (Map) object; + } + return this; + } catch (ClassCastException e) { + throw new IllegalArgumentException("object is not a Map"); + } + } + /** * Method to determine if a path exists * diff --git a/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/MessageDigestAuthenticatorTest.java b/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/MessageDigestAuthenticatorTest.java index 5a835f7f..3ff07413 100644 --- a/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/MessageDigestAuthenticatorTest.java +++ b/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/MessageDigestAuthenticatorTest.java @@ -22,6 +22,7 @@ import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Locale; import org.junit.Test; public class MessageDigestAuthenticatorTest extends BaseAuthenticatorTest { @@ -53,7 +54,7 @@ public void test_upperCase() throws Exception { String[] algorithms = new String[] {"SHA-1", "SHA-256", "SHA-512"}; for (String algorithm : algorithms) { - String hash = hash(algorithm, VALID_PASSWORD, SALT).toUpperCase(); + String hash = hash(algorithm, VALID_PASSWORD, SALT).toUpperCase(Locale.ENGLISH); MessageDigestAuthenticator messageDigestAuthenticator = new MessageDigestAuthenticator("/", VALID_USERNAME, hash, algorithm, SALT); diff --git a/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/PBKDF2AuthenticatorTest.java b/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/PBKDF2AuthenticatorTest.java index a6360d1c..85edabfd 100644 --- a/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/PBKDF2AuthenticatorTest.java +++ b/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/PBKDF2AuthenticatorTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals; +import java.util.Locale; import org.junit.Test; public class PBKDF2AuthenticatorTest extends BaseAuthenticatorTest { @@ -143,7 +144,7 @@ public void testPBKDF2WithHmacSHA1_upperCaseWithoutColon() throws Exception { + ":E0:72:6E:69:7D:EB:83:05:05:E5:D6:F2:19:99:49:3F:89:DA:DE:83:D7:2B:5B:7D:C9:56:B4:F2:F6:A5:61:29" + ":29:ED:DF:4C:4E:8D:EA:DF:47:A2:B0:89:11:86:D4:77:A1:02:E9:0C:26:A4:1E:2A:C1:A8:71:E0:93:8F:A4"; - hash = hash.toUpperCase().replace(":", ""); + hash = hash.toUpperCase(Locale.ENGLISH).replace(":", ""); PBKDF2Authenticator PBKDF2Authenticator = new PBKDF2Authenticator( @@ -281,7 +282,7 @@ public void testPBKDF2WithHmacSHA256_upperCaseWithoutColon() throws Exception { + ":9C:CB:AD:55:25:46:C5:73:09:6C:38:9C:F2:FD:82:7F:90:E5:31:EF:7E:3E:6B:B2:0C:38:77:23:EC:3A:CF:29" + ":F7:E5:4D:4E:CC:35:7A:C2:E5:CB:E3:B3:E5:09:2B:CC:B9:40:26:A4:28:E9:5F:2D:18:B2:14:41:E7:4D:5B"; - hash = hash.toUpperCase().replace(":", ""); + hash = hash.toUpperCase(Locale.ENGLISH).replace(":", ""); PBKDF2Authenticator PBKDF2Authenticator = new PBKDF2Authenticator( @@ -404,7 +405,7 @@ public void testPBKDF2WithHmacSHA512_upperCaseWithoutColon() throws Exception { String hash = "07:6F:E2:27:9B:CA:48:66:9B:13:9E:02:9C:AE:FC:E4:1A:2F:0F:E6:48:A3:FF:8E:D2:30:59:68:12:A6:29:34:FC:99:29:8A:98:65:AE:4B:05:7C:B6:83:A4:83:C0:32:E4:90:61:1D:DD:2E:53:17:01:FF:6A:64:48:B2:AA:22:DE:B3:BC:56:08:C6:66:EC:98:F8:96:8C:1B:DA:B2:F2:2A:6C:22:8E:19:CC:B2:62:55:3E:BE:DC:C7:58:36:9D:92:CF:D7:D2:A1:6D:8F:DC:DE:8E:E9:36:D4:E7:2D:0A:6D:A1:B8:56:0A:53:BB:17:E2:D5:DE:A0:48:51:FC:33"; - hash = hash.toUpperCase().replace(":", ""); + hash = hash.toUpperCase(Locale.ENGLISH).replace(":", ""); PBKDF2Authenticator PBKDF2Authenticator = new PBKDF2Authenticator( diff --git a/jmx_prometheus_httpserver/src/deb/bin/jmx_exporter b/jmx_prometheus_httpserver/src/deb/bin/jmx_exporter deleted file mode 100755 index d2e79cf3..00000000 --- a/jmx_prometheus_httpserver/src/deb/bin/jmx_exporter +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -exec java -jar /usr/share/jmx_exporter/jmx_prometheus_httpserver-*.jar $@ diff --git a/jmx_prometheus_httpserver/src/main/java/io/prometheus/jmx/WebServer.java b/jmx_prometheus_httpserver/src/main/java/io/prometheus/jmx/WebServer.java deleted file mode 100644 index 0b5864ec..00000000 --- a/jmx_prometheus_httpserver/src/main/java/io/prometheus/jmx/WebServer.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2015-2023 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 - * - * http://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; - -import io.prometheus.jmx.common.http.ConfigurationException; -import io.prometheus.jmx.common.http.HTTPServerFactory; -import io.prometheus.metrics.exporter.httpserver.HTTPServer; -import io.prometheus.metrics.model.registry.PrometheusRegistry; -import java.io.File; -import java.net.InetAddress; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; - -public class WebServer { - - private static final SimpleDateFormat SIMPLE_DATE_FORMAT = - new SimpleDateFormat("yyyy-MM-dd | HH:mm:ss.SSS", Locale.getDefault()); - - public static void main(String[] args) throws Exception { - if (args.length < 2) { - System.err.println("Usage: WebServer <[hostname:]port> "); - System.exit(1); - } - - String host = "0.0.0.0"; - int port; - int colonIndex = args[0].lastIndexOf(':'); - - if (colonIndex < 0) { - port = Integer.parseInt(args[0]); - } else { - port = Integer.parseInt(args[0].substring(colonIndex + 1)); - host = args[0].substring(0, colonIndex); - } - - new BuildInfoMetrics().register(PrometheusRegistry.defaultRegistry); - new JmxCollector(new File(args[1]), JmxCollector.Mode.STANDALONE) - .register(PrometheusRegistry.defaultRegistry); - - HTTPServer httpServer = null; - - try { - httpServer = - new HTTPServerFactory() - .createHTTPServer( - InetAddress.getByName(host), - port, - PrometheusRegistry.defaultRegistry, - new File(args[1])); - - System.out.println( - String.format( - "%s | %s | INFO | %s | %s", - SIMPLE_DATE_FORMAT.format(new Date()), - Thread.currentThread().getName(), - WebServer.class.getName(), - "Running")); - - Thread.currentThread().join(); - } catch (ConfigurationException e) { - System.err.println("Configuration Exception : " + e.getMessage()); - System.exit(1); - } catch (Throwable t) { - System.err.println("Exception starting"); - t.printStackTrace(); - } finally { - if (httpServer != null) { - httpServer.close(); - } - } - } -} diff --git a/jmx_prometheus_javaagent/pom.xml b/jmx_prometheus_javaagent/pom.xml index 88eea855..cf149237 100644 --- a/jmx_prometheus_javaagent/pom.xml +++ b/jmx_prometheus_javaagent/pom.xml @@ -28,35 +28,6 @@ UTF-8 - - - io.prometheus.jmx - collector - ${project.version} - - - io.prometheus.jmx - jmx_prometheus_common - ${project.version} - - - io.prometheus - prometheus-metrics-instrumentation-jvm - - - org.junit.jupiter - junit-jupiter - 5.10.2 - test - - - org.assertj - assertj-core - 3.26.0 - test - - - @@ -70,6 +41,7 @@ com.diffplug.spotless spotless-maven-plugin + 2.43.0 @@ -82,7 +54,7 @@ - check + apply compile @@ -183,6 +155,18 @@ META-INF/MANIFEST.MF + + io.prometheus:prometheus-metrics-exporter-opentelemetry + + META-INF/MANIFEST.MF + + + + io.prometheus:prometheus-metrics-shaded-opentelemetry + + META-INF/MANIFEST.MF + + org.yaml:snakeyaml @@ -259,4 +243,33 @@ + + + io.prometheus.jmx + collector + ${project.version} + + + io.prometheus.jmx + jmx_prometheus_common + ${project.version} + + + io.prometheus + prometheus-metrics-instrumentation-jvm + + + org.junit.jupiter + junit-jupiter + 5.10.2 + test + + + org.assertj + assertj-core + 3.26.0 + test + + + diff --git a/jmx_prometheus_javaagent/src/main/java/io/prometheus/jmx/Arguments.java b/jmx_prometheus_javaagent/src/main/java/io/prometheus/jmx/Arguments.java new file mode 100644 index 00000000..d54db949 --- /dev/null +++ b/jmx_prometheus_javaagent/src/main/java/io/prometheus/jmx/Arguments.java @@ -0,0 +1,150 @@ +package io.prometheus.jmx; + +import static java.lang.String.format; + +import io.prometheus.jmx.common.http.ConfigurationException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** Class to implement Arguments */ +public class Arguments { + + private static final String DEFAULT_HOST = "0.0.0.0"; + + public enum Mode { + HTTP, + OPEN_TELEMETRY + } + + private static final String CONFIGURATION_REGEX = + "^(?:((?:[\\w.-]+)|(?:\\[.+])):)?" + + // host name, or ipv4, or ipv6 address in brackets + "(?:(\\d{1,5}):)" + // port + + "(.+)"; // config file + + private final Mode mode; + private final String host; + private final Integer port; + private final String filename; + + /** + * Constructor + * + * @param mode mode + * @param host host + * @param port port + * @param filename filename + */ + private Arguments(Mode mode, String host, Integer port, String filename) { + this.mode = mode; + this.host = host; + this.port = port; + this.filename = filename; + } + + /** + * Method to get the mode inferred by the Java agent arguments + * + * @return the mode + */ + public Mode getMode() { + return mode; + } + + /** + * Method to get the host + * + * @return the host if it exists, else null + */ + public String getHost() { + return host; + } + + /** + * Method to get the port + * + * @return the port if it exists, else null + */ + public Integer getPort() { + return port; + } + + /** + * Method to get the filename + * + * @return the filename + */ + public String getFilename() { + return filename; + } + + /** + * Method to parse the Java Agent configuration arguments + * + * @param agentArgument the Java agent argument + * @return Arguments + */ + public static Arguments parse(String agentArgument) { + if (agentArgument == null || agentArgument.trim().isEmpty()) { + throw new ConfigurationException(format("Malformed arguments [%s]", agentArgument)); + } + + Pattern pattern = Pattern.compile(CONFIGURATION_REGEX); + Matcher matcher = pattern.matcher(agentArgument); + + Mode mode; + String host = null; + Integer port = null; + String filename; + + if (matcher.matches()) { + switch (matcher.groupCount()) { + case 2: + { + mode = Mode.HTTP; + host = DEFAULT_HOST; + + try { + port = Integer.parseInt(matcher.group(1)); + } catch (NumberFormatException e) { + throw new ConfigurationException( + format("Malformed arguments [%s]", agentArgument)); + } + filename = matcher.group(2); + break; + } + case 3: + { + mode = Mode.HTTP; + host = matcher.group(1) != null ? matcher.group(1) : DEFAULT_HOST; + + if (host.startsWith("[") && host.endsWith("]") && host.length() > 3) { + host = host.substring(1, host.length() - 1); + } + + port = Integer.parseInt(matcher.group(2)); + filename = matcher.group(3); + break; + } + default: + { + throw new ConfigurationException( + format( + "Malformed arguments for Standalone HTTP mode [%s]", + agentArgument)); + } + } + + if (host.trim().isEmpty()) { + throw new ConfigurationException( + format("Malformed arguments for Standalone HTTP mode [%s]", agentArgument)); + } + } else { + mode = Mode.OPEN_TELEMETRY; + filename = agentArgument; + } + + return new Arguments(mode, host, port, filename); + } +} diff --git a/jmx_prometheus_javaagent/src/main/java/io/prometheus/jmx/JavaAgent.java b/jmx_prometheus_javaagent/src/main/java/io/prometheus/jmx/JavaAgent.java index 408b7715..1ba7ae3f 100644 --- a/jmx_prometheus_javaagent/src/main/java/io/prometheus/jmx/JavaAgent.java +++ b/jmx_prometheus_javaagent/src/main/java/io/prometheus/jmx/JavaAgent.java @@ -16,105 +16,64 @@ package io.prometheus.jmx; -import io.prometheus.jmx.common.http.ConfigurationException; import io.prometheus.jmx.common.http.HTTPServerFactory; -import io.prometheus.metrics.exporter.httpserver.HTTPServer; +import io.prometheus.jmx.common.opentelemetry.OpenTelemetryExporterFactory; import io.prometheus.metrics.instrumentation.jvm.JvmMetrics; import io.prometheus.metrics.model.registry.PrometheusRegistry; import java.io.File; import java.lang.instrument.Instrumentation; import java.net.InetAddress; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class JavaAgent { - public static final String CONFIGURATION_REGEX = - "^(?:((?:[\\w.-]+)|(?:\\[.+])):)?" - + // host name, or ipv4, or ipv6 address in brackets - "(\\d{1,5}):" - + // port - "(.+)"; // config file - - private static final String DEFAULT_HOST = "0.0.0.0"; - - private static HTTPServer httpServer; - - public static void agentmain(String agentArgument, Instrumentation instrumentation) - throws Exception { + /** + * Java agent main + * + * @param agentArgument agentArgument + * @param instrumentation instrumentation + */ + public static void agentmain(String agentArgument, Instrumentation instrumentation) { premain(agentArgument, instrumentation); } - public static void premain(String agentArgument, Instrumentation instrumentation) - throws Exception { + /** + * Java agent premain + * + * @param agentArgument agentArgument + * @param instrumentation instrumentation + */ + public static void premain(String agentArgument, Instrumentation instrumentation) { try { - Config config = parseConfig(agentArgument); + Arguments arguments = Arguments.parse(agentArgument); + File file = new File(arguments.getFilename()); new BuildInfoMetrics().register(PrometheusRegistry.defaultRegistry); JvmMetrics.builder().register(PrometheusRegistry.defaultRegistry); - new JmxCollector(new File(config.file), JmxCollector.Mode.AGENT) + new JmxCollector(new File(arguments.getFilename()), JmxCollector.Mode.AGENT) .register(PrometheusRegistry.defaultRegistry); - String host = config.host != null ? config.host : DEFAULT_HOST; - - httpServer = - new HTTPServerFactory() - .createHTTPServer( - InetAddress.getByName(host), - config.port, - PrometheusRegistry.defaultRegistry, - new File(config.file)); + if (arguments.getMode() == Arguments.Mode.HTTP) { + HTTPServerFactory.getInstance() + .createHTTPServer( + InetAddress.getByName(arguments.getHost()), + arguments.getPort(), + PrometheusRegistry.defaultRegistry, + file); + } else { + OpenTelemetryExporterFactory.getInstance() + .createOpenTelemetryExporter(PrometheusRegistry.defaultRegistry, file); + } } catch (Throwable t) { synchronized (System.err) { System.err.println("Failed to start Prometheus JMX Exporter"); System.err.println(); - t.printStackTrace(); + t.printStackTrace(System.err); System.err.println(); System.err.println("Prometheus JMX Exporter exiting"); System.err.flush(); } - System.exit(1); - } - } - /** - * Parse the Java Agent configuration. The arguments are typically specified to the JVM as a - * javaagent as {@code -javaagent:/path/to/agent.jar=}. This method parses the {@code - * } portion. - * - * @param args provided agent args - * @return configuration to use for our application - */ - private static Config parseConfig(String args) { - Pattern pattern = Pattern.compile(CONFIGURATION_REGEX); - - Matcher matcher = pattern.matcher(args); - if (!matcher.matches()) { - System.err.println( - "Usage: -javaagent:/path/to/JavaAgent.jar=[host:]: "); - throw new ConfigurationException("Malformed arguments - " + args); - } - - String givenHost = matcher.group(1); - String givenPort = matcher.group(2); - String givenConfigFile = matcher.group(3); - - int port = Integer.parseInt(givenPort); - - return new Config(givenHost, port, givenConfigFile); - } - - private static class Config { - - String host; - int port; - String file; - - Config(String host, int port, String file) { - this.host = host; - this.port = port; - this.file = file; + System.exit(1); } } } diff --git a/jmx_prometheus_javaagent/src/test/java/io/prometheus/jmx/ArgumentsTest.java b/jmx_prometheus_javaagent/src/test/java/io/prometheus/jmx/ArgumentsTest.java new file mode 100644 index 00000000..799496d8 --- /dev/null +++ b/jmx_prometheus_javaagent/src/test/java/io/prometheus/jmx/ArgumentsTest.java @@ -0,0 +1,333 @@ +/* + * Copyright (C) 2023 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 + * + * http://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; + +import static java.lang.String.format; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import io.prometheus.jmx.common.http.ConfigurationException; +import org.junit.jupiter.api.Test; + +public class ArgumentsTest { + + private static final boolean VALID_CONFIGURATION = true; + private static final boolean INVALID_CONFIGURATION = false; + + private static final ArgumentsTestDefinition[] ARGUMENTS_TEST_DEFINITIONS = { + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "12345:/opt/prometheus/config.yaml", + Arguments.Mode.HTTP, + "0.0.0.0", + 12345, + "/opt/prometheus/config.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "12345:/opt/prometheus/config_file.yaml", + Arguments.Mode.HTTP, + "0.0.0.0", + 12345, + "/opt/prometheus/config_file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "12345:/opt/prometheus/config-file.yaml", + Arguments.Mode.HTTP, + "0.0.0.0", + 12345, + "/opt/prometheus/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "12345:/opt/prometheus/jmx-exporter/config-file.yaml", + Arguments.Mode.HTTP, + "0.0.0.0", + 12345, + "/opt/prometheus/jmx-exporter/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "12345:/opt/prometheus/jmx_exporter/config-file.yaml", + Arguments.Mode.HTTP, + "0.0.0.0", + 12345, + "/opt/prometheus/jmx_exporter/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "myhost.domain.com:12345:/opt/prometheus/config.yaml", + Arguments.Mode.HTTP, + "myhost.domain.com", + 12345, + "/opt/prometheus/config.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "myhost.domain.com:12345:/opt/prometheus/config_file.yaml", + Arguments.Mode.HTTP, + "myhost.domain.com", + 12345, + "/opt/prometheus/config_file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "myhost.domain.com:12345:/opt/prometheus/config-file.yaml", + Arguments.Mode.HTTP, + "myhost.domain.com", + 12345, + "/opt/prometheus/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "myhost.domain.com:12345:/opt/prometheus/jmx-exporter/config-file.yaml", + Arguments.Mode.HTTP, + "myhost.domain.com", + 12345, + "/opt/prometheus/jmx-exporter/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "myhost.domain.com:12345:/opt/prometheus/jmx_exporter/config-file.yaml", + Arguments.Mode.HTTP, + "myhost.domain.com", + 12345, + "/opt/prometheus/jmx_exporter/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "myhostname.sub-domain.prometheus.org:12345:/opt/prometheus/config.yaml", + Arguments.Mode.HTTP, + "myhostname.sub-domain.prometheus.org", + 12345, + "/opt/prometheus/config.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "myhostname.sub-domain.prometheus.org:12345:/opt/prometheus/config_file.yaml", + Arguments.Mode.HTTP, + "myhostname.sub-domain.prometheus.org", + 12345, + "/opt/prometheus/config_file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "myhostname.sub-domain.prometheus.org:12345:/opt/prometheus/config-file.yaml", + Arguments.Mode.HTTP, + "myhostname.sub-domain.prometheus.org", + 12345, + "/opt/prometheus/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "myhostname.sub-domain.prometheus.org:12345:/opt/prometheus/jmx-exporter/config-file.yaml", + Arguments.Mode.HTTP, + "myhostname.sub-domain.prometheus.org", + 12345, + "/opt/prometheus/jmx-exporter/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "myhostname.sub_domain.prometheus.org:12345:/opt/prometheus/config.yaml", + Arguments.Mode.HTTP, + "myhostname.sub_domain.prometheus.org", + 12345, + "/opt/prometheus/config.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "myhostname.sub_domain.prometheus.org:12345:/opt/prometheus/config_file.yaml", + Arguments.Mode.HTTP, + "myhostname.sub_domain.prometheus.org", + 12345, + "/opt/prometheus/config_file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "myhostname.sub_domain.prometheus.org:12345:/opt/prometheus/config-file.yaml", + Arguments.Mode.HTTP, + "myhostname.sub_domain.prometheus.org", + 12345, + "/opt/prometheus/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "myhostname.sub_domain.prometheus.org:12345:/opt/prometheus/jmx-exporter/config-file.yaml", + Arguments.Mode.HTTP, + "myhostname.sub_domain.prometheus.org", + 12345, + "/opt/prometheus/jmx-exporter/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "myhostname.sub_domain.prometheus.org:12345:/opt/prometheus/jmx_exporter/config-file.yaml", + Arguments.Mode.HTTP, + "myhostname.sub_domain.prometheus.org", + 12345, + "/opt/prometheus/jmx_exporter/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "192.168.1.1:12345:/opt/prometheus/config.yaml", + Arguments.Mode.HTTP, + "192.168.1.1", + 12345, + "/opt/prometheus/config.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "192.168.1.1:12345:/opt/prometheus/config_file.yaml", + Arguments.Mode.HTTP, + "192.168.1.1", + 12345, + "/opt/prometheus/config_file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "192.168.1.1:12345:/opt/prometheus/config-file.yaml", + Arguments.Mode.HTTP, + "192.168.1.1", + 12345, + "/opt/prometheus/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "192.168.1.1:12345:/opt/prometheus/jmx-exporter/config-file.yaml", + Arguments.Mode.HTTP, + "192.168.1.1", + 12345, + "/opt/prometheus/jmx-exporter/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "192.168.1.1:12345:/opt/prometheus/jmx_exporter/config-file.yaml", + Arguments.Mode.HTTP, + "192.168.1.1", + 12345, + "/opt/prometheus/jmx_exporter/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "192.168.1.1:12345:/opt/prometheus/jmx_exporter/config-file.yaml", + Arguments.Mode.HTTP, + "192.168.1.1", + 12345, + "/opt/prometheus/jmx_exporter/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "[::/0]:12345:/opt/prometheus/config.yaml", + Arguments.Mode.HTTP, + "::/0", + 12345, + "/opt/prometheus/config.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "[001:0db8:0a0b:12f0:0000:0000:0000:0001]:12345:/opt/prometheus/config.yaml", + Arguments.Mode.HTTP, + "001:0db8:0a0b:12f0:0000:0000:0000:0001", + 12345, + "/opt/prometheus/config.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "[001:0db8:0a0b:12f0:0000:0000:0000:0001]:12345:/opt/prometheus/config_file.yaml", + Arguments.Mode.HTTP, + "001:0db8:0a0b:12f0:0000:0000:0000:0001", + 12345, + "/opt/prometheus/config_file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "[001:0db8:0a0b:12f0:0000:0000:0000:0001]:12345:/opt/prometheus/config-file.yaml", + Arguments.Mode.HTTP, + "001:0db8:0a0b:12f0:0000:0000:0000:0001", + 12345, + "/opt/prometheus/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "[001:0db8:0a0b:12f0:0000:0000:0000:0001]:12345:/opt/prometheus/jmx-exporter/config-file.yaml", + Arguments.Mode.HTTP, + "001:0db8:0a0b:12f0:0000:0000:0000:0001", + 12345, + "/opt/prometheus/jmx-exporter/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "[001:0db8:0a0b:12f0:0000:0000:0000:0001]:12345:/opt/prometheus/jmx_exporter/config-file.yaml", + Arguments.Mode.HTTP, + "001:0db8:0a0b:12f0:0000:0000:0000:0001", + 12345, + "/opt/prometheus/jmx_exporter/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "[001:0db8:0a0b:12f0:0000:0000:0000:0001]:12345:/opt/prometheus/jmx_exporter/config-file.yaml", + Arguments.Mode.HTTP, + "001:0db8:0a0b:12f0:0000:0000:0000:0001", + 12345, + "/opt/prometheus/jmx_exporter/config-file.yaml"), + new ArgumentsTestDefinition( + VALID_CONFIGURATION, + "/opt/prometheus/config.yaml", + Arguments.Mode.OPEN_TELEMETRY, + null, + null, + "/opt/prometheus/config.yaml"), + /* + new ArgumentsTestDefinition( + INVALID_CONFIGURATION, + "::/opt/prometheus/config.yaml", + Arguments.Mode.HTTP, + null, + null, + "/opt/prometheus/config.yaml"), + new ArgumentsTestDefinition( + INVALID_CONFIGURATION, + "::/opt/prometheus/config.yaml", + Arguments.Mode.OPEN_TELEMETRY, + null, + null, + "/opt/prometheus/config.yaml")*/ + }; + + @Test + public void testsArguments() { + for (int i = 0; i < ARGUMENTS_TEST_DEFINITIONS.length; i++) { + ArgumentsTestDefinition argumentsTestDefinition = ARGUMENTS_TEST_DEFINITIONS[i]; + System.out.println( + format( + "testing Java agent argument [%d] [%s]", + i, argumentsTestDefinition.getArgument())); + ARGUMENTS_TEST_DEFINITIONS[i].assertValid(); + } + } + + public static class ArgumentsTestDefinition { + + private final String argument; + private final boolean validConfiguration; + private final Arguments.Mode mode; + private final String host; + private final Integer port; + private final String filename; + + public ArgumentsTestDefinition( + boolean validConfiguration, + String argument, + Arguments.Mode mode, + String host, + Integer port, + String filename) { + this.argument = argument; + this.validConfiguration = validConfiguration; + this.mode = mode; + this.host = host; + this.port = port; + this.filename = filename; + } + + public String getArgument() { + return argument; + } + + public void assertValid() { + if (validConfiguration) { + Arguments arguments = Arguments.parse(argument); + assertThat(arguments.getMode()).isEqualTo(mode); + assertThat(arguments.getHost()).isEqualTo(host); + assertThat(arguments.getPort()).isEqualTo(port); + assertThat(arguments.getFilename()).isEqualTo(filename); + } else { + assertThatExceptionOfType(ConfigurationException.class) + .isThrownBy(() -> Arguments.parse(argument)); + } + } + } +} diff --git a/jmx_prometheus_javaagent/src/test/java/io/prometheus/jmx/JavaAgentConfigurationRegexTest.java b/jmx_prometheus_javaagent/src/test/java/io/prometheus/jmx/JavaAgentConfigurationRegexTest.java deleted file mode 100644 index 0c1b07dd..00000000 --- a/jmx_prometheus_javaagent/src/test/java/io/prometheus/jmx/JavaAgentConfigurationRegexTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2023 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 - * - * http://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; - -import static org.assertj.core.api.Assertions.fail; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.junit.jupiter.api.Test; - -public class JavaAgentConfigurationRegexTest { - - private static final String[] ARGUMENTS = { - "12345:/opt/prometheus/config.yaml", - "12345:/opt/prometheus/config_file.yaml", - "12345:/opt/prometheus/config-file.yaml", - "12345:/opt/prometheus/jmx-exporter/config-file.yaml", - "12345:/opt/prometheus/jmx_exporter/config-file.yaml", - "myhost.domain.com:12345:/opt/prometheus/config.yaml", - "myhost.domain.com:12345:/opt/prometheus/config_file.yaml", - "myhost.domain.com:12345:/opt/prometheus/config-file.yaml", - "myhost.domain.com:12345:/opt/prometheus/jmx-exporter/config-file.yaml", - "myhost.domain.com:12345:/opt/prometheus/jmx_exporter/config-file.yaml", - "myhostname.sub-domain.prometheus.org:12345:/opt/prometheus/config.yaml", - "myhostname.sub-domain.prometheus.org:12345:/opt/prometheus/config_file.yaml", - "myhostname.sub-domain.prometheus.org:12345:/opt/prometheus/config-file.yaml", - "myhostname.sub-domain.prometheus.org:12345:/opt/prometheus/jmx-exporter/config-file.yaml", - "myhostname.sub_domain.prometheus.org:12345:/opt/prometheus/config.yaml", - "myhostname.sub_domain.prometheus.org:12345:/opt/prometheus/config_file.yaml", - "myhostname.sub_domain.prometheus.org:12345:/opt/prometheus/config-file.yaml", - "myhostname.sub_domain.prometheus.org:12345:/opt/prometheus/jmx-exporter/config-file.yaml", - "myhostname.sub_domain.prometheus.org:12345:/opt/prometheus/jmx_exporter/config-file.yaml", - "192.168.1.1:12345:/opt/prometheus/config.yaml", - "192.168.1.1:12345:/opt/prometheus/config_file.yaml", - "192.168.1.1:12345:/opt/prometheus/config-file.yaml", - "192.168.1.1:12345:/opt/prometheus/jmx-exporter/config-file.yaml", - "192.168.1.1:12345:/opt/prometheus/jmx_exporter/config-file.yaml" - }; - - @Test - public void testConfigurationRegex() { - Pattern pattern = Pattern.compile(JavaAgent.CONFIGURATION_REGEX); - Matcher matcher = pattern.matcher(""); - - for (String argument : ARGUMENTS) { - matcher.reset(argument); - if (!matcher.matches()) { - fail(String.format("Expected a match for [%s]", argument)); - } - } - } -} diff --git a/jmx_prometheus_httpserver/pom.xml b/jmx_prometheus_standalone/pom.xml similarity index 92% rename from jmx_prometheus_httpserver/pom.xml rename to jmx_prometheus_standalone/pom.xml index 497b6dd4..a3f9172d 100644 --- a/jmx_prometheus_httpserver/pom.xml +++ b/jmx_prometheus_standalone/pom.xml @@ -8,8 +8,8 @@ 1.x.x - jmx_prometheus_httpserver - Prometheus JMX Exporter - Http Server + jmx_prometheus_standalone + Prometheus JMX Exporter - Standalone Server See https://github.com/prometheus/jmx_exporter/blob/master/README.md @@ -41,6 +41,7 @@ com.diffplug.spotless spotless-maven-plugin + 2.43.0 @@ -53,7 +54,7 @@ - check + apply compile @@ -154,6 +155,18 @@ META-INF/MANIFEST.MF + + io.prometheus:prometheus-metrics-exporter-opentelemetry + + META-INF/MANIFEST.MF + + + + io.prometheus:prometheus-metrics-shaded-opentelemetry + + META-INF/MANIFEST.MF + + org.yaml:snakeyaml @@ -164,7 +177,7 @@ - io.prometheus.jmx.WebServer + io.prometheus.jmx.Standalone ${project.version} ${project.artifactId} @@ -196,7 +209,7 @@ - + jdeb org.vafer @@ -254,7 +267,7 @@ ${project.build.directory}/${project.build.finalName}.jar - ../integration_test_suite/integration_tests/src/test/resources/common/jmx_prometheus_httpserver.jar + ../integration_test_suite/integration_tests/src/test/resources/common/jmx_prometheus_standalone.jar diff --git a/jmx_prometheus_standalone/src/deb/bin/jmx_exporter b/jmx_prometheus_standalone/src/deb/bin/jmx_exporter new file mode 100755 index 00000000..906808e2 --- /dev/null +++ b/jmx_prometheus_standalone/src/deb/bin/jmx_exporter @@ -0,0 +1,3 @@ +#!/bin/sh + +exec java -jar /usr/share/jmx_exporter/jmx_prometheus_standalone-*.jar $@ diff --git a/jmx_prometheus_httpserver/src/deb/config/jmx_exporter.yaml b/jmx_prometheus_standalone/src/deb/config/jmx_exporter.yaml similarity index 100% rename from jmx_prometheus_httpserver/src/deb/config/jmx_exporter.yaml rename to jmx_prometheus_standalone/src/deb/config/jmx_exporter.yaml diff --git a/jmx_prometheus_httpserver/src/deb/control/control b/jmx_prometheus_standalone/src/deb/control/control similarity index 100% rename from jmx_prometheus_httpserver/src/deb/control/control rename to jmx_prometheus_standalone/src/deb/control/control diff --git a/jmx_prometheus_standalone/src/main/java/io/prometheus/jmx/Arguments.java b/jmx_prometheus_standalone/src/main/java/io/prometheus/jmx/Arguments.java new file mode 100644 index 00000000..b9ecc270 --- /dev/null +++ b/jmx_prometheus_standalone/src/main/java/io/prometheus/jmx/Arguments.java @@ -0,0 +1,140 @@ +package io.prometheus.jmx; + +import static java.lang.String.format; + +import io.prometheus.jmx.common.http.ConfigurationException; + +/** Class to implement Arguments */ +public class Arguments { + + private static final String DEFAULT_HOST = "0.0.0.0"; + + public enum Mode { + HTTP, + OPEN_TELEMETRY + } + + private final Mode mode; + private final String host; + private final Integer port; + private final String filename; + + /** + * Constructor + * + * @param mode mode + * @param host host + * @param port port + * @param filename filename + */ + private Arguments(Mode mode, String host, Integer port, String filename) { + this.mode = mode; + this.host = host; + this.port = port; + this.filename = filename; + } + + /** + * Method to get the mode inferred by the Java agent arguments + * + * @return + */ + public Mode getMode() { + return mode; + } + + /** + * Method to get the host + * + * @return the host if it exists, else null + */ + public String getHost() { + return host; + } + + /** + * Method to get the port + * + * @return the port if it exists, else null + */ + public Integer getPort() { + return port; + } + + /** + * Method to get the filename + * + * @return the filename + */ + public String getFilename() { + return filename; + } + + /** + * Method to parse the Java Standalone configuration arguments + * + * @param arguments the Java arguments + * @return Arguments + */ + public static Arguments parse(String[] arguments) { + if (arguments == null || arguments.length == 0) { + throw new ConfigurationException( + format("Malformed arguments [%s]", toString(arguments))); + } + + for (String argument : arguments) { + if (argument == null || argument.trim().isEmpty()) { + throw new ConfigurationException( + format("Malformed arguments [%s]", toString(arguments))); + } + } + + Mode mode; + String host = null; + Integer port = null; + String filename; + + if (arguments.length == 2) { + mode = Mode.HTTP; + + host = DEFAULT_HOST; + + int colonIndex = arguments[0].lastIndexOf(':'); + + try { + if (colonIndex < 0) { + port = Integer.parseInt(arguments[0]); + } else { + port = Integer.parseInt(arguments[0].substring(colonIndex + 1)); + host = arguments[0].substring(0, colonIndex); + } + } catch (NumberFormatException e) { + throw new ConfigurationException( + format("Malformed arguments [%s]", toString(arguments))); + } + + filename = arguments[1]; + } else { + mode = Mode.OPEN_TELEMETRY; + filename = arguments[0]; + } + + return new Arguments(mode, host, port, filename); + } + + private static String toString(String[] strings) { + if (strings == null) { + return null; + } + + StringBuilder stringBuilder = new StringBuilder(); + for (String string : strings) { + if (stringBuilder.length() > 0) { + stringBuilder.append(" "); + } + stringBuilder.append(string); + } + + return stringBuilder.toString(); + } +} diff --git a/jmx_prometheus_standalone/src/main/java/io/prometheus/jmx/Standalone.java b/jmx_prometheus_standalone/src/main/java/io/prometheus/jmx/Standalone.java new file mode 100644 index 00000000..02943d58 --- /dev/null +++ b/jmx_prometheus_standalone/src/main/java/io/prometheus/jmx/Standalone.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2015-2023 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 + * + * http://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; + +import static java.lang.String.format; + +import io.prometheus.jmx.common.http.ConfigurationException; +import io.prometheus.jmx.common.http.HTTPServerFactory; +import io.prometheus.jmx.common.opentelemetry.OpenTelemetryExporterFactory; +import io.prometheus.jmx.common.util.ResourceSupport; +import io.prometheus.metrics.exporter.httpserver.HTTPServer; +import io.prometheus.metrics.exporter.opentelemetry.OpenTelemetryExporter; +import io.prometheus.metrics.model.registry.PrometheusRegistry; +import java.io.File; +import java.net.InetAddress; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +/** Class to implement Standalone */ +public class Standalone { + + private static final SimpleDateFormat SIMPLE_DATE_FORMAT = + new SimpleDateFormat("yyyy-MM-dd | HH:mm:ss.SSS", Locale.getDefault()); + + /** + * Main method + * + * @param args args + * @throws Exception Exception + */ + public static void main(String[] args) throws Exception { + HTTPServer httpServer = null; + OpenTelemetryExporter openTelemetryExporter = null; + String usage = ResourceSupport.load("/usage.txt"); + + if (args == null || args.length < 1 || args.length > 2) { + System.err.println(usage); + System.err.println(); + System.exit(1); + } + + try { + Arguments arguments = Arguments.parse(args); + File file = new File(arguments.getFilename()); + + new BuildInfoMetrics().register(PrometheusRegistry.defaultRegistry); + new JmxCollector(file, JmxCollector.Mode.STANDALONE) + .register(PrometheusRegistry.defaultRegistry); + + if (arguments.getMode() == Arguments.Mode.HTTP) { + httpServer = + HTTPServerFactory.getInstance() + .createHTTPServer( + InetAddress.getByName(arguments.getHost()), + arguments.getPort(), + PrometheusRegistry.defaultRegistry, + file); + } else { + openTelemetryExporter = + OpenTelemetryExporterFactory.getInstance() + .createOpenTelemetryExporter( + PrometheusRegistry.defaultRegistry, file); + } + + info( + "Running (%s)", + arguments.getMode() == Arguments.Mode.HTTP ? "HTTP" : "OpenTelemetry"); + + Thread.currentThread().join(); + } catch (ConfigurationException e) { + synchronized (System.err) { + System.err.println("Configuration Exception : " + e.getMessage()); + e.printStackTrace(System.err); + System.exit(1); + } + } catch (Throwable t) { + synchronized (System.err) { + System.err.println("Exception starting"); + t.printStackTrace(System.err); + System.exit(1); + } + } finally { + if (openTelemetryExporter != null) { + openTelemetryExporter.close(); + } + if (httpServer != null) { + httpServer.close(); + } + } + } + + private static void info(String format, Object... objects) { + System.out.println( + format( + "%s | %s | INFO | %s | %s", + SIMPLE_DATE_FORMAT.format(new Date()), + Thread.currentThread().getName(), + Standalone.class.getName(), + format(format, objects))); + } +} diff --git a/jmx_prometheus_standalone/src/main/resources/usage.txt b/jmx_prometheus_standalone/src/main/resources/usage.txt new file mode 100644 index 00000000..90141e45 --- /dev/null +++ b/jmx_prometheus_standalone/src/main/resources/usage.txt @@ -0,0 +1,39 @@ +------------------------------ +JMX Exporter Standalone Server +------------------------------ + +The JMX Exporter Standalone server has two exclusive modes: + +Prometheus (HTTP) mode +---------------------- + +- Exposes a "/metrics" endpoint to allow metrics collection via Prometheus (HTTP) +- OpenTelemetry configuration is ignored + +Usage: + + java -jar jmx_prometheus_standalone-.jar [HOSTNAME:] + +Example: + + java -jar jmx_prometheus_standalone-1.0.1.jar 12345 config.yaml + +OpenTelemetry mode +------------------ + +- Pushes metrics to an OpenTelemetry endpoint +- Requires OpenTelemetry to be configured in the YAML configuration file +- HTTP configuration is ignored + +Usage: + + java -jar jmx_prometheus_standalone-.jar + +Example: + + java -jar jmx_prometheus_standalone-1.0.1.jar config.yaml + +Documentation +------------- + +https://github.com/prometheus/jmx_exporter diff --git a/jmx_prometheus_httpserver/version-rules.xml b/jmx_prometheus_standalone/version-rules.xml similarity index 100% rename from jmx_prometheus_httpserver/version-rules.xml rename to jmx_prometheus_standalone/version-rules.xml diff --git a/pom.xml b/pom.xml index 21f31182..5b03d76e 100644 --- a/pom.xml +++ b/pom.xml @@ -48,8 +48,8 @@ collector jmx_prometheus_common - jmx_prometheus_httpserver jmx_prometheus_javaagent + jmx_prometheus_standalone integration_test_suite @@ -86,6 +86,11 @@ prometheus-metrics-exporter-httpserver ${prometheus.metrics.version} + + io.prometheus + prometheus-metrics-exporter-opentelemetry + ${prometheus.metrics.version} + @@ -200,7 +205,7 @@ - + diff --git a/run_sample_httpserver.sh b/run_sample_httpserver.sh deleted file mode 100755 index be49ba1f..00000000 --- a/run_sample_httpserver.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -# Script to run a java application for testing jmx4prometheus. - -VERSION=$(sed -n -e 's#.*\(.*-SNAPSHOT\)#\1#p' pom.xml) - -# Note: You can use localhost:5556 instead of 5556 for configuring socket hostname. - -java \ - -Dcom.sun.management.jmxremote.ssl=false \ - -Dcom.sun.management.jmxremote.authenticate=false \ - -Dcom.sun.management.jmxremote.port=5555 \ - -jar jmx_prometheus_httpserver/target/jmx_prometheus_httpserver-"${VERSION}".jar 5556 \ - example_configs/httpserver_sample_config.yml diff --git a/run_sample_standalone.sh b/run_sample_standalone.sh new file mode 100755 index 00000000..25aa5a4c --- /dev/null +++ b/run_sample_standalone.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# Script to run a java application for testing the Prometheus JMX Standalone exporter. + +VERSION=$(grep "" pom.xml | head -1 | sed -n 's/.*\(.*\)<\/version>.*/\1/p') + +# Note: You can use localhost:5556 instead of 5556 for configuring socket hostname. + +java \ + -Dcom.sun.management.jmxremote.ssl=false \ + -Dcom.sun.management.jmxremote.authenticate=false \ + -Dcom.sun.management.jmxremote.port=5555 \ + -jar jmx_prometheus_standalone/target/jmx_prometheus_standalone-"${VERSION}".jar 5556 \ + example_configs/standalone_sample_config.yml diff --git a/stress-test.sh b/stress-test.sh index 38ecca85..b743484f 100755 --- a/stress-test.sh +++ b/stress-test.sh @@ -22,6 +22,9 @@ # ( + export JAVA_DOCKER_IMAGES=ALL + export PROMETHEUS_DOCKER_IMAGES=ALL + while true; do DATE=`date` diff --git a/tools/build-and-copy.sh b/tools/build-and-copy.sh index f39483e3..91bcce4a 100755 --- a/tools/build-and-copy.sh +++ b/tools/build-and-copy.sh @@ -49,7 +49,7 @@ BUILD_EXIT_CODE="$?" if [ "${BUILD_EXIT_CODE}" == "0" ]; then cp "jmx_prometheus_javaagent/target/jmx_prometheus_javaagent-${BUILD_VERSION}.jar" "${DESTINATION_DIRECTORY}" - cp "jmx_prometheus_httpserver/target/jmx_prometheus_httpserver-${BUILD_VERSION}.jar" "${DESTINATION_DIRECTORY}" + cp "jmx_prometheus_standalone/target/jmx_prometheus_standalone-${BUILD_VERSION}.jar" "${DESTINATION_DIRECTORY}" fi # Revert the versions diff --git a/tools/patch-and-run-integration-test-suite.sh b/tools/patch-and-run-integration-test-suite.sh index 4aa8fc50..ed981a53 100755 --- a/tools/patch-and-run-integration-test-suite.sh +++ b/tools/patch-and-run-integration-test-suite.sh @@ -16,12 +16,12 @@ function emit_error () { } JAVA_AGENT_JAR="${1}" -HTTPSERVER_JAR="${2}" +STANDALONE_JAR="${2}" PROJECT_ROOT_DIRECTORY=$(git rev-parse --show-toplevel) if [ "$#" -ne 2 ]; then - echo "Usage: ${0} " + echo "Usage: ${0} " exit 1 fi @@ -36,9 +36,9 @@ rm -Rf ./integration_test_suite/integration_tests/src/test/resources/common/* > cp "${JAVA_AGENT_JAR}" ./integration_test_suite/integration_tests/src/test/resources/common/jmx_prometheus_javaagent.jar check_exit_code "Failed to patch the integration test suite [${JAVA_AGENT_JAR}]" -# Copy the Java HTTP server exporter jar into the integration test suite -cp "${HTTPSERVER_JAR}" ./integration_test_suite/integration_tests/src/test/resources/common/jmx_prometheus_httpserver.jar -check_exit_code "Failed to patch the integration test suite [${HTTPSERVER_JAR}]" +# Copy the Java standalone server exporter jar into the integration test suite +cp "${STANDALONE_JAR}" ./integration_test_suite/integration_tests/src/test/resources/common/jmx_prometheus_standalone.jar +check_exit_code "Failed to patch the integration test suite [${STANDALONE_JAR}]" # Pull smoke test Docker images ./integration_test_suite/docker-pull-images.smoke-test.sh @@ -60,13 +60,13 @@ then emit_error "Java agent jar mismatch" fi -# Validate the java httpserver jar version -DOWNLOAD_HTTPSERVER_JAR_SHA256=$(sha256sum "${HTTPSERVER_JAR}") -INTEGRATION_HTTPSERVER_JAR_SHA256=$(sha256sum ./integration_tests/src/test/resources/common/jmx_prometheus_httpserver.jar) +# Validate the java standalone jar version +DOWNLOAD_STANDALONE_JAR_SHA256=$(sha256sum "${STANDALONE_JAR}") +INTEGRATION_STANDALONE_JAR_SHA256=$(sha256sum ./integration_tests/src/test/resources/common/jmx_prometheus_standalone.jar) -if [ "${DOWNLOAD_HTTPSERVER_JAR_SHA256}" != "${DOWNLOAD_HTTPSERVER_JAR_SHA256}" ]; +if [ "${DOWNLOAD_STANDALONE_JAR_SHA256}" != "${DOWNLOAD_STANDALONE_JAR_SHA256}" ]; then - emit_error "Java HTTP server jar mismatch" + emit_error "Java standalone server jar mismatch" fi # Change to the project root directory