diff --git a/.github/workflows/multi-version-test.yml b/.github/workflows/multi-version-test.yml new file mode 100644 index 000000000..813f1a83c --- /dev/null +++ b/.github/workflows/multi-version-test.yml @@ -0,0 +1,39 @@ +--- +name: Java-Version Compatibility Tests + +on: [pull_request] + +permissions: {} + +jobs: + compatibility-test: + name: Test on Java ${{ matrix.java }} + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + java: [8, 11, 17, 21, 25] + steps: + - name: Check out + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 + with: + persist-credentials: false + + - name: Set up Java ${{ matrix.java }} + id: setup-java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: ${{ matrix.java }} + + - name: Cache local Maven repository + uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-java${{ matrix.java }}-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven-java${{ matrix.java }}- + ${{ runner.os }}-maven- + + - name: Build and test on Java ${{ matrix.java }} + run: ./mvnw clean install -Dtest.java.version=${{ matrix.java }} -Djava.version=${{ matrix.java }} -DskipErrorProne=true -Dspotless.skip=true -Dcheckstyle.skip=true -Dwarnings=-nowarn -Dcoverage.skip=true \ No newline at end of file diff --git a/.mvn/jvm.config b/.mvn/jvm.config deleted file mode 100644 index 32599cefe..000000000 --- a/.mvn/jvm.config +++ /dev/null @@ -1,10 +0,0 @@ ---add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED ---add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED ---add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED ---add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED ---add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED ---add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED ---add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED ---add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED ---add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED ---add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED diff --git a/integration-tests/it-spring-boot-smoke-test/pom.xml b/integration-tests/it-spring-boot-smoke-test/pom.xml index 35663055f..a245bef31 100644 --- a/integration-tests/it-spring-boot-smoke-test/pom.xml +++ b/integration-tests/it-spring-boot-smoke-test/pom.xml @@ -21,8 +21,7 @@ Spring Smoke Tests - 25 - 6.0.2 + ${test.java.version} @@ -89,95 +88,108 @@ - - org.graalvm.buildtools - native-maven-plugin - - - - - --initialize-at-build-time=org.junit.jupiter.api.DisplayNameGenerator$IndicativeSentences - - - --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor$ClassInfo - - - --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor$LifecycleMethods - - - --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassTemplateInvocationTestDescriptor - - - --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassTemplateTestDescriptor - - - --initialize-at-build-time=org.junit.jupiter.engine.descriptor.DynamicDescendantFilter$Mode - - - --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ExclusiveResourceCollector$1 - - - --initialize-at-build-time=org.junit.jupiter.engine.descriptor.MethodBasedTestDescriptor$MethodInfo - - - --initialize-at-build-time=org.junit.jupiter.engine.discovery.ClassSelectorResolver$DummyClassTemplateInvocationContext - - - --initialize-at-build-time=org.junit.platform.engine.support.store.NamespacedHierarchicalStore$EvaluatedValue - - --initialize-at-build-time=org.junit.platform.launcher.core.DiscoveryIssueNotifier - - - --initialize-at-build-time=org.junit.platform.launcher.core.HierarchicalOutputDirectoryProvider - - - --initialize-at-build-time=org.junit.platform.launcher.core.LauncherDiscoveryResult$EngineResultInfo - - - --initialize-at-build-time=org.junit.platform.suite.engine.SuiteTestDescriptor$LifecycleMethods - - - --initialize-at-build-time=org.junit.platform.commons.logging.LoggerFactory$DelegatingLogger - - - --initialize-at-build-time=org.junit.jupiter.engine.execution.ConditionEvaluator - - - --initialize-at-build-time=org.junit.jupiter.engine.execution.InterceptingExecutableInvoker - - - --initialize-at-build-time=org.junit.jupiter.api.extension.ConditionEvaluationResult - - - --initialize-at-build-time=org.junit.jupiter.engine.execution.InvocationInterceptorChain - - - - - org.springframework.boot spring-boot-maven-plugin - - com.diffplug.spotless - spotless-maven-plugin - 3.1.0 - - - - - - - - verify - - check - - - - + + + java17-plus + + [17,) + + + + + org.graalvm.buildtools + native-maven-plugin + + + + + --initialize-at-build-time=org.junit.jupiter.api.DisplayNameGenerator$IndicativeSentences + + + --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor$ClassInfo + + + --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor$LifecycleMethods + + + --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassTemplateInvocationTestDescriptor + + + --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassTemplateTestDescriptor + + + --initialize-at-build-time=org.junit.jupiter.engine.descriptor.DynamicDescendantFilter$Mode + + + --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ExclusiveResourceCollector$1 + + + --initialize-at-build-time=org.junit.jupiter.engine.descriptor.MethodBasedTestDescriptor$MethodInfo + + + --initialize-at-build-time=org.junit.jupiter.engine.discovery.ClassSelectorResolver$DummyClassTemplateInvocationContext + + + --initialize-at-build-time=org.junit.platform.engine.support.store.NamespacedHierarchicalStore$EvaluatedValue + + --initialize-at-build-time=org.junit.platform.launcher.core.DiscoveryIssueNotifier + + + --initialize-at-build-time=org.junit.platform.launcher.core.HierarchicalOutputDirectoryProvider + + + --initialize-at-build-time=org.junit.platform.launcher.core.LauncherDiscoveryResult$EngineResultInfo + + + --initialize-at-build-time=org.junit.platform.suite.engine.SuiteTestDescriptor$LifecycleMethods + + + --initialize-at-build-time=org.junit.platform.commons.logging.LoggerFactory$DelegatingLogger + + + --initialize-at-build-time=org.junit.jupiter.engine.execution.ConditionEvaluator + + + --initialize-at-build-time=org.junit.jupiter.engine.execution.InterceptingExecutableInvoker + + + --initialize-at-build-time=org.junit.jupiter.api.extension.ConditionEvaluationResult + + + --initialize-at-build-time=org.junit.jupiter.engine.execution.InvocationInterceptorChain + + + + + + + com.diffplug.spotless + spotless-maven-plugin + 3.1.0 + + + + + + + + verify + + check + + + + + + + + + diff --git a/pom.xml b/pom.xml index 6f3d5282a..4273703ef 100644 --- a/pom.xml +++ b/pom.xml @@ -26,8 +26,10 @@ 4.33.4 33.5.0-jre 6.0.2 + 5.9.3 2.16.0-alpha 8 + 25 0.70 false false @@ -69,6 +71,67 @@ 3.0.2 provided + + + org.junit.jupiter + junit-jupiter + ${junit-jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit-jupiter.version} + test + + + org.mockito + mockito-core + 5.21.0 + test + + + org.assertj + assertj-core + 3.27.6 + test + + + com.google.guava + guava + ${guava.version} + test + + + org.slf4j + slf4j-simple + 2.0.17 + test + + + org.junit-pioneer + junit-pioneer + 2.3.0 + test + + + org.awaitility + awaitility + 4.3.0 + test + + + org.wiremock + wiremock + 3.13.2 + test + + + org.hamcrest + hamcrest-core + + + @@ -249,51 +312,26 @@ maven-compiler-plugin + ${java.version} ${java.version} ${java.version} - 25 - 25 - 25 + ${test.java.version} + ${test.java.version} + ${test.java.version} true -Xlint:all,-serial,-processing,-options ${warnings} --should-stop=ifError=FLOW -XDcompilePolicy=simple - - -Xplugin:ErrorProne - -Xep:AlmostJavadoc:OFF - -Xep:MissingSummary:OFF - -Xep:LongDoubleConversion:OFF - -Xep:StringSplitter:OFF - -XepExcludedPaths:(.*/generated/.*|.*/src/test/java/.*|.*/examples/.*|.*/integration-tests/.*) - -XepOpt:NullAway:AnnotatedPackages=io.prometheus.metrics - - - - com.google.errorprone - error_prone_core - 2.46.0 - - - com.uber.nullaway - nullaway - 0.13.0 - - - org.codehaus.mojo versions-maven-plugin - 2.21.0 + 2.20.1 file://${project.basedir}/version-rules.xml @@ -301,6 +339,31 @@ + + + + org.junit + junit-bom + ${junit-jupiter.version} + pom + import + + + io.opentelemetry.instrumentation + opentelemetry-instrumentation-bom-alpha + ${otel.instrumentation.version} + pom + import + + + io.opentelemetry + opentelemetry-proto + 1.7.1-alpha + test + + + + @@ -340,93 +403,6 @@ benchmarks integration-tests - - - - org.junit - junit-bom - ${junit-jupiter.version} - pom - import - - - io.opentelemetry.instrumentation - opentelemetry-instrumentation-bom-alpha - ${otel.instrumentation.version} - pom - import - - - io.opentelemetry - opentelemetry-proto - 1.7.1-alpha - test - - - - - - - org.junit.jupiter - junit-jupiter - ${junit-jupiter.version} - test - - - org.junit.jupiter - junit-jupiter-params - ${junit-jupiter.version} - test - - - org.mockito - mockito-core - 5.21.0 - test - - - org.assertj - assertj-core - 3.27.6 - test - - - com.google.guava - guava - ${guava.version} - test - - - org.slf4j - slf4j-simple - 2.0.17 - test - - - org.junit-pioneer - junit-pioneer - 2.3.0 - test - - - org.awaitility - awaitility - 4.3.0 - test - - - org.wiremock - wiremock - 3.13.2 - test - - - org.hamcrest - hamcrest-core - - - - javadoc @@ -448,6 +424,106 @@ + + java8-11 + + [1.8,12) + + + ${junit-jupiter.version.java8} + + + + + maven-compiler-plugin + + + + ${java.version} + ${java.version} + ${test.java.version} + ${test.java.version} + true + + -Xlint:all,-serial,-processing,-options + ${warnings} + + -XDcompilePolicy=simple + + + + + + + + errorprone + + [21,) + + !skipErrorProne + true + + + + + + maven-compiler-plugin + + true + + -Xlint:all,-serial,-processing,-options + ${warnings} + --should-stop=ifError=FLOW + -XDcompilePolicy=simple + -Xplugin:ErrorProne + -Xep:AlmostJavadoc:OFF + -Xep:MissingSummary:OFF + -Xep:LongDoubleConversion:OFF + -Xep:StringSplitter:OFF + -XepExcludedPaths:(.*/generated/.*|.*/src/test/java/.*|.*/examples/.*|.*/integration-tests/.*) + -XepOpt:NullAway:AnnotatedPackages=io.prometheus.metrics + + + + --add-exports + jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED + --add-exports + jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED + --add-exports + jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED + --add-exports + jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED + --add-exports + jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED + --add-exports + jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED + --add-exports + jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED + --add-exports + jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED + --add-opens + jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED + --add-opens + jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED + + + + + com.google.errorprone + error_prone_core + 2.46.0 + + + com.uber.nullaway + nullaway + 0.12.15 + + + + + + + release diff --git a/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExemplarsPropertiesTest.java b/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExemplarsPropertiesTest.java index 53f7ae072..21b0aafd8 100644 --- a/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExemplarsPropertiesTest.java +++ b/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExemplarsPropertiesTest.java @@ -11,28 +11,33 @@ class ExemplarsPropertiesTest { @Test void load() { - ExemplarsProperties properties = - load( - Map.of( - "io.prometheus.exemplars.minRetentionPeriodSeconds", "1", - "io.prometheus.exemplars.maxRetentionPeriodSeconds", "2", - "io.prometheus.exemplars.sampleIntervalMilliseconds", "3")); + Map props1 = new HashMap<>(); + props1.put("io.prometheus.exemplars.minRetentionPeriodSeconds", "1"); + props1.put("io.prometheus.exemplars.maxRetentionPeriodSeconds", "2"); + props1.put("io.prometheus.exemplars.sampleIntervalMilliseconds", "3"); + ExemplarsProperties properties = load(props1); assertThat(properties.getMinRetentionPeriodSeconds()).isOne(); assertThat(properties.getMaxRetentionPeriodSeconds()).isEqualTo(2); assertThat(properties.getSampleIntervalMilliseconds()).isEqualTo(3); + Map props2 = new HashMap<>(); + props2.put("io.prometheus.exemplars.minRetentionPeriodSeconds", "-1"); assertThatExceptionOfType(PrometheusPropertiesException.class) - .isThrownBy(() -> load(Map.of("io.prometheus.exemplars.minRetentionPeriodSeconds", "-1"))) + .isThrownBy(() -> load(props2)) .withMessage( "io.prometheus.exemplars.minRetentionPeriodSeconds: Expecting value > 0. Found: -1"); + Map props3 = new HashMap<>(); + props3.put("io.prometheus.exemplars.maxRetentionPeriodSeconds", "0"); assertThatExceptionOfType(PrometheusPropertiesException.class) - .isThrownBy(() -> load(Map.of("io.prometheus.exemplars.maxRetentionPeriodSeconds", "0"))) + .isThrownBy(() -> load(props3)) .withMessage( "io.prometheus.exemplars.maxRetentionPeriodSeconds: Expecting value > 0. Found: 0"); + Map props4 = new HashMap<>(); + props4.put("io.prometheus.exemplars.sampleIntervalMilliseconds", "-1"); assertThatExceptionOfType(PrometheusPropertiesException.class) - .isThrownBy(() -> load(Map.of("io.prometheus.exemplars.sampleIntervalMilliseconds", "-1"))) + .isThrownBy(() -> load(props4)) .withMessage( "io.prometheus.exemplars.sampleIntervalMilliseconds: Expecting value > 0. Found: -1"); } diff --git a/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterFilterPropertiesTest.java b/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterFilterPropertiesTest.java index 0b30fbd43..4f5ee3d9d 100644 --- a/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterFilterPropertiesTest.java +++ b/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterFilterPropertiesTest.java @@ -10,13 +10,12 @@ class ExporterFilterPropertiesTest { @Test void load() { - ExporterFilterProperties properties = - load( - Map.of( - "io.prometheus.exporter.filter.metricNameMustBeEqualTo", "a,b,c", - "io.prometheus.exporter.filter.metricNameMustNotBeEqualTo", "d,e,f", - "io.prometheus.exporter.filter.metricNameMustStartWith", "g,h,i", - "io.prometheus.exporter.filter.metricNameMustNotStartWith", "j,k,l")); + Map props = new HashMap<>(); + props.put("io.prometheus.exporter.filter.metricNameMustBeEqualTo", "a,b,c"); + props.put("io.prometheus.exporter.filter.metricNameMustNotBeEqualTo", "d,e,f"); + props.put("io.prometheus.exporter.filter.metricNameMustStartWith", "g,h,i"); + props.put("io.prometheus.exporter.filter.metricNameMustNotStartWith", "j,k,l"); + ExporterFilterProperties properties = load(props); assertThat(properties.getAllowedMetricNames()).containsExactly("a", "b", "c"); assertThat(properties.getExcludedMetricNames()).containsExactly("d", "e", "f"); assertThat(properties.getAllowedMetricNamePrefixes()).containsExactly("g", "h", "i"); diff --git a/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterHttpServerPropertiesTest.java b/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterHttpServerPropertiesTest.java index ae83c305e..1edc8e688 100644 --- a/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterHttpServerPropertiesTest.java +++ b/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterHttpServerPropertiesTest.java @@ -11,13 +11,16 @@ class ExporterHttpServerPropertiesTest { @Test void load() { - ExporterHttpServerProperties properties = - load(Map.of("io.prometheus.exporter.httpServer.port", "1")); + Map props1 = new HashMap<>(); + props1.put("io.prometheus.exporter.httpServer.port", "1"); + ExporterHttpServerProperties properties = load(props1); assertThat(properties.getPort()).isOne(); assertThat(properties.isPreferUncompressedResponse()).isFalse(); + Map props2 = new HashMap<>(); + props2.put("io.prometheus.exporter.httpServer.port", "0"); assertThatExceptionOfType(PrometheusPropertiesException.class) - .isThrownBy(() -> load(Map.of("io.prometheus.exporter.httpServer.port", "0"))) + .isThrownBy(() -> load(props2)) .withMessage("io.prometheus.exporter.httpServer.port: Expecting value > 0. Found: 0"); } diff --git a/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterOpenTelemetryPropertiesTest.java b/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterOpenTelemetryPropertiesTest.java index 7ba275570..1c609eedf 100644 --- a/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterOpenTelemetryPropertiesTest.java +++ b/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterOpenTelemetryPropertiesTest.java @@ -10,29 +10,29 @@ class ExporterOpenTelemetryPropertiesTest { @Test void load() { - ExporterOpenTelemetryProperties properties = - load( - Map.of( - "io.prometheus.exporter.opentelemetry.protocol", "grpc", - "io.prometheus.exporter.opentelemetry.endpoint", "http://localhost:8080", - "io.prometheus.exporter.opentelemetry.headers", "key1=value1,key2=value2", - "io.prometheus.exporter.opentelemetry.intervalSeconds", "10", - "io.prometheus.exporter.opentelemetry.timeoutSeconds", "5", - "io.prometheus.exporter.opentelemetry.serviceName", "serviceName", - "io.prometheus.exporter.opentelemetry.serviceNamespace", "serviceNamespace", - "io.prometheus.exporter.opentelemetry.serviceInstanceId", "serviceInstanceId", - "io.prometheus.exporter.opentelemetry.serviceVersion", "serviceVersion", - "io.prometheus.exporter.opentelemetry.resourceAttributes", - "key1=value1,key2=value2")); + Map props = new HashMap<>(); + props.put("io.prometheus.exporter.opentelemetry.protocol", "grpc"); + props.put("io.prometheus.exporter.opentelemetry.endpoint", "http://localhost:8080"); + props.put("io.prometheus.exporter.opentelemetry.headers", "key1=value1,key2=value2"); + props.put("io.prometheus.exporter.opentelemetry.intervalSeconds", "10"); + props.put("io.prometheus.exporter.opentelemetry.timeoutSeconds", "5"); + props.put("io.prometheus.exporter.opentelemetry.serviceName", "serviceName"); + props.put("io.prometheus.exporter.opentelemetry.serviceNamespace", "serviceNamespace"); + props.put("io.prometheus.exporter.opentelemetry.serviceInstanceId", "serviceInstanceId"); + props.put("io.prometheus.exporter.opentelemetry.serviceVersion", "serviceVersion"); + props.put("io.prometheus.exporter.opentelemetry.resourceAttributes", "key1=value1,key2=value2"); + ExporterOpenTelemetryProperties properties = load(props); assertValues(properties); } private static void assertValues(ExporterOpenTelemetryProperties properties) { + Map expectedHeaders = new HashMap<>(); + expectedHeaders.put("key1", "value1"); + expectedHeaders.put("key2", "value2"); assertThat(properties.getProtocol()).isEqualTo("grpc"); assertThat(properties.getEndpoint()).isEqualTo("http://localhost:8080"); - assertThat(properties.getHeaders()) - .containsExactlyInAnyOrderEntriesOf(Map.of("key1", "value1", "key2", "value2")); + assertThat(properties.getHeaders()).containsExactlyInAnyOrderEntriesOf(expectedHeaders); assertThat(properties.getInterval()).isEqualTo("10s"); assertThat(properties.getTimeout()).isEqualTo("5s"); assertThat(properties.getServiceName()).isEqualTo("serviceName"); @@ -40,7 +40,7 @@ private static void assertValues(ExporterOpenTelemetryProperties properties) { assertThat(properties.getServiceInstanceId()).isEqualTo("serviceInstanceId"); assertThat(properties.getServiceVersion()).isEqualTo("serviceVersion"); assertThat(properties.getResourceAttributes()) - .containsExactlyInAnyOrderEntriesOf(Map.of("key1", "value1", "key2", "value2")); + .containsExactlyInAnyOrderEntriesOf(expectedHeaders); } private static ExporterOpenTelemetryProperties load(Map map) { diff --git a/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterPropertiesTest.java b/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterPropertiesTest.java index dec9e03a5..d1568625d 100644 --- a/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterPropertiesTest.java +++ b/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterPropertiesTest.java @@ -11,30 +11,24 @@ class ExporterPropertiesTest { @Test void load() { - ExporterProperties properties = - load( - new HashMap<>( - Map.of( - "io.prometheus.exporter.includeCreatedTimestamps", "true", - "io.prometheus.exporter.exemplarsOnAllMetricTypes", "true"))); + Map props1 = new HashMap<>(); + props1.put("io.prometheus.exporter.includeCreatedTimestamps", "true"); + props1.put("io.prometheus.exporter.exemplarsOnAllMetricTypes", "true"); + ExporterProperties properties = load(props1); assertThat(properties.getIncludeCreatedTimestamps()).isTrue(); assertThat(properties.getExemplarsOnAllMetricTypes()).isTrue(); + Map props2 = new HashMap<>(); + props2.put("io.prometheus.exporter.includeCreatedTimestamps", "invalid"); assertThatExceptionOfType(PrometheusPropertiesException.class) - .isThrownBy( - () -> - load( - new HashMap<>( - Map.of("io.prometheus.exporter.includeCreatedTimestamps", "invalid")))) + .isThrownBy(() -> load(props2)) .withMessage( "io.prometheus.exporter.includeCreatedTimestamps: Expecting 'true' or 'false'. Found:" + " invalid"); + Map props3 = new HashMap<>(); + props3.put("io.prometheus.exporter.exemplarsOnAllMetricTypes", "invalid"); assertThatExceptionOfType(PrometheusPropertiesException.class) - .isThrownBy( - () -> - load( - new HashMap<>( - Map.of("io.prometheus.exporter.exemplarsOnAllMetricTypes", "invalid")))) + .isThrownBy(() -> load(props3)) .withMessage( "io.prometheus.exporter.exemplarsOnAllMetricTypes: Expecting 'true' or 'false'. Found:" + " invalid"); diff --git a/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterPushgatewayPropertiesTest.java b/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterPushgatewayPropertiesTest.java index e1e06348a..ab0222089 100644 --- a/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterPushgatewayPropertiesTest.java +++ b/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterPushgatewayPropertiesTest.java @@ -12,19 +12,20 @@ class ExporterPushgatewayPropertiesTest { @Test void load() { - ExporterPushgatewayProperties properties = - load( - Map.of( - "io.prometheus.exporter.pushgateway.address", "http://localhost", - "io.prometheus.exporter.pushgateway.job", "job", - "io.prometheus.exporter.pushgateway.scheme", "http")); + Map props1 = new HashMap<>(); + props1.put("io.prometheus.exporter.pushgateway.address", "http://localhost"); + props1.put("io.prometheus.exporter.pushgateway.job", "job"); + props1.put("io.prometheus.exporter.pushgateway.scheme", "http"); + ExporterPushgatewayProperties properties = load(props1); assertThat(properties.getAddress()).isEqualTo("http://localhost"); assertThat(properties.getJob()).isEqualTo("job"); assertThat(properties.getScheme()).isEqualTo("http"); + Map props2 = new HashMap<>(); + props2.put("io.prometheus.exporter.pushgateway.scheme", "foo"); assertThatExceptionOfType(PrometheusPropertiesException.class) - .isThrownBy(() -> load(Map.of("io.prometheus.exporter.pushgateway.scheme", "foo"))) + .isThrownBy(() -> load(props2)) .withMessage( "io.prometheus.exporter.pushgateway.scheme: Illegal value. Expecting 'http' or 'https'." + " Found: foo"); diff --git a/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/UtilTest.java b/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/UtilTest.java index 23ffbd33b..579142f59 100644 --- a/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/UtilTest.java +++ b/prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/UtilTest.java @@ -11,14 +11,16 @@ class UtilTest { @Test void loadOptionalDuration_positive() { - Map properties = new HashMap<>(Map.of("foo", "5")); + Map properties = new HashMap<>(); + properties.put("foo", "5"); assertThat(Util.loadOptionalDuration("foo", properties)).isEqualTo(Duration.ofSeconds(5)); } @Test void loadOptionalDuration_zero() { - Map properties = new HashMap<>(Map.of("foo", "0")); + Map properties = new HashMap<>(); + properties.put("foo", "0"); assertThat(Util.loadOptionalDuration("foo", properties)).isNull(); } @@ -32,7 +34,8 @@ void loadOptionalDuration_missing() { @Test void loadOptionalDuration_negative_throws() { - Map properties = new HashMap<>(Map.of("foo", "-1")); + Map properties = new HashMap<>(); + properties.put("foo", "-1"); assertThatExceptionOfType(PrometheusPropertiesException.class) .isThrownBy(() -> Util.loadOptionalDuration("foo", properties)) @@ -41,7 +44,8 @@ void loadOptionalDuration_negative_throws() { @Test void loadOptionalDuration_invalidNumber_throws() { - Map properties = new HashMap<>(Map.of("foo", "abc")); + Map properties = new HashMap<>(); + properties.put("foo", "abc"); assertThatExceptionOfType(PrometheusPropertiesException.class) .isThrownBy(() -> Util.loadOptionalDuration("foo", properties)) diff --git a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/CounterTest.java b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/CounterTest.java index c39bf1ad6..1a890c487 100644 --- a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/CounterTest.java +++ b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/CounterTest.java @@ -220,24 +220,34 @@ public void testExemplarSampler() throws Exception { @Override public String getCurrentTraceId() { - return switch (callNumber) { - case 1 -> "abc"; - case 3 -> "def"; - case 4 -> "123"; - case 5 -> "bab"; - default -> throw new RuntimeException("unexpected call"); - }; + switch (callNumber) { + case 1: + return "abc"; + case 3: + return "def"; + case 4: + return "123"; + case 5: + return "bab"; + default: + throw new RuntimeException("unexpected call"); + } } @Override public String getCurrentSpanId() { - return switch (callNumber) { - case 1 -> "123"; - case 3 -> "456"; - case 4 -> "abc"; - case 5 -> "cdc"; - default -> throw new RuntimeException("unexpected call"); - }; + switch (callNumber) { + case 1: + return "123"; + case 3: + return "456"; + case 4: + return "abc"; + case 5: + return "cdc"; + default: + throw new RuntimeException("unexpected call"); + } } @Override diff --git a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/GaugeTest.java b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/GaugeTest.java index 108fc05ce..21479a5b9 100644 --- a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/GaugeTest.java +++ b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/GaugeTest.java @@ -122,24 +122,34 @@ public void testExemplarSampler() throws Exception { @Override public String getCurrentTraceId() { - return switch (callNumber) { - case 1 -> "abc"; - case 3 -> "def"; - case 4 -> "123"; - case 5 -> "bab"; - default -> throw new RuntimeException("unexpected call"); - }; + switch (callNumber) { + case 1: + return "abc"; + case 3: + return "def"; + case 4: + return "123"; + case 5: + return "bab"; + default: + throw new RuntimeException("unexpected call"); + } } @Override public String getCurrentSpanId() { - return switch (callNumber) { - case 1 -> "123"; - case 3 -> "456"; - case 4 -> "abc"; - case 5 -> "cdc"; - default -> throw new RuntimeException("unexpected call"); - }; + switch (callNumber) { + case 1: + return "123"; + case 3: + return "456"; + case 4: + return "abc"; + case 5: + return "cdc"; + default: + throw new RuntimeException("unexpected call"); + } } @Override diff --git a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java index 0a17dccd3..0fb550a60 100644 --- a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java +++ b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java @@ -923,24 +923,22 @@ public void testDefaults() throws IOException { + "} }"; String expectedTextFormat = // default classic buckets - """ - # TYPE test histogram - test_bucket{le="0.005"} 0 - test_bucket{le="0.01"} 0 - test_bucket{le="0.025"} 0 - test_bucket{le="0.05"} 0 - test_bucket{le="0.1"} 0 - test_bucket{le="0.25"} 0 - test_bucket{le="0.5"} 1 - test_bucket{le="1.0"} 1 - test_bucket{le="2.5"} 1 - test_bucket{le="5.0"} 1 - test_bucket{le="10.0"} 1 - test_bucket{le="+Inf"} 1 - test_count 1 - test_sum 0.5 - # EOF - """; + "# TYPE test histogram\n" + + "test_bucket{le=\"0.005\"} 0\n" + + "test_bucket{le=\"0.01\"} 0\n" + + "test_bucket{le=\"0.025\"} 0\n" + + "test_bucket{le=\"0.05\"} 0\n" + + "test_bucket{le=\"0.1\"} 0\n" + + "test_bucket{le=\"0.25\"} 0\n" + + "test_bucket{le=\"0.5\"} 1\n" + + "test_bucket{le=\"1.0\"} 1\n" + + "test_bucket{le=\"2.5\"} 1\n" + + "test_bucket{le=\"5.0\"} 1\n" + + "test_bucket{le=\"10.0\"} 1\n" + + "test_bucket{le=\"+Inf\"} 1\n" + + "test_count 1\n" + + "test_sum 0.5\n" + + "# EOF\n"; // protobuf Metrics.MetricFamily protobufData = diff --git a/prometheus-metrics-exporter-httpserver/src/test/java/io/prometheus/metrics/exporter/httpserver/HTTPServerTest.java b/prometheus-metrics-exporter-httpserver/src/test/java/io/prometheus/metrics/exporter/httpserver/HTTPServerTest.java index 9b7f658de..5959c5c91 100644 --- a/prometheus-metrics-exporter-httpserver/src/test/java/io/prometheus/metrics/exporter/httpserver/HTTPServerTest.java +++ b/prometheus-metrics-exporter-httpserver/src/test/java/io/prometheus/metrics/exporter/httpserver/HTTPServerTest.java @@ -12,6 +12,7 @@ import io.prometheus.metrics.model.registry.PrometheusScrapeRequest; import io.prometheus.metrics.model.snapshots.MetricSnapshots; import java.io.IOException; +import java.lang.reflect.Method; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; @@ -45,7 +46,7 @@ public Result authenticate(HttpExchange exchange) { HttpHandler handler = exchange -> { boolean found = false; - Subject current = Subject.current(); + Subject current = getCurrentSubject(); for (Principal p : current.getPrincipals()) { if (user.equals(p.getName())) { found = true; @@ -186,4 +187,27 @@ void healthDisabled() throws IOException { "204", "/-/healthy"); } + + /** + * Get current Subject using reflection to support both Java 17 and Java 18+. + * + *

Java 18+ has Subject.current(), but Java 17 and earlier require + * Subject.getSubject(AccessController.getContext()). + */ + @SuppressWarnings({"removal"}) + private static Subject getCurrentSubject() { + try { + Method currentMethod = Subject.class.getMethod("current"); + return (Subject) currentMethod.invoke(null); + } catch (NoSuchMethodException e) { + // Fall back to pre-Java 18 API + try { + return Subject.getSubject(java.security.AccessController.getContext()); + } catch (Exception ex) { + throw new RuntimeException("Failed to get current Subject", ex); + } + } catch (Exception e) { + throw new RuntimeException("Failed to invoke Subject.current()", e); + } + } } diff --git a/prometheus-metrics-exporter-opentelemetry/src/test/java/io/prometheus/metrics/exporter/opentelemetry/OtelAutoConfigTest.java b/prometheus-metrics-exporter-opentelemetry/src/test/java/io/prometheus/metrics/exporter/opentelemetry/OtelAutoConfigTest.java index 5a9103565..37c79b43f 100644 --- a/prometheus-metrics-exporter-opentelemetry/src/test/java/io/prometheus/metrics/exporter/opentelemetry/OtelAutoConfigTest.java +++ b/prometheus-metrics-exporter-opentelemetry/src/test/java/io/prometheus/metrics/exporter/opentelemetry/OtelAutoConfigTest.java @@ -65,7 +65,7 @@ public static Stream testCases() { "values from builder", new TestCase() .expectedProperties( - Map.of( + ImmutableMap.of( "otel.exporter.otlp.protocol", Optional.of("http/protobuf"), "otel.exporter.otlp.endpoint", @@ -79,7 +79,7 @@ public static Stream testCases() { "otel.service.name", Optional.of("builder-service"))) .expectedResourceAttributes( - Map.of( + ImmutableMap.of( "key", "builder-value", "service.name", diff --git a/prometheus-metrics-exporter-opentelemetry/src/test/java/io/prometheus/metrics/exporter/opentelemetry/otelmodel/PrometheusMetricDataTest.java b/prometheus-metrics-exporter-opentelemetry/src/test/java/io/prometheus/metrics/exporter/opentelemetry/otelmodel/PrometheusMetricDataTest.java index fb5542538..ecc807ab3 100644 --- a/prometheus-metrics-exporter-opentelemetry/src/test/java/io/prometheus/metrics/exporter/opentelemetry/otelmodel/PrometheusMetricDataTest.java +++ b/prometheus-metrics-exporter-opentelemetry/src/test/java/io/prometheus/metrics/exporter/opentelemetry/otelmodel/PrometheusMetricDataTest.java @@ -1,41 +1,44 @@ package io.prometheus.metrics.exporter.opentelemetry.otelmodel; -import static java.util.Map.entry; import static org.junit.jupiter.api.Assertions.*; import io.prometheus.metrics.model.snapshots.Unit; +import java.util.HashMap; import java.util.Map; import org.junit.jupiter.api.Test; class PrometheusMetricDataTest { Map translations = - Map.ofEntries( - entry("days", "d"), - entry("hours", "h"), - entry("minutes", "min"), - entry("seconds", "s"), - entry("milliseconds", "ms"), - entry("microseconds", "us"), - entry("nanoseconds", "ns"), - entry("bytes", "By"), - entry("kibibytes", "KiBy"), - entry("mebibytes", "MiBy"), - entry("gibibytes", "GiBy"), - entry("tibibytes", "TiBy"), - entry("kilobytes", "KBy"), - entry("megabytes", "MBy"), - entry("gigabytes", "GBy"), - entry("terabytes", "TBy"), - entry("meters", "m"), - entry("volts", "V"), - entry("amperes", "A"), - entry("joules", "J"), - entry("watts", "W"), - entry("grams", "g"), - entry("celsius", "Cel"), - entry("hertz", "Hz"), - entry("percent", "%")); + new HashMap() { + { + put("days", "d"); + put("hours", "h"); + put("minutes", "min"); + put("seconds", "s"); + put("milliseconds", "ms"); + put("microseconds", "us"); + put("nanoseconds", "ns"); + put("bytes", "By"); + put("kibibytes", "KiBy"); + put("mebibytes", "MiBy"); + put("gibibytes", "GiBy"); + put("tibibytes", "TiBy"); + put("kilobytes", "KBy"); + put("megabytes", "MBy"); + put("gigabytes", "GBy"); + put("terabytes", "TBy"); + put("meters", "m"); + put("volts", "V"); + put("amperes", "A"); + put("joules", "J"); + put("watts", "W"); + put("grams", "g"); + put("celsius", "Cel"); + put("hertz", "Hz"); + put("percent", "%"); + } + }; @Test void convertUnit() { diff --git a/prometheus-metrics-exposition-textformats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java b/prometheus-metrics-exposition-textformats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java index 8a31e41b1..e1b7510ba 100644 --- a/prometheus-metrics-exposition-textformats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java +++ b/prometheus-metrics-exposition-textformats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java @@ -240,17 +240,8 @@ public void testCounterComplete() throws IOException { @Test public void testCounterMinimal() throws IOException { - String openMetricsText = - """ - # TYPE my_counter counter - my_counter_total 1.1 - # EOF - """; - String prometheusText = - """ - # TYPE my_counter_total counter - my_counter_total 1.1 - """; + String openMetricsText = "# TYPE my_counter counter\n" + "my_counter_total 1.1\n" + "# EOF\n"; + String prometheusText = "# TYPE my_counter_total counter\n" + "my_counter_total 1.1\n"; String prometheusProtobuf = "name: \"my_counter_total\" type: COUNTER metric { counter { value: 1.1 } }"; CounterSnapshot counter = @@ -268,16 +259,12 @@ public void testCounterMinimal() throws IOException { @Test public void testCounterWithDots() throws IOException { String openMetricsText = - """ - # TYPE U__my_2e_request_2e_count counter - U__my_2e_request_2e_count_total{U__http_2e_path="/hello"} 3.0 # {U__some_2e_exemplar_2e_key="some value"} 3.0 1690298864.383 - # EOF - """; + "# TYPE U__my_2e_request_2e_count counter\n" + + "U__my_2e_request_2e_count_total{U__http_2e_path=\"/hello\"} 3.0 # {U__some_2e_exemplar_2e_key=\"some value\"} 3.0 1690298864.383\n" + + "# EOF\n"; String prometheusText = - """ - # TYPE my_request_count_total counter - my_request_count_total{http_path="/hello"} 3.0 - """; + "# TYPE my_request_count_total counter\n" + + "my_request_count_total{http_path=\"/hello\"} 3.0\n"; String prometheusProtobuf = // @formatter:off "name: \"my_request_count_total\" " @@ -391,16 +378,9 @@ public void testGaugeComplete() throws IOException { @Test public void testGaugeMinimal() throws IOException { String openMetricsText = - """ - # TYPE temperature_centigrade gauge - temperature_centigrade 22.3 - # EOF - """; + "# TYPE temperature_centigrade gauge\n" + "temperature_centigrade 22.3\n" + "# EOF\n"; String prometheusText = - """ - # TYPE temperature_centigrade gauge - temperature_centigrade 22.3 - """; + "# TYPE temperature_centigrade gauge\n" + "temperature_centigrade 22.3\n"; String prometheusProtobuf = "name: \"temperature_centigrade\" type: GAUGE metric { gauge { value: 22.3 } }"; GaugeSnapshot gauge = @@ -418,13 +398,11 @@ public void testGaugeMinimal() throws IOException { @Test public void testGaugeWithDots() throws IOException { String openMetricsText = - """ - # TYPE U__my_2e_temperature_2e_celsius gauge - # UNIT U__my_2e_temperature_2e_celsius celsius - # HELP U__my_2e_temperature_2e_celsius Temperature - U__my_2e_temperature_2e_celsius{U__location_2e_id="data-center-1"} 23.0 - # EOF - """; + "# TYPE U__my_2e_temperature_2e_celsius gauge\n" + + "# UNIT U__my_2e_temperature_2e_celsius celsius\n" + + "# HELP U__my_2e_temperature_2e_celsius Temperature\n" + + "U__my_2e_temperature_2e_celsius{U__location_2e_id=\"data-center-1\"} 23.0\n" + + "# EOF\n"; String openMetricsTextWithExemplarsOnAllTimeSeries = "# TYPE my_temperature_celsius gauge\n" + "# UNIT my_temperature_celsius celsius\n" @@ -434,11 +412,9 @@ public void testGaugeWithDots() throws IOException { + "\n" + "# EOF\n"; String prometheusText = - """ - # HELP my_temperature_celsius Temperature - # TYPE my_temperature_celsius gauge - my_temperature_celsius{location_id="data-center-1"} 23.0 - """; + "# HELP my_temperature_celsius Temperature\n" + + "# TYPE my_temperature_celsius gauge\n" + + "my_temperature_celsius{location_id=\"data-center-1\"} 23.0\n"; String prometheusProtobuf = // @formatter:off "name: \"my_temperature_celsius\" " @@ -474,12 +450,10 @@ public void testGaugeWithDots() throws IOException { @Test public void testGaugeUTF8() throws IOException { String prometheusText = - """ - # HELP "gauge.name" gauge\\ndoc\\nstr"ing - # TYPE "gauge.name" gauge - {"gauge.name","name.1"="Björn","name*2"="佖佥"} 3.14E42 - {"gauge.name","name.1"="val with\\nnew line","name*2"="val with \\\\backslash and \\"quotes\\""} +Inf - """; + "# HELP \"gauge.name\" gauge\\ndoc\\nstr\"ing\n" + + "# TYPE \"gauge.name\" gauge\n" + + "{\"gauge.name\",\"name.1\"=\"Björn\",\"name*2\"=\"佖佥\"} 3.14E42\n" + + "{\"gauge.name\",\"name.1\"=\"val with\\nnew line\",\"name*2\"=\"val with \\\\backslash and \\\"quotes\\\"\"} +Inf\n"; GaugeSnapshot gauge = GaugeSnapshot.builder() .name("gauge.name") @@ -801,21 +775,17 @@ public void testSummaryComplete() throws IOException { @Test public void testSummaryWithoutQuantiles() throws IOException { String openMetricsText = - """ - # TYPE latency_seconds summary - # UNIT latency_seconds seconds - # HELP latency_seconds latency - latency_seconds_count 3 - latency_seconds_sum 1.2 - # EOF - """; + "# TYPE latency_seconds summary\n" + + "# UNIT latency_seconds seconds\n" + + "# HELP latency_seconds latency\n" + + "latency_seconds_count 3\n" + + "latency_seconds_sum 1.2\n" + + "# EOF\n"; String prometheusText = - """ - # HELP latency_seconds latency - # TYPE latency_seconds summary - latency_seconds_count 3 - latency_seconds_sum 1.2 - """; + "# HELP latency_seconds latency\n" + + "# TYPE latency_seconds summary\n" + + "latency_seconds_count 3\n" + + "latency_seconds_sum 1.2\n"; String prometheusProtobuf = // @formatter:off "name: \"latency_seconds\" " @@ -845,16 +815,11 @@ public void testSummaryWithoutQuantiles() throws IOException { @Test public void testSummaryNoCountAndSum() throws IOException { String openMetricsText = - """ - # TYPE latency_seconds summary - latency_seconds{quantile="0.95"} 200.0 - # EOF - """; + "# TYPE latency_seconds summary\n" + + "latency_seconds{quantile=\"0.95\"} 200.0\n" + + "# EOF\n"; String prometheusText = - """ - # TYPE latency_seconds summary - latency_seconds{quantile="0.95"} 200.0 - """; + "# TYPE latency_seconds summary\n" + "latency_seconds{quantile=\"0.95\"} 200.0\n"; String prometheusProtobuf = // @formatter:off "name: \"latency_seconds\" " @@ -883,16 +848,8 @@ public void testSummaryNoCountAndSum() throws IOException { @Test public void testSummaryJustCount() throws IOException { String openMetricsText = - """ - # TYPE latency_seconds summary - latency_seconds_count 1 - # EOF - """; - String prometheusText = - """ - # TYPE latency_seconds summary - latency_seconds_count 1 - """; + "# TYPE latency_seconds summary\n" + "latency_seconds_count 1\n" + "# EOF\n"; + String prometheusText = "# TYPE latency_seconds summary\n" + "latency_seconds_count 1\n"; String prometheusProtobuf = // @formatter:off "name: \"latency_seconds\" " @@ -918,16 +875,8 @@ public void testSummaryJustCount() throws IOException { @Test public void testSummaryJustSum() throws IOException { String openMetricsText = - """ - # TYPE latency_seconds summary - latency_seconds_sum 12.3 - # EOF - """; - String prometheusText = - """ - # TYPE latency_seconds summary - latency_seconds_sum 12.3 - """; + "# TYPE latency_seconds summary\n" + "latency_seconds_sum 12.3\n" + "# EOF\n"; + String prometheusText = "# TYPE latency_seconds summary\n" + "latency_seconds_sum 12.3\n"; String prometheusProtobuf = // @formatter:off "name: \"latency_seconds\" " @@ -971,18 +920,14 @@ public void testSummaryEmptyData() throws IOException { @Test public void testSummaryEmptyAndNonEmpty() throws IOException { String openMetricsText = - """ - # TYPE latency_seconds summary - latency_seconds_count{path="/v2"} 2 - latency_seconds_sum{path="/v2"} 10.7 - # EOF - """; + "# TYPE latency_seconds summary\n" + + "latency_seconds_count{path=\"/v2\"} 2\n" + + "latency_seconds_sum{path=\"/v2\"} 10.7\n" + + "# EOF\n"; String prometheusText = - """ - # TYPE latency_seconds summary - latency_seconds_count{path="/v2"} 2 - latency_seconds_sum{path="/v2"} 10.7 - """; + "# TYPE latency_seconds summary\n" + + "latency_seconds_count{path=\"/v2\"} 2\n" + + "latency_seconds_sum{path=\"/v2\"} 10.7\n"; String prometheusProtobuf = // @formatter:off "name: \"latency_seconds\" " @@ -1017,14 +962,12 @@ public void testSummaryEmptyAndNonEmpty() throws IOException { @Test public void testSummaryWithDots() throws IOException { String openMetricsText = - """ - # TYPE U__my_2e_request_2e_duration_2e_seconds summary - # UNIT U__my_2e_request_2e_duration_2e_seconds seconds - # HELP U__my_2e_request_2e_duration_2e_seconds Request duration in seconds - U__my_2e_request_2e_duration_2e_seconds_count{U__http_2e_path="/hello"} 1 - U__my_2e_request_2e_duration_2e_seconds_sum{U__http_2e_path="/hello"} 0.03 - # EOF - """; + "# TYPE U__my_2e_request_2e_duration_2e_seconds summary\n" + + "# UNIT U__my_2e_request_2e_duration_2e_seconds seconds\n" + + "# HELP U__my_2e_request_2e_duration_2e_seconds Request duration in seconds\n" + + "U__my_2e_request_2e_duration_2e_seconds_count{U__http_2e_path=\"/hello\"} 1\n" + + "U__my_2e_request_2e_duration_2e_seconds_sum{U__http_2e_path=\"/hello\"} 0.03\n" + + "# EOF\n"; String openMetricsTextWithExemplarsOnAllTimeSeries = "# TYPE my_request_duration_seconds summary\n" + "# UNIT my_request_duration_seconds seconds\n" @@ -1035,12 +978,10 @@ public void testSummaryWithDots() throws IOException { + "my_request_duration_seconds_sum{http_path=\"/hello\"} 0.03\n" + "# EOF\n"; String prometheusText = - """ - # HELP my_request_duration_seconds Request duration in seconds - # TYPE my_request_duration_seconds summary - my_request_duration_seconds_count{http_path="/hello"} 1 - my_request_duration_seconds_sum{http_path="/hello"} 0.03 - """; + "# HELP my_request_duration_seconds Request duration in seconds\n" + + "# TYPE my_request_duration_seconds summary\n" + + "my_request_duration_seconds_count{http_path=\"/hello\"} 1\n" + + "my_request_duration_seconds_sum{http_path=\"/hello\"} 0.03\n"; String prometheusProtobuf = // @formatter:off "name: \"my_request_duration_seconds\" " @@ -1383,17 +1324,13 @@ public void testClassicHistogramMinimal() throws Exception { // In OpenMetrics a histogram can have a _count if and only if it has a _sum. // In Prometheus format, a histogram can have a _count without a _sum. String openMetricsText = - """ - # TYPE request_latency_seconds histogram - request_latency_seconds_bucket{le="+Inf"} 2 - # EOF - """; + "# TYPE request_latency_seconds histogram\n" + + "request_latency_seconds_bucket{le=\"+Inf\"} 2\n" + + "# EOF\n"; String prometheusText = - """ - # TYPE request_latency_seconds histogram - request_latency_seconds_bucket{le="+Inf"} 2 - request_latency_seconds_count 2 - """; + "# TYPE request_latency_seconds histogram\n" + + "request_latency_seconds_bucket{le=\"+Inf\"} 2\n" + + "request_latency_seconds_count 2\n"; String prometheusProtobuf = // @formatter:off "name: \"request_latency_seconds\" " @@ -1429,17 +1366,13 @@ public void testClassicHistogramMinimal() throws Exception { @Test public void testClassicHistogramMinimalWithDots() throws Exception { String openMetricsText = - """ - # TYPE "request.latency_seconds" histogram - {"request.latency_seconds_bucket",le="+Inf"} 2 - # EOF - """; + "# TYPE \"request.latency_seconds\" histogram\n" + + "{\"request.latency_seconds_bucket\",le=\"+Inf\"} 2\n" + + "# EOF\n"; String prometheusText = - """ - # TYPE request_latency_seconds histogram - request_latency_seconds_bucket{le="+Inf"} 2 - request_latency_seconds_count 2 - """; + "# TYPE request_latency_seconds histogram\n" + + "request_latency_seconds_bucket{le=\"+Inf\"} 2\n" + + "request_latency_seconds_count 2\n"; HistogramSnapshot histogram = HistogramSnapshot.builder() .name("request.latency_seconds") @@ -1460,20 +1393,16 @@ public void testClassicHistogramMinimalWithDots() throws Exception { @Test public void testClassicHistogramCountAndSum() throws Exception { String openMetricsText = - """ - # TYPE request_latency_seconds histogram - request_latency_seconds_bucket{le="+Inf"} 2 - request_latency_seconds_count 2 - request_latency_seconds_sum 3.2 - # EOF - """; + "# TYPE request_latency_seconds histogram\n" + + "request_latency_seconds_bucket{le=\"+Inf\"} 2\n" + + "request_latency_seconds_count 2\n" + + "request_latency_seconds_sum 3.2\n" + + "# EOF\n"; String prometheusText = - """ - # TYPE request_latency_seconds histogram - request_latency_seconds_bucket{le="+Inf"} 2 - request_latency_seconds_count 2 - request_latency_seconds_sum 3.2 - """; + "# TYPE request_latency_seconds histogram\n" + + "request_latency_seconds_bucket{le=\"+Inf\"} 2\n" + + "request_latency_seconds_count 2\n" + + "request_latency_seconds_sum 3.2\n"; String prometheusProtobuf = // @formatter:off "name: \"request_latency_seconds\" " @@ -1809,18 +1738,14 @@ public void testClassicGaugeHistogramMinimal() throws IOException { // In OpenMetrics a histogram can have a _count if and only if it has a _sum. // In Prometheus format, a histogram can have a _count without a _sum. String openMetricsText = - """ - # TYPE queue_size_bytes gaugehistogram - queue_size_bytes_bucket{le="+Inf"} 130 - # EOF - """; + "# TYPE queue_size_bytes gaugehistogram\n" + + "queue_size_bytes_bucket{le=\"+Inf\"} 130\n" + + "# EOF\n"; String prometheusText = - """ - # TYPE queue_size_bytes histogram - queue_size_bytes_bucket{le="+Inf"} 130 - # TYPE queue_size_bytes_gcount gauge - queue_size_bytes_gcount 130 - """; + "# TYPE queue_size_bytes histogram\n" + + "queue_size_bytes_bucket{le=\"+Inf\"} 130\n" + + "# TYPE queue_size_bytes_gcount gauge\n" + + "queue_size_bytes_gcount 130\n"; String prometheusProtobuf = // @formatter:off "name: \"queue_size_bytes\" " @@ -1857,22 +1782,18 @@ public void testClassicGaugeHistogramMinimal() throws IOException { @Test public void testClassicGaugeHistogramCountAndSum() throws IOException { String openMetricsText = - """ - # TYPE queue_size_bytes gaugehistogram - queue_size_bytes_bucket{le="+Inf"} 130 - queue_size_bytes_gcount 130 - queue_size_bytes_gsum 27000.0 - # EOF - """; + "# TYPE queue_size_bytes gaugehistogram\n" + + "queue_size_bytes_bucket{le=\"+Inf\"} 130\n" + + "queue_size_bytes_gcount 130\n" + + "queue_size_bytes_gsum 27000.0\n" + + "# EOF\n"; String prometheusText = - """ - # TYPE queue_size_bytes histogram - queue_size_bytes_bucket{le="+Inf"} 130 - # TYPE queue_size_bytes_gcount gauge - queue_size_bytes_gcount 130 - # TYPE queue_size_bytes_gsum gauge - queue_size_bytes_gsum 27000.0 - """; + "# TYPE queue_size_bytes histogram\n" + + "queue_size_bytes_bucket{le=\"+Inf\"} 130\n" + + "# TYPE queue_size_bytes_gcount gauge\n" + + "queue_size_bytes_gcount 130\n" + + "# TYPE queue_size_bytes_gsum gauge\n" + + "queue_size_bytes_gsum 27000.0\n"; String prometheusProtobuf = // @formatter:off "name: \"queue_size_bytes\" " @@ -1911,15 +1832,13 @@ public void testClassicGaugeHistogramCountAndSum() throws IOException { @Test public void testClassicHistogramWithDots() throws IOException { String openMetricsText = - """ - # TYPE U__my_2e_request_2e_duration_2e_seconds histogram - # UNIT U__my_2e_request_2e_duration_2e_seconds seconds - # HELP U__my_2e_request_2e_duration_2e_seconds Request duration in seconds - U__my_2e_request_2e_duration_2e_seconds_bucket{U__http_2e_path="/hello",le="+Inf"} 130 # {U__some_2e_exemplar_2e_key="some value"} 3.0 1690298864.383 - U__my_2e_request_2e_duration_2e_seconds_count{U__http_2e_path="/hello"} 130 - U__my_2e_request_2e_duration_2e_seconds_sum{U__http_2e_path="/hello"} 0.01 - # EOF - """; + "# TYPE U__my_2e_request_2e_duration_2e_seconds histogram\n" + + "# UNIT U__my_2e_request_2e_duration_2e_seconds seconds\n" + + "# HELP U__my_2e_request_2e_duration_2e_seconds Request duration in seconds\n" + + "U__my_2e_request_2e_duration_2e_seconds_bucket{U__http_2e_path=\"/hello\",le=\"+Inf\"} 130 # {U__some_2e_exemplar_2e_key=\"some value\"} 3.0 1690298864.383\n" + + "U__my_2e_request_2e_duration_2e_seconds_count{U__http_2e_path=\"/hello\"} 130\n" + + "U__my_2e_request_2e_duration_2e_seconds_sum{U__http_2e_path=\"/hello\"} 0.01\n" + + "# EOF\n"; String openMetricsTextWithExemplarsOnAllTimeSeries = "# TYPE my_request_duration_seconds histogram\n" + "# UNIT my_request_duration_seconds seconds\n" @@ -1933,13 +1852,11 @@ public void testClassicHistogramWithDots() throws IOException { + "my_request_duration_seconds_sum{http_path=\"/hello\"} 0.01\n" + "# EOF\n"; String prometheusText = - """ - # HELP my_request_duration_seconds Request duration in seconds - # TYPE my_request_duration_seconds histogram - my_request_duration_seconds_bucket{http_path="/hello",le="+Inf"} 130 - my_request_duration_seconds_count{http_path="/hello"} 130 - my_request_duration_seconds_sum{http_path="/hello"} 0.01 - """; + "# HELP my_request_duration_seconds Request duration in seconds\n" + + "# TYPE my_request_duration_seconds histogram\n" + + "my_request_duration_seconds_bucket{http_path=\"/hello\",le=\"+Inf\"} 130\n" + + "my_request_duration_seconds_count{http_path=\"/hello\"} 130\n" + + "my_request_duration_seconds_sum{http_path=\"/hello\"} 0.01\n"; String prometheusProtobuf = // @formatter:off "name: \"my_request_duration_seconds\" " @@ -2294,17 +2211,13 @@ public void testNativeHistogramComplete() throws IOException { @Test public void testNativeHistogramMinimal() throws IOException { String openMetricsText = - """ - # TYPE latency_seconds histogram - latency_seconds_bucket{le="+Inf"} 0 - # EOF - """; + "# TYPE latency_seconds histogram\n" + + "latency_seconds_bucket{le=\"+Inf\"} 0\n" + + "# EOF\n"; String prometheusText = - """ - # TYPE latency_seconds histogram - latency_seconds_bucket{le="+Inf"} 0 - latency_seconds_count 0 - """; + "# TYPE latency_seconds histogram\n" + + "latency_seconds_bucket{le=\"+Inf\"} 0\n" + + "latency_seconds_count 0\n"; String prometheusProtobuf = // @formatter:off "name: \"latency_seconds\" " @@ -2332,15 +2245,13 @@ public void testNativeHistogramMinimal() throws IOException { @Test public void testNativeHistogramWithDots() throws IOException { String openMetricsText = - """ - # TYPE U__my_2e_request_2e_duration_2e_seconds histogram - # UNIT U__my_2e_request_2e_duration_2e_seconds seconds - # HELP U__my_2e_request_2e_duration_2e_seconds Request duration in seconds - U__my_2e_request_2e_duration_2e_seconds_bucket{U__http_2e_path="/hello",le="+Inf"} 4 # {U__some_2e_exemplar_2e_key="some value"} 3.0 1690298864.383 - U__my_2e_request_2e_duration_2e_seconds_count{U__http_2e_path="/hello"} 4 - U__my_2e_request_2e_duration_2e_seconds_sum{U__http_2e_path="/hello"} 3.2 - # EOF - """; + "# TYPE U__my_2e_request_2e_duration_2e_seconds histogram\n" + + "# UNIT U__my_2e_request_2e_duration_2e_seconds seconds\n" + + "# HELP U__my_2e_request_2e_duration_2e_seconds Request duration in seconds\n" + + "U__my_2e_request_2e_duration_2e_seconds_bucket{U__http_2e_path=\"/hello\",le=\"+Inf\"} 4 # {U__some_2e_exemplar_2e_key=\"some value\"} 3.0 1690298864.383\n" + + "U__my_2e_request_2e_duration_2e_seconds_count{U__http_2e_path=\"/hello\"} 4\n" + + "U__my_2e_request_2e_duration_2e_seconds_sum{U__http_2e_path=\"/hello\"} 3.2\n" + + "# EOF\n"; String openMetricsTextWithExemplarsOnAllTimeSeries = "# TYPE my_request_duration_seconds histogram\n" + "# UNIT my_request_duration_seconds seconds\n" @@ -2354,13 +2265,11 @@ public void testNativeHistogramWithDots() throws IOException { + "my_request_duration_seconds_sum{http_path=\"/hello\"} 3.2\n" + "# EOF\n"; String prometheusText = - """ - # HELP my_request_duration_seconds Request duration in seconds - # TYPE my_request_duration_seconds histogram - my_request_duration_seconds_bucket{http_path="/hello",le="+Inf"} 4 - my_request_duration_seconds_count{http_path="/hello"} 4 - my_request_duration_seconds_sum{http_path="/hello"} 3.2 - """; + "# HELP my_request_duration_seconds Request duration in seconds\n" + + "# TYPE my_request_duration_seconds histogram\n" + + "my_request_duration_seconds_bucket{http_path=\"/hello\",le=\"+Inf\"} 4\n" + + "my_request_duration_seconds_count{http_path=\"/hello\"} 4\n" + + "my_request_duration_seconds_sum{http_path=\"/hello\"} 3.2\n"; String prometheusProtobuf = // @formatter:off "name: \"my_request_duration_seconds\" " @@ -2411,18 +2320,14 @@ public void testNativeHistogramWithDots() throws IOException { @Test public void testInfo() throws IOException { String openMetrics = - """ - # TYPE version info - # HELP version version information - version_info{version="1.2.3"} 1 - # EOF - """; + "# TYPE version info\n" + + "# HELP version version information\n" + + "version_info{version=\"1.2.3\"} 1\n" + + "# EOF\n"; String prometheus = - """ - # HELP version_info version information - # TYPE version_info gauge - version_info{version="1.2.3"} 1 - """; + "# HELP version_info version information\n" + + "# TYPE version_info gauge\n" + + "version_info{version=\"1.2.3\"} 1\n"; InfoSnapshot info = InfoSnapshot.builder() .name("version") @@ -2441,18 +2346,14 @@ public void testInfo() throws IOException { @Test public void testInfoWithDots() throws IOException { String openMetricsText = - """ - # TYPE U__jvm_2e_status info - # HELP U__jvm_2e_status JVM status info - U__jvm_2e_status_info{U__jvm_2e_version="1.2.3"} 1 - # EOF - """; + "# TYPE U__jvm_2e_status info\n" + + "# HELP U__jvm_2e_status JVM status info\n" + + "U__jvm_2e_status_info{U__jvm_2e_version=\"1.2.3\"} 1\n" + + "# EOF\n"; String prometheusText = - """ - # HELP jvm_status_info JVM status info - # TYPE jvm_status_info gauge - jvm_status_info{jvm_version="1.2.3"} 1 - """; + "# HELP jvm_status_info JVM status info\n" + + "# TYPE jvm_status_info gauge\n" + + "jvm_status_info{jvm_version=\"1.2.3\"} 1\n"; String prometheusProtobuf = // @formatter:off "name: \"jvm_status_info\" " @@ -2538,18 +2439,12 @@ public void testStateSetComplete() throws IOException { @Test public void testStateSetMinimal() throws IOException { String openMetrics = - """ - # TYPE state stateset - state{state="a"} 1 - state{state="bb"} 0 - # EOF - """; + "# TYPE state stateset\n" + + "state{state=\"a\"} 1\n" + + "state{state=\"bb\"} 0\n" + + "# EOF\n"; String prometheus = - """ - # TYPE state gauge - state{state="a"} 1 - state{state="bb"} 0 - """; + "# TYPE state gauge\n" + "state{state=\"a\"} 1\n" + "state{state=\"bb\"} 0\n"; StateSetSnapshot stateSet = StateSetSnapshot.builder() .name("state") @@ -2568,20 +2463,16 @@ public void testStateSetMinimal() throws IOException { @Test public void testStateSetWithDots() throws IOException { String openMetricsText = - """ - # TYPE U__my_2e_application_2e_state stateset - # HELP U__my_2e_application_2e_state My application state - U__my_2e_application_2e_state{U__data_2e_center="us east",U__my_2e_application_2e_state="feature.enabled"} 1 - U__my_2e_application_2e_state{U__data_2e_center="us east",U__my_2e_application_2e_state="is.alpha.version"} 0 - # EOF - """; + "# TYPE U__my_2e_application_2e_state stateset\n" + + "# HELP U__my_2e_application_2e_state My application state\n" + + "U__my_2e_application_2e_state{U__data_2e_center=\"us east\",U__my_2e_application_2e_state=\"feature.enabled\"} 1\n" + + "U__my_2e_application_2e_state{U__data_2e_center=\"us east\",U__my_2e_application_2e_state=\"is.alpha.version\"} 0\n" + + "# EOF\n"; String prometheusText = - """ - # HELP my_application_state My application state - # TYPE my_application_state gauge - my_application_state{data_center="us east",my_application_state="feature.enabled"} 1 - my_application_state{data_center="us east",my_application_state="is.alpha.version"} 0 - """; + "# HELP my_application_state My application state\n" + + "# TYPE my_application_state gauge\n" + + "my_application_state{data_center=\"us east\",my_application_state=\"feature.enabled\"} 1\n" + + "my_application_state{data_center=\"us east\",my_application_state=\"is.alpha.version\"} 0\n"; String prometheusProtobuf = // @formatter:off "name: \"my_application_state\" " @@ -2680,17 +2571,8 @@ public void testUnknownComplete() throws IOException { @Test public void testUnknownMinimal() throws IOException { - String openMetrics = - """ - # TYPE other unknown - other 22.3 - # EOF - """; - String prometheus = - """ - # TYPE other untyped - other 22.3 - """; + String openMetrics = "# TYPE other unknown\n" + "other 22.3\n" + "# EOF\n"; + String prometheus = "# TYPE other untyped\n" + "other 22.3\n"; UnknownSnapshot unknown = UnknownSnapshot.builder() .name("other") @@ -2705,13 +2587,11 @@ public void testUnknownMinimal() throws IOException { @Test public void testUnknownWithDots() throws IOException { String openMetrics = - """ - # TYPE U__some_2e_unknown_2e_metric__bytes unknown - # UNIT U__some_2e_unknown_2e_metric__bytes bytes - # HELP U__some_2e_unknown_2e_metric__bytes help message - U__some_2e_unknown_2e_metric__bytes{U__test_2e_env="7"} 0.7 - # EOF - """; + "# TYPE U__some_2e_unknown_2e_metric__bytes unknown\n" + + "# UNIT U__some_2e_unknown_2e_metric__bytes bytes\n" + + "# HELP U__some_2e_unknown_2e_metric__bytes help message\n" + + "U__some_2e_unknown_2e_metric__bytes{U__test_2e_env=\"7\"} 0.7\n" + + "# EOF\n"; String openMetricsWithExemplarsOnAllTimeSeries = "# TYPE some_unknown_metric_bytes unknown\n" + "# UNIT some_unknown_metric_bytes bytes\n" @@ -2721,11 +2601,9 @@ public void testUnknownWithDots() throws IOException { + "\n" + "# EOF\n"; String prometheus = - """ - # HELP some_unknown_metric_bytes help message - # TYPE some_unknown_metric_bytes untyped - some_unknown_metric_bytes{test_env="7"} 0.7 - """; + "# HELP some_unknown_metric_bytes help message\n" + + "# TYPE some_unknown_metric_bytes untyped\n" + + "some_unknown_metric_bytes{test_env=\"7\"} 0.7\n"; String prometheusProtobuf = // @formatter:off "name: \"some_unknown_metric_bytes\" " @@ -2758,18 +2636,14 @@ public void testUnknownWithDots() throws IOException { @Test public void testHelpEscape() throws IOException { String openMetrics = - """ - # TYPE test counter - # HELP test Some text and \\n some \\" escaping - test_total 1.0 - # EOF - """; + "# TYPE test counter\n" + + "# HELP test Some text and \\n some \\\" escaping\n" + + "test_total 1.0\n" + + "# EOF\n"; String prometheus = - """ - # HELP test_total Some text and \\n some " escaping - # TYPE test_total counter - test_total 1.0 - """; + "# HELP test_total Some text and \\n some \" escaping\n" + + "# TYPE test_total counter\n" + + "test_total 1.0\n"; CounterSnapshot counter = CounterSnapshot.builder() .name("test") @@ -2785,16 +2659,11 @@ public void testHelpEscape() throws IOException { @Test public void testLabelValueEscape() throws IOException { String openMetrics = - """ - # TYPE test counter - test_total{a="x",b="escaping\\" example \\n "} 1.0 - # EOF - """; + "# TYPE test counter\n" + + "test_total{a=\"x\",b=\"escaping\\\" example \\n \"} 1.0\n" + + "# EOF\n"; String prometheus = - """ - # TYPE test_total counter - test_total{a="x",b="escaping\\" example \\n "} 1.0 - """; + "# TYPE test_total counter\n" + "test_total{a=\"x\",b=\"escaping\\\" example \\n \"} 1.0\n"; CounterSnapshot counter = CounterSnapshot.builder() .name("test") @@ -2843,11 +2712,7 @@ public void testWrite() throws IOException { byte[] out = buff.toByteArray(); assertThat(out.length).isNotEqualTo(0); - String expected = - """ - # TYPE foo_metric untyped - foo_metric 1.234 - """; + String expected = "# TYPE foo_metric untyped\n" + "foo_metric 1.234\n"; assertThat(new String(out, UTF_8)).hasToString(expected); } diff --git a/prometheus-metrics-instrumentation-caffeine/src/test/java/io/prometheus/metrics/instrumentation/caffeine/CacheMetricsCollectorTest.java b/prometheus-metrics-instrumentation-caffeine/src/test/java/io/prometheus/metrics/instrumentation/caffeine/CacheMetricsCollectorTest.java index 3a7b634a7..58e5eeadc 100644 --- a/prometheus-metrics-instrumentation-caffeine/src/test/java/io/prometheus/metrics/instrumentation/caffeine/CacheMetricsCollectorTest.java +++ b/prometheus-metrics-instrumentation-caffeine/src/test/java/io/prometheus/metrics/instrumentation/caffeine/CacheMetricsCollectorTest.java @@ -75,19 +75,15 @@ public void cacheExposesMetricsForHitMissAndEviction(Options options) { if (options.collectEvictionWeightAsCounter) { assertCounterMetric(registry, "caffeine_cache_eviction_weight", "users", 2.0); openMetricEvictionWeightExpectedText = -""" -# TYPE caffeine_cache_eviction_weight counter -# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries -caffeine_cache_eviction_weight_total{cache="users"} 2.0 -"""; + "# TYPE caffeine_cache_eviction_weight counter\n" + + "# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries\n" + + "caffeine_cache_eviction_weight_total{cache=\"users\"} 2.0\n"; } else { assertGaugeMetric(registry, "caffeine_cache_eviction_weight", "users", 2.0); openMetricEvictionWeightExpectedText = -""" -# TYPE caffeine_cache_eviction_weight gauge -# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries -caffeine_cache_eviction_weight{cache="users"} 2.0 -"""; + "# TYPE caffeine_cache_eviction_weight gauge\n" + + "# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries\n" + + "caffeine_cache_eviction_weight{cache=\"users\"} 2.0\n"; } final String expected = @@ -153,28 +149,22 @@ public void weightedCacheExposesMetricsForHitMissAndEvictionWeightedSize(Options if (options.collectEvictionWeightAsCounter) { assertCounterMetric(registry, "caffeine_cache_eviction_weight", "users", 31.0); openMetricEvictionWeightExpectedText = -""" -# TYPE caffeine_cache_eviction_weight counter -# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries -caffeine_cache_eviction_weight_total{cache="users"} 31.0 -"""; + "# TYPE caffeine_cache_eviction_weight counter\n" + + "# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries\n" + + "caffeine_cache_eviction_weight_total{cache=\"users\"} 31.0\n"; } else { assertGaugeMetric(registry, "caffeine_cache_eviction_weight", "users", 31.0); openMetricEvictionWeightExpectedText = -""" -# TYPE caffeine_cache_eviction_weight gauge -# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries -caffeine_cache_eviction_weight{cache="users"} 31.0 -"""; + "# TYPE caffeine_cache_eviction_weight gauge\n" + + "# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries\n" + + "caffeine_cache_eviction_weight{cache=\"users\"} 31.0\n"; } String openMetricWeightedSizeExpectedText; if (options.collectWeightedSize) { openMetricWeightedSizeExpectedText = - """ - # TYPE caffeine_cache_weighted_size gauge - # HELP caffeine_cache_weighted_size Approximate accumulated weight of cache entries - caffeine_cache_weighted_size{cache="users"} 31.0 - """; + "# TYPE caffeine_cache_weighted_size gauge\n" + + "# HELP caffeine_cache_weighted_size Approximate accumulated weight of cache entries\n" + + "caffeine_cache_weighted_size{cache=\"users\"} 31.0\n"; } else { openMetricWeightedSizeExpectedText = ""; } diff --git a/prometheus-metrics-instrumentation-dropwizard/src/test/java/io/prometheus/metrics/instrumentation/dropwizard/DropwizardExportsTest.java b/prometheus-metrics-instrumentation-dropwizard/src/test/java/io/prometheus/metrics/instrumentation/dropwizard/DropwizardExportsTest.java index ba5407942..81e271a26 100644 --- a/prometheus-metrics-instrumentation-dropwizard/src/test/java/io/prometheus/metrics/instrumentation/dropwizard/DropwizardExportsTest.java +++ b/prometheus-metrics-instrumentation-dropwizard/src/test/java/io/prometheus/metrics/instrumentation/dropwizard/DropwizardExportsTest.java @@ -49,12 +49,10 @@ public void testBuilderCreatesOkay() { public void testCounter() { metricRegistry.counter("foo.bar").inc(1); String expected = -""" -# TYPE foo_bar counter -# HELP foo_bar Generated from Dropwizard metric import (metric=foo.bar, type=com.codahale.metrics.Counter) -foo_bar_total 1.0 -# EOF -"""; + "# TYPE foo_bar counter\n" + + "# HELP foo_bar Generated from Dropwizard metric import (metric=foo.bar, type=com.codahale.metrics.Counter)\n" + + "foo_bar_total 1.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat()).isEqualTo(expected); } @@ -105,24 +103,22 @@ public Boolean getValue() { metricRegistry.register("boolean.gauge", booleanGauge); String expected = -""" -# TYPE boolean_gauge gauge -# HELP boolean_gauge Generated from Dropwizard metric import (metric=boolean.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$5) -boolean_gauge 1.0 -# TYPE double_gauge gauge -# HELP double_gauge Generated from Dropwizard metric import (metric=double.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$2) -double_gauge 1.234 -# TYPE float_gauge gauge -# HELP float_gauge Generated from Dropwizard metric import (metric=float.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$4) -float_gauge 0.1234000027179718 -# TYPE integer_gauge gauge -# HELP integer_gauge Generated from Dropwizard metric import (metric=integer.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$1) -integer_gauge 1234.0 -# TYPE long_gauge gauge -# HELP long_gauge Generated from Dropwizard metric import (metric=long.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$3) -long_gauge 1234.0 -# EOF -"""; + "# TYPE boolean_gauge gauge\n" + + "# HELP boolean_gauge Generated from Dropwizard metric import (metric=boolean.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$5)\n" + + "boolean_gauge 1.0\n" + + "# TYPE double_gauge gauge\n" + + "# HELP double_gauge Generated from Dropwizard metric import (metric=double.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$2)\n" + + "double_gauge 1.234\n" + + "# TYPE float_gauge gauge\n" + + "# HELP float_gauge Generated from Dropwizard metric import (metric=float.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$4)\n" + + "float_gauge 0.1234000027179718\n" + + "# TYPE integer_gauge gauge\n" + + "# HELP integer_gauge Generated from Dropwizard metric import (metric=integer.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$1)\n" + + "integer_gauge 1234.0\n" + + "# TYPE long_gauge gauge\n" + + "# HELP long_gauge Generated from Dropwizard metric import (metric=long.gauge, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$3)\n" + + "long_gauge 1234.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat()).isEqualTo(expected); } @@ -161,34 +157,30 @@ public void testHistogram() { // The result should look like this String expected1 = -""" -# TYPE hist summary -# HELP hist Generated from Dropwizard metric import (metric=hist, type=com.codahale.metrics.Histogram) -hist{quantile="0.5"} 49.0 -hist{quantile="0.75"} 74.0 -hist{quantile="0.95"} 94.0 -hist{quantile="0.98"} 97.0 -hist{quantile="0.99"} 98.0 -hist{quantile="0.999"} 99.0 -hist_count 100 -# EOF -"""; + "# TYPE hist summary\n" + + "# HELP hist Generated from Dropwizard metric import (metric=hist, type=com.codahale.metrics.Histogram)\n" + + "hist{quantile=\"0.5\"} 49.0\n" + + "hist{quantile=\"0.75\"} 74.0\n" + + "hist{quantile=\"0.95\"} 94.0\n" + + "hist{quantile=\"0.98\"} 97.0\n" + + "hist{quantile=\"0.99\"} 98.0\n" + + "hist{quantile=\"0.999\"} 99.0\n" + + "hist_count 100\n" + + "# EOF\n"; // However, Dropwizard uses a random reservoir sampling algorithm, so the values could as well // be off-by-one String expected2 = -""" -# TYPE hist summary -# HELP hist Generated from Dropwizard metric import (metric=hist, type=com.codahale.metrics.Histogram) -hist{quantile="0.5"} 50.0 -hist{quantile="0.75"} 75.0 -hist{quantile="0.95"} 95.0 -hist{quantile="0.98"} 98.0 -hist{quantile="0.99"} 99.0 -hist{quantile="0.999"} 99.0 -hist_count 100 -# EOF -"""; + "# TYPE hist summary\n" + + "# HELP hist Generated from Dropwizard metric import (metric=hist, type=com.codahale.metrics.Histogram)\n" + + "hist{quantile=\"0.5\"} 50.0\n" + + "hist{quantile=\"0.75\"} 75.0\n" + + "hist{quantile=\"0.95\"} 95.0\n" + + "hist{quantile=\"0.98\"} 98.0\n" + + "hist{quantile=\"0.99\"} 99.0\n" + + "hist{quantile=\"0.999\"} 99.0\n" + + "hist_count 100\n" + + "# EOF\n"; // The following asserts the values matches either of the expected value. String textFormat = convertToOpenMetricsFormat(pmRegistry); @@ -205,12 +197,10 @@ public void testMeter() { meter.mark(); String expected = -""" -# TYPE meter counter -# HELP meter Generated from Dropwizard metric import (metric=meter_total, type=com.codahale.metrics.Meter) -meter_total 2.0 -# EOF -"""; + "# TYPE meter counter\n" + + "# HELP meter Generated from Dropwizard metric import (metric=meter_total, type=com.codahale.metrics.Meter)\n" + + "meter_total 2.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat()).isEqualTo(expected); } @@ -247,36 +237,34 @@ public void testThatMetricHelpUsesOriginalDropwizardName() { metricRegistry.register("my.application.namedGauge1", new ExampleDoubleGauge()); String expected = -""" -# TYPE my_application_namedCounter1 counter -# HELP my_application_namedCounter1 Generated from Dropwizard metric import (metric=my.application.namedCounter1, type=com.codahale.metrics.Counter) -my_application_namedCounter1_total 0.0 -# TYPE my_application_namedGauge1 gauge -# HELP my_application_namedGauge1 Generated from Dropwizard metric import (metric=my.application.namedGauge1, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$ExampleDoubleGauge) -my_application_namedGauge1 0.0 -# TYPE my_application_namedHistogram1 summary -# HELP my_application_namedHistogram1 Generated from Dropwizard metric import (metric=my.application.namedHistogram1, type=com.codahale.metrics.Histogram) -my_application_namedHistogram1{quantile="0.5"} 0.0 -my_application_namedHistogram1{quantile="0.75"} 0.0 -my_application_namedHistogram1{quantile="0.95"} 0.0 -my_application_namedHistogram1{quantile="0.98"} 0.0 -my_application_namedHistogram1{quantile="0.99"} 0.0 -my_application_namedHistogram1{quantile="0.999"} 0.0 -my_application_namedHistogram1_count 0 -# TYPE my_application_namedMeter1 counter -# HELP my_application_namedMeter1 Generated from Dropwizard metric import (metric=my.application.namedMeter1_total, type=com.codahale.metrics.Meter) -my_application_namedMeter1_total 0.0 -# TYPE my_application_namedTimer1 summary -# HELP my_application_namedTimer1 Generated from Dropwizard metric import (metric=my.application.namedTimer1, type=com.codahale.metrics.Timer) -my_application_namedTimer1{quantile="0.5"} 0.0 -my_application_namedTimer1{quantile="0.75"} 0.0 -my_application_namedTimer1{quantile="0.95"} 0.0 -my_application_namedTimer1{quantile="0.98"} 0.0 -my_application_namedTimer1{quantile="0.99"} 0.0 -my_application_namedTimer1{quantile="0.999"} 0.0 -my_application_namedTimer1_count 0 -# EOF -"""; + "# TYPE my_application_namedCounter1 counter\n" + + "# HELP my_application_namedCounter1 Generated from Dropwizard metric import (metric=my.application.namedCounter1, type=com.codahale.metrics.Counter)\n" + + "my_application_namedCounter1_total 0.0\n" + + "# TYPE my_application_namedGauge1 gauge\n" + + "# HELP my_application_namedGauge1 Generated from Dropwizard metric import (metric=my.application.namedGauge1, type=io.prometheus.metrics.instrumentation.dropwizard.DropwizardExportsTest$ExampleDoubleGauge)\n" + + "my_application_namedGauge1 0.0\n" + + "# TYPE my_application_namedHistogram1 summary\n" + + "# HELP my_application_namedHistogram1 Generated from Dropwizard metric import (metric=my.application.namedHistogram1, type=com.codahale.metrics.Histogram)\n" + + "my_application_namedHistogram1{quantile=\"0.5\"} 0.0\n" + + "my_application_namedHistogram1{quantile=\"0.75\"} 0.0\n" + + "my_application_namedHistogram1{quantile=\"0.95\"} 0.0\n" + + "my_application_namedHistogram1{quantile=\"0.98\"} 0.0\n" + + "my_application_namedHistogram1{quantile=\"0.99\"} 0.0\n" + + "my_application_namedHistogram1{quantile=\"0.999\"} 0.0\n" + + "my_application_namedHistogram1_count 0\n" + + "# TYPE my_application_namedMeter1 counter\n" + + "# HELP my_application_namedMeter1 Generated from Dropwizard metric import (metric=my.application.namedMeter1_total, type=com.codahale.metrics.Meter)\n" + + "my_application_namedMeter1_total 0.0\n" + + "# TYPE my_application_namedTimer1 summary\n" + + "# HELP my_application_namedTimer1 Generated from Dropwizard metric import (metric=my.application.namedTimer1, type=com.codahale.metrics.Timer)\n" + + "my_application_namedTimer1{quantile=\"0.5\"} 0.0\n" + + "my_application_namedTimer1{quantile=\"0.75\"} 0.0\n" + + "my_application_namedTimer1{quantile=\"0.95\"} 0.0\n" + + "my_application_namedTimer1{quantile=\"0.98\"} 0.0\n" + + "my_application_namedTimer1{quantile=\"0.99\"} 0.0\n" + + "my_application_namedTimer1{quantile=\"0.999\"} 0.0\n" + + "my_application_namedTimer1_count 0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat()).isEqualTo(expected); } @@ -284,11 +272,7 @@ public void testThatMetricHelpUsesOriginalDropwizardName() { void responseWhenRegistryIsEmpty() { var registry = new PrometheusRegistry(); registry.register(DropwizardExports.builder().dropwizardRegistry(metricRegistry).build()); - assertThat(convertToOpenMetricsFormat(registry)) - .isEqualTo( -""" -# EOF -"""); + assertThat(convertToOpenMetricsFormat(registry)).isEqualTo("# EOF\n"); } @Test @@ -320,12 +304,10 @@ void collectInvalidMetricPassesWhenExceptionIsIgnored() { .register(registry); assertThat(convertToOpenMetricsFormat(registry)) .isEqualTo( -""" -# TYPE my_application_namedCounter2 counter -# HELP my_application_namedCounter2 Generated from Dropwizard metric import (metric=my.application.namedCounter2, type=com.codahale.metrics.Counter) -my_application_namedCounter2_total 10.0 -# EOF -"""); + "# TYPE my_application_namedCounter2 counter\n" + + "# HELP my_application_namedCounter2 Generated from Dropwizard metric import (metric=my.application.namedCounter2, type=com.codahale.metrics.Counter)\n" + + "my_application_namedCounter2_total 10.0\n" + + "# EOF\n"); assertThat(buf.toString()) .contains("my.application.namedCounter1: -10.0: counters cannot have a negative value"); } diff --git a/prometheus-metrics-instrumentation-dropwizard5/src/test/java/io/prometheus/metrics/instrumentation/dropwizard5/DropwizardExportsTest.java b/prometheus-metrics-instrumentation-dropwizard5/src/test/java/io/prometheus/metrics/instrumentation/dropwizard5/DropwizardExportsTest.java index ff76438d1..618033996 100644 --- a/prometheus-metrics-instrumentation-dropwizard5/src/test/java/io/prometheus/metrics/instrumentation/dropwizard5/DropwizardExportsTest.java +++ b/prometheus-metrics-instrumentation-dropwizard5/src/test/java/io/prometheus/metrics/instrumentation/dropwizard5/DropwizardExportsTest.java @@ -33,12 +33,10 @@ public void setUp() { public void testCounter() { metricRegistry.counter("foo.bar").inc(1); String expected = -""" -# TYPE foo_bar counter -# HELP foo_bar Generated from Dropwizard metric import (metric=foo.bar, type=io.dropwizard.metrics5.Counter) -foo_bar_total 1.0 -# EOF -"""; + "# TYPE foo_bar counter\n" + + "# HELP foo_bar Generated from Dropwizard metric import (metric=foo.bar, type=io.dropwizard.metrics5.Counter)\n" + + "foo_bar_total 1.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat()).isEqualTo(expected); } @@ -89,24 +87,22 @@ public Boolean getValue() { metricRegistry.register(MetricName.parse("boolean.gauge"), booleanGauge); String expected = -""" -# TYPE boolean_gauge gauge -# HELP boolean_gauge Generated from Dropwizard metric import (metric=boolean.gauge, type=io.prometheus.metrics.instrumentation.dropwizard5.DropwizardExportsTest$5) -boolean_gauge 1.0 -# TYPE double_gauge gauge -# HELP double_gauge Generated from Dropwizard metric import (metric=double.gauge, type=io.prometheus.metrics.instrumentation.dropwizard5.DropwizardExportsTest$2) -double_gauge 1.234 -# TYPE float_gauge gauge -# HELP float_gauge Generated from Dropwizard metric import (metric=float.gauge, type=io.prometheus.metrics.instrumentation.dropwizard5.DropwizardExportsTest$4) -float_gauge 0.1234000027179718 -# TYPE integer_gauge gauge -# HELP integer_gauge Generated from Dropwizard metric import (metric=integer.gauge, type=io.prometheus.metrics.instrumentation.dropwizard5.DropwizardExportsTest$1) -integer_gauge 1234.0 -# TYPE long_gauge gauge -# HELP long_gauge Generated from Dropwizard metric import (metric=long.gauge, type=io.prometheus.metrics.instrumentation.dropwizard5.DropwizardExportsTest$3) -long_gauge 1234.0 -# EOF -"""; + "# TYPE boolean_gauge gauge\n" + + "# HELP boolean_gauge Generated from Dropwizard metric import (metric=boolean.gauge, type=io.prometheus.metrics.instrumentation.dropwizard5.DropwizardExportsTest$5)\n" + + "boolean_gauge 1.0\n" + + "# TYPE double_gauge gauge\n" + + "# HELP double_gauge Generated from Dropwizard metric import (metric=double.gauge, type=io.prometheus.metrics.instrumentation.dropwizard5.DropwizardExportsTest$2)\n" + + "double_gauge 1.234\n" + + "# TYPE float_gauge gauge\n" + + "# HELP float_gauge Generated from Dropwizard metric import (metric=float.gauge, type=io.prometheus.metrics.instrumentation.dropwizard5.DropwizardExportsTest$4)\n" + + "float_gauge 0.1234000027179718\n" + + "# TYPE integer_gauge gauge\n" + + "# HELP integer_gauge Generated from Dropwizard metric import (metric=integer.gauge, type=io.prometheus.metrics.instrumentation.dropwizard5.DropwizardExportsTest$1)\n" + + "integer_gauge 1234.0\n" + + "# TYPE long_gauge gauge\n" + + "# HELP long_gauge Generated from Dropwizard metric import (metric=long.gauge, type=io.prometheus.metrics.instrumentation.dropwizard5.DropwizardExportsTest$3)\n" + + "long_gauge 1234.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat()).isEqualTo(expected); } @@ -210,12 +206,10 @@ public void testMeter() { meter.mark(); String expected = -""" -# TYPE meter counter -# HELP meter Generated from Dropwizard metric import (metric=meter_total, type=io.dropwizard.metrics5.Meter) -meter_total 2.0 -# EOF -"""; + "# TYPE meter counter\n" + + "# HELP meter Generated from Dropwizard metric import (metric=meter_total, type=io.dropwizard.metrics5.Meter)\n" + + "meter_total 2.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat()).isEqualTo(expected); } @@ -256,36 +250,34 @@ public void testThatMetricHelpUsesOriginalDropwizardName() { MetricName.parse("my.application.namedGauge1"), new ExampleDoubleGauge()); String expected = -""" -# TYPE my_application_namedCounter1 counter -# HELP my_application_namedCounter1 Generated from Dropwizard metric import (metric=my.application.namedCounter1, type=io.dropwizard.metrics5.Counter) -my_application_namedCounter1_total 0.0 -# TYPE my_application_namedGauge1 gauge -# HELP my_application_namedGauge1 Generated from Dropwizard metric import (metric=my.application.namedGauge1, type=io.prometheus.metrics.instrumentation.dropwizard5.DropwizardExportsTest$ExampleDoubleGauge) -my_application_namedGauge1 0.0 -# TYPE my_application_namedHistogram1 summary -# HELP my_application_namedHistogram1 Generated from Dropwizard metric import (metric=my.application.namedHistogram1, type=io.dropwizard.metrics5.Histogram) -my_application_namedHistogram1{quantile="0.5"} 0.0 -my_application_namedHistogram1{quantile="0.75"} 0.0 -my_application_namedHistogram1{quantile="0.95"} 0.0 -my_application_namedHistogram1{quantile="0.98"} 0.0 -my_application_namedHistogram1{quantile="0.99"} 0.0 -my_application_namedHistogram1{quantile="0.999"} 0.0 -my_application_namedHistogram1_count 0 -# TYPE my_application_namedMeter1 counter -# HELP my_application_namedMeter1 Generated from Dropwizard metric import (metric=my.application.namedMeter1_total, type=io.dropwizard.metrics5.Meter) -my_application_namedMeter1_total 0.0 -# TYPE my_application_namedTimer1 summary -# HELP my_application_namedTimer1 Generated from Dropwizard metric import (metric=my.application.namedTimer1, type=io.dropwizard.metrics5.Timer) -my_application_namedTimer1{quantile="0.5"} 0.0 -my_application_namedTimer1{quantile="0.75"} 0.0 -my_application_namedTimer1{quantile="0.95"} 0.0 -my_application_namedTimer1{quantile="0.98"} 0.0 -my_application_namedTimer1{quantile="0.99"} 0.0 -my_application_namedTimer1{quantile="0.999"} 0.0 -my_application_namedTimer1_count 0 -# EOF -"""; + "# TYPE my_application_namedCounter1 counter\n" + + "# HELP my_application_namedCounter1 Generated from Dropwizard metric import (metric=my.application.namedCounter1, type=io.dropwizard.metrics5.Counter)\n" + + "my_application_namedCounter1_total 0.0\n" + + "# TYPE my_application_namedGauge1 gauge\n" + + "# HELP my_application_namedGauge1 Generated from Dropwizard metric import (metric=my.application.namedGauge1, type=io.prometheus.metrics.instrumentation.dropwizard5.DropwizardExportsTest$ExampleDoubleGauge)\n" + + "my_application_namedGauge1 0.0\n" + + "# TYPE my_application_namedHistogram1 summary\n" + + "# HELP my_application_namedHistogram1 Generated from Dropwizard metric import (metric=my.application.namedHistogram1, type=io.dropwizard.metrics5.Histogram)\n" + + "my_application_namedHistogram1{quantile=\"0.5\"} 0.0\n" + + "my_application_namedHistogram1{quantile=\"0.75\"} 0.0\n" + + "my_application_namedHistogram1{quantile=\"0.95\"} 0.0\n" + + "my_application_namedHistogram1{quantile=\"0.98\"} 0.0\n" + + "my_application_namedHistogram1{quantile=\"0.99\"} 0.0\n" + + "my_application_namedHistogram1{quantile=\"0.999\"} 0.0\n" + + "my_application_namedHistogram1_count 0\n" + + "# TYPE my_application_namedMeter1 counter\n" + + "# HELP my_application_namedMeter1 Generated from Dropwizard metric import (metric=my.application.namedMeter1_total, type=io.dropwizard.metrics5.Meter)\n" + + "my_application_namedMeter1_total 0.0\n" + + "# TYPE my_application_namedTimer1 summary\n" + + "# HELP my_application_namedTimer1 Generated from Dropwizard metric import (metric=my.application.namedTimer1, type=io.dropwizard.metrics5.Timer)\n" + + "my_application_namedTimer1{quantile=\"0.5\"} 0.0\n" + + "my_application_namedTimer1{quantile=\"0.75\"} 0.0\n" + + "my_application_namedTimer1{quantile=\"0.95\"} 0.0\n" + + "my_application_namedTimer1{quantile=\"0.98\"} 0.0\n" + + "my_application_namedTimer1{quantile=\"0.99\"} 0.0\n" + + "my_application_namedTimer1{quantile=\"0.999\"} 0.0\n" + + "my_application_namedTimer1_count 0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat()).isEqualTo(expected); } @@ -293,11 +285,7 @@ public void testThatMetricHelpUsesOriginalDropwizardName() { void responseWhenRegistryIsEmpty() { var registry = new PrometheusRegistry(); registry.register(DropwizardExports.builder().dropwizardRegistry(metricRegistry).build()); - assertThat(convertToOpenMetricsFormat(registry)) - .isEqualTo( -""" -# EOF -"""); + assertThat(convertToOpenMetricsFormat(registry)).isEqualTo("# EOF\n"); } @Test @@ -329,12 +317,10 @@ void collectInvalidMetricPassesWhenExceptionIsIgnored() { .register(registry); assertThat(convertToOpenMetricsFormat(registry)) .isEqualTo( -""" -# TYPE my_application_namedCounter2 counter -# HELP my_application_namedCounter2 Generated from Dropwizard metric import (metric=my.application.namedCounter2, type=io.dropwizard.metrics5.Counter) -my_application_namedCounter2_total 10.0 -# EOF -"""); + "# TYPE my_application_namedCounter2 counter\n" + + "# HELP my_application_namedCounter2 Generated from Dropwizard metric import (metric=my.application.namedCounter2, type=io.dropwizard.metrics5.Counter)\n" + + "my_application_namedCounter2_total 10.0\n" + + "# EOF\n"); assertThat(buf.toString()) .contains("my.application.namedCounter1: -10.0: counters cannot have a negative value"); } diff --git a/prometheus-metrics-instrumentation-dropwizard5/src/test/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/CustomLabelMapperTest.java b/prometheus-metrics-instrumentation-dropwizard5/src/test/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/CustomLabelMapperTest.java index 44c365898..6672a9f92 100644 --- a/prometheus-metrics-instrumentation-dropwizard5/src/test/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/CustomLabelMapperTest.java +++ b/prometheus-metrics-instrumentation-dropwizard5/src/test/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/CustomLabelMapperTest.java @@ -45,12 +45,10 @@ public void test_WHEN_NoMatches_THEN_ShouldReturnDefaultSample() { System.out.println(convertToOpenMetricsFormat(dropwizardExports.collect())); String expected = -""" -# TYPE app_okhttpclient_client_HttpClient_service counter -# HELP app_okhttpclient_client_HttpClient_service Generated from Dropwizard metric import (metric=app.okhttpclient.client.HttpClient.service.total, type=io.dropwizard.metrics5.Counter) -app_okhttpclient_client_HttpClient_service_total 1.0 -# EOF -"""; + "# TYPE app_okhttpclient_client_HttpClient_service counter\n" + + "# HELP app_okhttpclient_client_HttpClient_service Generated from Dropwizard metric import (metric=app.okhttpclient.client.HttpClient.service.total, type=io.dropwizard.metrics5.Counter)\n" + + "app_okhttpclient_client_HttpClient_service_total 1.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(dropwizardExports.collect())).isEqualTo(expected); } @@ -76,12 +74,10 @@ public void test_WHEN_OneMatch_THEN_ShouldReturnConverted() { metricRegistry.counter("app.okhttpclient.client.HttpClient.greatService.total").inc(1); String expected = -""" -# TYPE app_okhttpclient_client_HttpClient counter -# HELP app_okhttpclient_client_HttpClient Generated from Dropwizard metric import (metric=app.okhttpclient.client.HttpClient.greatService.total, type=io.dropwizard.metrics5.Counter) -app_okhttpclient_client_HttpClient_total{service="greatService"} 1.0 -# EOF -"""; + "# TYPE app_okhttpclient_client_HttpClient counter\n" + + "# HELP app_okhttpclient_client_HttpClient Generated from Dropwizard metric import (metric=app.okhttpclient.client.HttpClient.greatService.total, type=io.dropwizard.metrics5.Counter)\n" + + "app_okhttpclient_client_HttpClient_total{service=\"greatService\"} 1.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(dropwizardExports.collect())).isEqualTo(expected); } @@ -107,12 +103,10 @@ public void test_WHEN_MoreMatches_THEN_ShouldReturnFirstOne() { metricRegistry.counter("app.okhttpclient.client.HttpClient.greatService.total").inc(1); String expected = -""" -# TYPE app_okhttpclient_client_HttpClient counter -# HELP app_okhttpclient_client_HttpClient Generated from Dropwizard metric import (metric=app.okhttpclient.client.HttpClient.greatService.total, type=io.dropwizard.metrics5.Counter) -app_okhttpclient_client_HttpClient_total{service="greatService"} 1.0 -# EOF -"""; + "# TYPE app_okhttpclient_client_HttpClient counter\n" + + "# HELP app_okhttpclient_client_HttpClient Generated from Dropwizard metric import (metric=app.okhttpclient.client.HttpClient.greatService.total, type=io.dropwizard.metrics5.Counter)\n" + + "app_okhttpclient_client_HttpClient_total{service=\"greatService\"} 1.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(dropwizardExports.collect())).isEqualTo(expected); } @@ -144,12 +138,10 @@ public void test_WHEN_MoreMatchesReverseOrder_THEN_ShouldReturnFirstOne() { metricRegistry.counter("app.okhttpclient.client.HttpClient.greatService.400").inc(1); String expected = -""" -# TYPE app_okhttpclient_client_HttpClient counter -# HELP app_okhttpclient_client_HttpClient Generated from Dropwizard metric import (metric=app.okhttpclient.client.HttpClient.greatService.400, type=io.dropwizard.metrics5.Counter) -app_okhttpclient_client_HttpClient_total{service="greatService",status="400"} 1.0 -# EOF -"""; + "# TYPE app_okhttpclient_client_HttpClient counter\n" + + "# HELP app_okhttpclient_client_HttpClient Generated from Dropwizard metric import (metric=app.okhttpclient.client.HttpClient.greatService.400, type=io.dropwizard.metrics5.Counter)\n" + + "app_okhttpclient_client_HttpClient_total{service=\"greatService\",status=\"400\"} 1.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(dropwizardExports.collect())).isEqualTo(expected); } @@ -177,12 +169,10 @@ public void test_WHEN_MoreToFormatInLabelsAndName_THEN_ShouldReturnCorrectSample System.out.println(convertToOpenMetricsFormat(dropwizardExports.collect())); String expected = -""" -# TYPE app_okhttpclient_client_HttpClient_greatService counter -# HELP app_okhttpclient_client_HttpClient_greatService Generated from Dropwizard metric import (metric=app.okhttpclient.client.HttpClient.greatService.400, type=io.dropwizard.metrics5.Counter) -app_okhttpclient_client_HttpClient_greatService_total{service="greatService_400",status="s_400"} 1.0 -# EOF -"""; + "# TYPE app_okhttpclient_client_HttpClient_greatService counter\n" + + "# HELP app_okhttpclient_client_HttpClient_greatService Generated from Dropwizard metric import (metric=app.okhttpclient.client.HttpClient.greatService.400, type=io.dropwizard.metrics5.Counter)\n" + + "app_okhttpclient_client_HttpClient_greatService_total{service=\"greatService_400\",status=\"s_400\"} 1.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(dropwizardExports.collect())).isEqualTo(expected); } @@ -206,12 +196,10 @@ public void test_WHEN_AdditionalLabels_THEN_ShouldReturnCorrectSample() { metricRegistry.counter("app.okhttpclient.client.HttpClient.greatService.400").inc(1); String expected = -""" -# TYPE app_okhttpclient_client_HttpClient_greatService counter -# HELP app_okhttpclient_client_HttpClient_greatService Generated from Dropwizard metric import (metric=app.okhttpclient.client.HttpClient.greatService.400, type=io.dropwizard.metrics5.Counter) -app_okhttpclient_client_HttpClient_greatService_total{client="sampleClient",service="greatService",status="s_400"} 1.0 -# EOF -"""; + "# TYPE app_okhttpclient_client_HttpClient_greatService counter\n" + + "# HELP app_okhttpclient_client_HttpClient_greatService Generated from Dropwizard metric import (metric=app.okhttpclient.client.HttpClient.greatService.400, type=io.dropwizard.metrics5.Counter)\n" + + "app_okhttpclient_client_HttpClient_greatService_total{client=\"sampleClient\",service=\"greatService\",status=\"s_400\"} 1.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(dropwizardExports.collect())).isEqualTo(expected); } diff --git a/prometheus-metrics-instrumentation-guava/src/test/java/io/prometheus/metrics/instrumentation/guava/CacheMetricsCollectorTest.java b/prometheus-metrics-instrumentation-guava/src/test/java/io/prometheus/metrics/instrumentation/guava/CacheMetricsCollectorTest.java index 31da91f20..496fba791 100644 --- a/prometheus-metrics-instrumentation-guava/src/test/java/io/prometheus/metrics/instrumentation/guava/CacheMetricsCollectorTest.java +++ b/prometheus-metrics-instrumentation-guava/src/test/java/io/prometheus/metrics/instrumentation/guava/CacheMetricsCollectorTest.java @@ -49,24 +49,22 @@ public void cacheExposesMetricsForHitMissAndEviction() { assertCounterMetric(registry, "guava_cache_eviction", "users", 2.0); final String expected = - """ - # TYPE guava_cache_eviction counter - # HELP guava_cache_eviction Cache eviction totals, doesn't include manually removed entries - guava_cache_eviction_total{cache="users"} 2.0 - # TYPE guava_cache_hit counter - # HELP guava_cache_hit Cache hit totals - guava_cache_hit_total{cache="users"} 1.0 - # TYPE guava_cache_miss counter - # HELP guava_cache_miss Cache miss totals - guava_cache_miss_total{cache="users"} 2.0 - # TYPE guava_cache_requests counter - # HELP guava_cache_requests Cache request totals - guava_cache_requests_total{cache="users"} 3.0 - # TYPE guava_cache_size gauge - # HELP guava_cache_size Cache size - guava_cache_size{cache="users"} 2.0 - # EOF - """; + "# TYPE guava_cache_eviction counter\n" + + "# HELP guava_cache_eviction Cache eviction totals, doesn't include manually removed entries\n" + + "guava_cache_eviction_total{cache=\"users\"} 2.0\n" + + "# TYPE guava_cache_hit counter\n" + + "# HELP guava_cache_hit Cache hit totals\n" + + "guava_cache_hit_total{cache=\"users\"} 1.0\n" + + "# TYPE guava_cache_miss counter\n" + + "# HELP guava_cache_miss Cache miss totals\n" + + "guava_cache_miss_total{cache=\"users\"} 2.0\n" + + "# TYPE guava_cache_requests counter\n" + + "# HELP guava_cache_requests Cache request totals\n" + + "guava_cache_requests_total{cache=\"users\"} 3.0\n" + + "# TYPE guava_cache_size gauge\n" + + "# HELP guava_cache_size Cache size\n" + + "guava_cache_size{cache=\"users\"} 2.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(registry)).isEqualTo(expected); } diff --git a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmBufferPoolMetricsTest.java b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmBufferPoolMetricsTest.java index e3bf55fb4..5d4523351 100644 --- a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmBufferPoolMetricsTest.java +++ b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmBufferPoolMetricsTest.java @@ -42,23 +42,21 @@ public void testGoodCase() throws IOException { MetricSnapshots snapshots = registry.scrape(); String expected = - """ - # TYPE jvm_buffer_pool_capacity_bytes gauge - # UNIT jvm_buffer_pool_capacity_bytes bytes - # HELP jvm_buffer_pool_capacity_bytes Bytes capacity of a given JVM buffer pool. - jvm_buffer_pool_capacity_bytes{pool="direct"} 3456.0 - jvm_buffer_pool_capacity_bytes{pool="mapped"} 4567.0 - # TYPE jvm_buffer_pool_used_buffers gauge - # HELP jvm_buffer_pool_used_buffers Used buffers of a given JVM buffer pool. - jvm_buffer_pool_used_buffers{pool="direct"} 2.0 - jvm_buffer_pool_used_buffers{pool="mapped"} 3.0 - # TYPE jvm_buffer_pool_used_bytes gauge - # UNIT jvm_buffer_pool_used_bytes bytes - # HELP jvm_buffer_pool_used_bytes Used bytes of a given JVM buffer pool. - jvm_buffer_pool_used_bytes{pool="direct"} 1234.0 - jvm_buffer_pool_used_bytes{pool="mapped"} 2345.0 - # EOF - """; + "# TYPE jvm_buffer_pool_capacity_bytes gauge\n" + + "# UNIT jvm_buffer_pool_capacity_bytes bytes\n" + + "# HELP jvm_buffer_pool_capacity_bytes Bytes capacity of a given JVM buffer pool.\n" + + "jvm_buffer_pool_capacity_bytes{pool=\"direct\"} 3456.0\n" + + "jvm_buffer_pool_capacity_bytes{pool=\"mapped\"} 4567.0\n" + + "# TYPE jvm_buffer_pool_used_buffers gauge\n" + + "# HELP jvm_buffer_pool_used_buffers Used buffers of a given JVM buffer pool.\n" + + "jvm_buffer_pool_used_buffers{pool=\"direct\"} 2.0\n" + + "jvm_buffer_pool_used_buffers{pool=\"mapped\"} 3.0\n" + + "# TYPE jvm_buffer_pool_used_bytes gauge\n" + + "# UNIT jvm_buffer_pool_used_bytes bytes\n" + + "# HELP jvm_buffer_pool_used_bytes Used bytes of a given JVM buffer pool.\n" + + "jvm_buffer_pool_used_bytes{pool=\"direct\"} 1234.0\n" + + "jvm_buffer_pool_used_bytes{pool=\"mapped\"} 2345.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(snapshots)).isEqualTo(expected); } diff --git a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmClassLoadingMetricsTest.java b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmClassLoadingMetricsTest.java index ac13ab382..6070aebba 100644 --- a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmClassLoadingMetricsTest.java +++ b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmClassLoadingMetricsTest.java @@ -33,18 +33,16 @@ public void testGoodCase() throws IOException { MetricSnapshots snapshots = registry.scrape(); String expected = -""" -# TYPE jvm_classes_currently_loaded gauge -# HELP jvm_classes_currently_loaded The number of classes that are currently loaded in the JVM -jvm_classes_currently_loaded 1000.0 -# TYPE jvm_classes_loaded counter -# HELP jvm_classes_loaded The total number of classes that have been loaded since the JVM has started execution -jvm_classes_loaded_total 2000.0 -# TYPE jvm_classes_unloaded counter -# HELP jvm_classes_unloaded The total number of classes that have been unloaded since the JVM has started execution -jvm_classes_unloaded_total 500.0 -# EOF -"""; + "# TYPE jvm_classes_currently_loaded gauge\n" + + "# HELP jvm_classes_currently_loaded The number of classes that are currently loaded in the JVM\n" + + "jvm_classes_currently_loaded 1000.0\n" + + "# TYPE jvm_classes_loaded counter\n" + + "# HELP jvm_classes_loaded The total number of classes that have been loaded since the JVM has started execution\n" + + "jvm_classes_loaded_total 2000.0\n" + + "# TYPE jvm_classes_unloaded counter\n" + + "# HELP jvm_classes_unloaded The total number of classes that have been unloaded since the JVM has started execution\n" + + "jvm_classes_unloaded_total 500.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(snapshots)).isEqualTo(expected); } diff --git a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmCompilationMetricsTest.java b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmCompilationMetricsTest.java index 73d1a39df..caddb89ea 100644 --- a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmCompilationMetricsTest.java +++ b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmCompilationMetricsTest.java @@ -32,13 +32,11 @@ public void testGoodCase() throws IOException { MetricSnapshots snapshots = registry.scrape(); String expected = -""" -# TYPE jvm_compilation_time_seconds counter -# UNIT jvm_compilation_time_seconds seconds -# HELP jvm_compilation_time_seconds The total time in seconds taken for HotSpot class compilation -jvm_compilation_time_seconds_total 10.0 -# EOF -"""; + "# TYPE jvm_compilation_time_seconds counter\n" + + "# UNIT jvm_compilation_time_seconds seconds\n" + + "# HELP jvm_compilation_time_seconds The total time in seconds taken for HotSpot class compilation\n" + + "jvm_compilation_time_seconds_total 10.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(snapshots)).isEqualTo(expected); } diff --git a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmGarbageCollectorMetricsTest.java b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmGarbageCollectorMetricsTest.java index 177f29d2e..3a09b4ef0 100644 --- a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmGarbageCollectorMetricsTest.java +++ b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmGarbageCollectorMetricsTest.java @@ -41,16 +41,14 @@ public void testGoodCase() throws IOException { MetricSnapshots snapshots = registry.scrape(); String expected = - """ - # TYPE jvm_gc_collection_seconds summary - # UNIT jvm_gc_collection_seconds seconds - # HELP jvm_gc_collection_seconds Time spent in a given JVM garbage collector in seconds. - jvm_gc_collection_seconds_count{gc="MyGC1"} 100 - jvm_gc_collection_seconds_sum{gc="MyGC1"} 10.0 - jvm_gc_collection_seconds_count{gc="MyGC2"} 200 - jvm_gc_collection_seconds_sum{gc="MyGC2"} 20.0 - # EOF - """; + "# TYPE jvm_gc_collection_seconds summary\n" + + "# UNIT jvm_gc_collection_seconds seconds\n" + + "# HELP jvm_gc_collection_seconds Time spent in a given JVM garbage collector in seconds.\n" + + "jvm_gc_collection_seconds_count{gc=\"MyGC1\"} 100\n" + + "jvm_gc_collection_seconds_sum{gc=\"MyGC1\"} 10.0\n" + + "jvm_gc_collection_seconds_count{gc=\"MyGC2\"} 200\n" + + "jvm_gc_collection_seconds_sum{gc=\"MyGC2\"} 20.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(snapshots)).isEqualTo(expected); } diff --git a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmMemoryMetricsTest.java b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmMemoryMetricsTest.java index a79ec3b3b..22aa2c46a 100644 --- a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmMemoryMetricsTest.java +++ b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmMemoryMetricsTest.java @@ -89,72 +89,70 @@ public void testGoodCase() throws IOException { MetricSnapshots snapshots = registry.scrape(); String expected = -""" -# TYPE jvm_memory_committed_bytes gauge -# UNIT jvm_memory_committed_bytes bytes -# HELP jvm_memory_committed_bytes Committed (bytes) of a given JVM memory area. -jvm_memory_committed_bytes{area="heap"} 4.0 -jvm_memory_committed_bytes{area="nonheap"} 8.0 -# TYPE jvm_memory_init_bytes gauge -# UNIT jvm_memory_init_bytes bytes -# HELP jvm_memory_init_bytes Initial bytes of a given JVM memory area. -jvm_memory_init_bytes{area="heap"} 5.0 -jvm_memory_init_bytes{area="nonheap"} 9.0 -# TYPE jvm_memory_max_bytes gauge -# UNIT jvm_memory_max_bytes bytes -# HELP jvm_memory_max_bytes Max (bytes) of a given JVM memory area. -jvm_memory_max_bytes{area="heap"} 3.0 -jvm_memory_max_bytes{area="nonheap"} 7.0 -# TYPE jvm_memory_objects_pending_finalization gauge -# HELP jvm_memory_objects_pending_finalization The number of objects waiting in the finalizer queue. -jvm_memory_objects_pending_finalization 1.0 -# TYPE jvm_memory_pool_collection_committed_bytes gauge -# UNIT jvm_memory_pool_collection_committed_bytes bytes -# HELP jvm_memory_pool_collection_committed_bytes Committed after last collection bytes of a given JVM memory pool. -jvm_memory_pool_collection_committed_bytes{pool="PS Eden Space"} 20.0 -jvm_memory_pool_collection_committed_bytes{pool="PS Old Gen"} 24.0 -# TYPE jvm_memory_pool_collection_init_bytes gauge -# UNIT jvm_memory_pool_collection_init_bytes bytes -# HELP jvm_memory_pool_collection_init_bytes Initial after last collection bytes of a given JVM memory pool. -jvm_memory_pool_collection_init_bytes{pool="PS Eden Space"} 21.0 -jvm_memory_pool_collection_init_bytes{pool="PS Old Gen"} 25.0 -# TYPE jvm_memory_pool_collection_max_bytes gauge -# UNIT jvm_memory_pool_collection_max_bytes bytes -# HELP jvm_memory_pool_collection_max_bytes Max bytes after last collection of a given JVM memory pool. -jvm_memory_pool_collection_max_bytes{pool="PS Eden Space"} 19.0 -jvm_memory_pool_collection_max_bytes{pool="PS Old Gen"} 23.0 -# TYPE jvm_memory_pool_collection_used_bytes gauge -# UNIT jvm_memory_pool_collection_used_bytes bytes -# HELP jvm_memory_pool_collection_used_bytes Used bytes after last collection of a given JVM memory pool. -jvm_memory_pool_collection_used_bytes{pool="PS Eden Space"} 18.0 -jvm_memory_pool_collection_used_bytes{pool="PS Old Gen"} 22.0 -# TYPE jvm_memory_pool_committed_bytes gauge -# UNIT jvm_memory_pool_committed_bytes bytes -# HELP jvm_memory_pool_committed_bytes Committed bytes of a given JVM memory pool. -jvm_memory_pool_committed_bytes{pool="PS Eden Space"} 12.0 -jvm_memory_pool_committed_bytes{pool="PS Old Gen"} 16.0 -# TYPE jvm_memory_pool_init_bytes gauge -# UNIT jvm_memory_pool_init_bytes bytes -# HELP jvm_memory_pool_init_bytes Initial bytes of a given JVM memory pool. -jvm_memory_pool_init_bytes{pool="PS Eden Space"} 13.0 -jvm_memory_pool_init_bytes{pool="PS Old Gen"} 17.0 -# TYPE jvm_memory_pool_max_bytes gauge -# UNIT jvm_memory_pool_max_bytes bytes -# HELP jvm_memory_pool_max_bytes Max bytes of a given JVM memory pool. -jvm_memory_pool_max_bytes{pool="PS Eden Space"} 11.0 -jvm_memory_pool_max_bytes{pool="PS Old Gen"} 15.0 -# TYPE jvm_memory_pool_used_bytes gauge -# UNIT jvm_memory_pool_used_bytes bytes -# HELP jvm_memory_pool_used_bytes Used bytes of a given JVM memory pool. -jvm_memory_pool_used_bytes{pool="PS Eden Space"} 10.0 -jvm_memory_pool_used_bytes{pool="PS Old Gen"} 14.0 -# TYPE jvm_memory_used_bytes gauge -# UNIT jvm_memory_used_bytes bytes -# HELP jvm_memory_used_bytes Used bytes of a given JVM memory area. -jvm_memory_used_bytes{area="heap"} 2.0 -jvm_memory_used_bytes{area="nonheap"} 6.0 -# EOF -"""; + "# TYPE jvm_memory_committed_bytes gauge\n" + + "# UNIT jvm_memory_committed_bytes bytes\n" + + "# HELP jvm_memory_committed_bytes Committed (bytes) of a given JVM memory area.\n" + + "jvm_memory_committed_bytes{area=\"heap\"} 4.0\n" + + "jvm_memory_committed_bytes{area=\"nonheap\"} 8.0\n" + + "# TYPE jvm_memory_init_bytes gauge\n" + + "# UNIT jvm_memory_init_bytes bytes\n" + + "# HELP jvm_memory_init_bytes Initial bytes of a given JVM memory area.\n" + + "jvm_memory_init_bytes{area=\"heap\"} 5.0\n" + + "jvm_memory_init_bytes{area=\"nonheap\"} 9.0\n" + + "# TYPE jvm_memory_max_bytes gauge\n" + + "# UNIT jvm_memory_max_bytes bytes\n" + + "# HELP jvm_memory_max_bytes Max (bytes) of a given JVM memory area.\n" + + "jvm_memory_max_bytes{area=\"heap\"} 3.0\n" + + "jvm_memory_max_bytes{area=\"nonheap\"} 7.0\n" + + "# TYPE jvm_memory_objects_pending_finalization gauge\n" + + "# HELP jvm_memory_objects_pending_finalization The number of objects waiting in the finalizer queue.\n" + + "jvm_memory_objects_pending_finalization 1.0\n" + + "# TYPE jvm_memory_pool_collection_committed_bytes gauge\n" + + "# UNIT jvm_memory_pool_collection_committed_bytes bytes\n" + + "# HELP jvm_memory_pool_collection_committed_bytes Committed after last collection bytes of a given JVM memory pool.\n" + + "jvm_memory_pool_collection_committed_bytes{pool=\"PS Eden Space\"} 20.0\n" + + "jvm_memory_pool_collection_committed_bytes{pool=\"PS Old Gen\"} 24.0\n" + + "# TYPE jvm_memory_pool_collection_init_bytes gauge\n" + + "# UNIT jvm_memory_pool_collection_init_bytes bytes\n" + + "# HELP jvm_memory_pool_collection_init_bytes Initial after last collection bytes of a given JVM memory pool.\n" + + "jvm_memory_pool_collection_init_bytes{pool=\"PS Eden Space\"} 21.0\n" + + "jvm_memory_pool_collection_init_bytes{pool=\"PS Old Gen\"} 25.0\n" + + "# TYPE jvm_memory_pool_collection_max_bytes gauge\n" + + "# UNIT jvm_memory_pool_collection_max_bytes bytes\n" + + "# HELP jvm_memory_pool_collection_max_bytes Max bytes after last collection of a given JVM memory pool.\n" + + "jvm_memory_pool_collection_max_bytes{pool=\"PS Eden Space\"} 19.0\n" + + "jvm_memory_pool_collection_max_bytes{pool=\"PS Old Gen\"} 23.0\n" + + "# TYPE jvm_memory_pool_collection_used_bytes gauge\n" + + "# UNIT jvm_memory_pool_collection_used_bytes bytes\n" + + "# HELP jvm_memory_pool_collection_used_bytes Used bytes after last collection of a given JVM memory pool.\n" + + "jvm_memory_pool_collection_used_bytes{pool=\"PS Eden Space\"} 18.0\n" + + "jvm_memory_pool_collection_used_bytes{pool=\"PS Old Gen\"} 22.0\n" + + "# TYPE jvm_memory_pool_committed_bytes gauge\n" + + "# UNIT jvm_memory_pool_committed_bytes bytes\n" + + "# HELP jvm_memory_pool_committed_bytes Committed bytes of a given JVM memory pool.\n" + + "jvm_memory_pool_committed_bytes{pool=\"PS Eden Space\"} 12.0\n" + + "jvm_memory_pool_committed_bytes{pool=\"PS Old Gen\"} 16.0\n" + + "# TYPE jvm_memory_pool_init_bytes gauge\n" + + "# UNIT jvm_memory_pool_init_bytes bytes\n" + + "# HELP jvm_memory_pool_init_bytes Initial bytes of a given JVM memory pool.\n" + + "jvm_memory_pool_init_bytes{pool=\"PS Eden Space\"} 13.0\n" + + "jvm_memory_pool_init_bytes{pool=\"PS Old Gen\"} 17.0\n" + + "# TYPE jvm_memory_pool_max_bytes gauge\n" + + "# UNIT jvm_memory_pool_max_bytes bytes\n" + + "# HELP jvm_memory_pool_max_bytes Max bytes of a given JVM memory pool.\n" + + "jvm_memory_pool_max_bytes{pool=\"PS Eden Space\"} 11.0\n" + + "jvm_memory_pool_max_bytes{pool=\"PS Old Gen\"} 15.0\n" + + "# TYPE jvm_memory_pool_used_bytes gauge\n" + + "# UNIT jvm_memory_pool_used_bytes bytes\n" + + "# HELP jvm_memory_pool_used_bytes Used bytes of a given JVM memory pool.\n" + + "jvm_memory_pool_used_bytes{pool=\"PS Eden Space\"} 10.0\n" + + "jvm_memory_pool_used_bytes{pool=\"PS Old Gen\"} 14.0\n" + + "# TYPE jvm_memory_used_bytes gauge\n" + + "# UNIT jvm_memory_used_bytes bytes\n" + + "# HELP jvm_memory_used_bytes Used bytes of a given JVM memory area.\n" + + "jvm_memory_used_bytes{area=\"heap\"} 2.0\n" + + "jvm_memory_used_bytes{area=\"nonheap\"} 6.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(snapshots)).isEqualTo(expected); } diff --git a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmNativeMemoryMetricsTest.java b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmNativeMemoryMetricsTest.java index bbf42ecc7..95cd30871 100644 --- a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmNativeMemoryMetricsTest.java +++ b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmNativeMemoryMetricsTest.java @@ -81,160 +81,157 @@ public void testNativeMemoryTrackingEnabled() throws IOException { Mockito.mock(JvmNativeMemoryMetrics.PlatformMBeanServerAdapter.class); when(adapter.vmNativeMemorySummaryInBytes()) .thenReturn( - """ - Native Memory Tracking: - - Total: reserved=10341970661, committed=642716389 - malloc: 27513573 #22947 - mmap: reserved=10314457088, committed=615202816 - - - Java Heap (reserved=8531214336, committed=536870912) - (mmap: reserved=8531214336, committed=536870912)\s - \s - - Class (reserved=1073899939, committed=616867) - (classes #1630) - ( instance classes #1462, array classes #168) - (malloc=158115 #2350)\s - (mmap: reserved=1073741824, committed=458752)\s - ( Metadata: ) - ( reserved=67108864, committed=2818048) - ( used=2748008) - ( waste=70040 =2.49%) - ( Class space:) - ( reserved=1073741824, committed=458752) - ( used=343568) - ( waste=115184 =25.11%) - \s - - Thread (reserved=21020080, committed=847280) - (thread #20) - (stack: reserved=20971520, committed=798720) - (malloc=27512 #125)\s - (arena=21048 #37) - \s - - Code (reserved=253796784, committed=7836080) - (malloc=105944 #1403)\s - (mmap: reserved=253689856, committed=7729152)\s - (arena=984 #1) - \s - - GC (reserved=373343252, committed=76530708) - (malloc=22463508 #720)\s - (mmap: reserved=350879744, committed=54067200)\s - \s - - Compiler (reserved=1926356, committed=1926356) - (malloc=20428 #73)\s - (arena=1905928 #20) - \s - - Internal (reserved=242257, committed=242257) - (malloc=176721 #1808)\s - (mmap: reserved=65536, committed=65536)\s - \s - - Other (reserved=4096, committed=4096) - (malloc=4096 #2)\s - \s - - Symbol (reserved=1505072, committed=1505072) - (malloc=1136432 #14482)\s - (arena=368640 #1) - \s - - Native Memory Tracking (reserved=373448, committed=373448) - (malloc=6280 #91)\s - (tracking overhead=367168) - \s - - Shared class space (reserved=16777216, committed=12386304) - (mmap: reserved=16777216, committed=12386304)\s - \s - - Arena Chunk (reserved=503216, committed=503216) - (malloc=503216)\s - \s - - Tracing (reserved=33097, committed=33097) - (malloc=369 #10)\s - (arena=32728 #1) - \s - - Arguments (reserved=160, committed=160) - (malloc=160 #5)\s - \s - - Module (reserved=169168, committed=169168) - (malloc=169168 #1266)\s - \s - - Safepoint (reserved=8192, committed=8192) - (mmap: reserved=8192, committed=8192)\s - \s - - Synchronization (reserved=31160, committed=31160) - (malloc=31160 #452)\s - \s - - Serviceability (reserved=600, committed=600) - (malloc=600 #6)\s - \s - - Metaspace (reserved=67120768, committed=2829952) - (malloc=11904 #12)\s - (mmap: reserved=67108864, committed=2818048)\s - \s - - String Deduplication (reserved=632, committed=632) - (malloc=632 #8)\s - \s - - Object Monitors (reserved=832, committed=832) - (malloc=832 #4)\s - \s - - """); + " Native Memory Tracking:\n" + + "\n" + + " Total: reserved=10341970661, committed=642716389\n" + + " malloc: 27513573 #22947\n" + + " mmap: reserved=10314457088, committed=615202816\n" + + "\n" + + " - Java Heap (reserved=8531214336, committed=536870912)\n" + + " (mmap: reserved=8531214336, committed=536870912) \n" + + " \n" + + " - Class (reserved=1073899939, committed=616867)\n" + + " (classes #1630)\n" + + " ( instance classes #1462, array classes #168)\n" + + " (malloc=158115 #2350) \n" + + " (mmap: reserved=1073741824, committed=458752) \n" + + " ( Metadata: )\n" + + " ( reserved=67108864, committed=2818048)\n" + + " ( used=2748008)\n" + + " ( waste=70040 =2.49%)\n" + + " ( Class space:)\n" + + " ( reserved=1073741824, committed=458752)\n" + + " ( used=343568)\n" + + " ( waste=115184 =25.11%)\n" + + " \n" + + " - Thread (reserved=21020080, committed=847280)\n" + + " (thread #20)\n" + + " (stack: reserved=20971520, committed=798720)\n" + + " (malloc=27512 #125) \n" + + " (arena=21048 #37)\n" + + " \n" + + " - Code (reserved=253796784, committed=7836080)\n" + + " (malloc=105944 #1403) \n" + + " (mmap: reserved=253689856, committed=7729152) \n" + + " (arena=984 #1)\n" + + " \n" + + " - GC (reserved=373343252, committed=76530708)\n" + + " (malloc=22463508 #720) \n" + + " (mmap: reserved=350879744, committed=54067200) \n" + + " \n" + + " - Compiler (reserved=1926356, committed=1926356)\n" + + " (malloc=20428 #73) \n" + + " (arena=1905928 #20)\n" + + " \n" + + " - Internal (reserved=242257, committed=242257)\n" + + " (malloc=176721 #1808) \n" + + " (mmap: reserved=65536, committed=65536) \n" + + " \n" + + " - Other (reserved=4096, committed=4096)\n" + + " (malloc=4096 #2) \n" + + " \n" + + " - Symbol (reserved=1505072, committed=1505072)\n" + + " (malloc=1136432 #14482) \n" + + " (arena=368640 #1)\n" + + " \n" + + " - Native Memory Tracking (reserved=373448, committed=373448)\n" + + " (malloc=6280 #91) \n" + + " (tracking overhead=367168)\n" + + " \n" + + " - Shared class space (reserved=16777216, committed=12386304)\n" + + " (mmap: reserved=16777216, committed=12386304) \n" + + " \n" + + " - Arena Chunk (reserved=503216, committed=503216)\n" + + " (malloc=503216) \n" + + " \n" + + " - Tracing (reserved=33097, committed=33097)\n" + + " (malloc=369 #10) \n" + + " (arena=32728 #1)\n" + + " \n" + + " - Arguments (reserved=160, committed=160)\n" + + " (malloc=160 #5) \n" + + " \n" + + " - Module (reserved=169168, committed=169168)\n" + + " (malloc=169168 #1266) \n" + + " \n" + + " - Safepoint (reserved=8192, committed=8192)\n" + + " (mmap: reserved=8192, committed=8192) \n" + + " \n" + + " - Synchronization (reserved=31160, committed=31160)\n" + + " (malloc=31160 #452) \n" + + " \n" + + " - Serviceability (reserved=600, committed=600)\n" + + " (malloc=600 #6) \n" + + " \n" + + " - Metaspace (reserved=67120768, committed=2829952)\n" + + " (malloc=11904 #12) \n" + + " (mmap: reserved=67108864, committed=2818048) \n" + + " \n" + + " - String Deduplication (reserved=632, committed=632)\n" + + " (malloc=632 #8) \n" + + " \n" + + " - Object Monitors (reserved=832, committed=832)\n" + + " (malloc=832 #4) \n" + + " \n" + + "\n" + + " "); PrometheusRegistry registry = new PrometheusRegistry(); new JvmNativeMemoryMetrics.Builder(PrometheusProperties.get(), adapter).register(registry); MetricSnapshots snapshots = registry.scrape(); String expected = -""" -# TYPE jvm_native_memory_committed_bytes gauge -# UNIT jvm_native_memory_committed_bytes bytes -# HELP jvm_native_memory_committed_bytes Committed bytes of a given JVM. Committed memory represents the amount of memory the JVM is using right now. -jvm_native_memory_committed_bytes{pool="Arena Chunk"} 503216.0 -jvm_native_memory_committed_bytes{pool="Arguments"} 160.0 -jvm_native_memory_committed_bytes{pool="Class"} 616867.0 -jvm_native_memory_committed_bytes{pool="Code"} 7836080.0 -jvm_native_memory_committed_bytes{pool="Compiler"} 1926356.0 -jvm_native_memory_committed_bytes{pool="GC"} 7.6530708E7 -jvm_native_memory_committed_bytes{pool="Internal"} 242257.0 -jvm_native_memory_committed_bytes{pool="Java Heap"} 5.36870912E8 -jvm_native_memory_committed_bytes{pool="Metaspace"} 2829952.0 -jvm_native_memory_committed_bytes{pool="Module"} 169168.0 -jvm_native_memory_committed_bytes{pool="Native Memory Tracking"} 373448.0 -jvm_native_memory_committed_bytes{pool="Object Monitors"} 832.0 -jvm_native_memory_committed_bytes{pool="Other"} 4096.0 -jvm_native_memory_committed_bytes{pool="Safepoint"} 8192.0 -jvm_native_memory_committed_bytes{pool="Serviceability"} 600.0 -jvm_native_memory_committed_bytes{pool="Shared class space"} 1.2386304E7 -jvm_native_memory_committed_bytes{pool="String Deduplication"} 632.0 -jvm_native_memory_committed_bytes{pool="Symbol"} 1505072.0 -jvm_native_memory_committed_bytes{pool="Synchronization"} 31160.0 -jvm_native_memory_committed_bytes{pool="Thread"} 847280.0 -jvm_native_memory_committed_bytes{pool="Total"} 6.42716389E8 -jvm_native_memory_committed_bytes{pool="Tracing"} 33097.0 -# TYPE jvm_native_memory_reserved_bytes gauge -# UNIT jvm_native_memory_reserved_bytes bytes -# HELP jvm_native_memory_reserved_bytes Reserved bytes of a given JVM. Reserved memory represents the total amount of memory the JVM can potentially use. -jvm_native_memory_reserved_bytes{pool="Arena Chunk"} 503216.0 -jvm_native_memory_reserved_bytes{pool="Arguments"} 160.0 -jvm_native_memory_reserved_bytes{pool="Class"} 1.073899939E9 -jvm_native_memory_reserved_bytes{pool="Code"} 2.53796784E8 -jvm_native_memory_reserved_bytes{pool="Compiler"} 1926356.0 -jvm_native_memory_reserved_bytes{pool="GC"} 3.73343252E8 -jvm_native_memory_reserved_bytes{pool="Internal"} 242257.0 -jvm_native_memory_reserved_bytes{pool="Java Heap"} 8.531214336E9 -jvm_native_memory_reserved_bytes{pool="Metaspace"} 6.7120768E7 -jvm_native_memory_reserved_bytes{pool="Module"} 169168.0 -jvm_native_memory_reserved_bytes{pool="Native Memory Tracking"} 373448.0 -jvm_native_memory_reserved_bytes{pool="Object Monitors"} 832.0 -jvm_native_memory_reserved_bytes{pool="Other"} 4096.0 -jvm_native_memory_reserved_bytes{pool="Safepoint"} 8192.0 -jvm_native_memory_reserved_bytes{pool="Serviceability"} 600.0 -jvm_native_memory_reserved_bytes{pool="Shared class space"} 1.6777216E7 -jvm_native_memory_reserved_bytes{pool="String Deduplication"} 632.0 -jvm_native_memory_reserved_bytes{pool="Symbol"} 1505072.0 -jvm_native_memory_reserved_bytes{pool="Synchronization"} 31160.0 -jvm_native_memory_reserved_bytes{pool="Thread"} 2.102008E7 -jvm_native_memory_reserved_bytes{pool="Total"} 1.0341970661E10 -jvm_native_memory_reserved_bytes{pool="Tracing"} 33097.0 -# EOF -"""; + "# TYPE jvm_native_memory_committed_bytes gauge\n" + + "# UNIT jvm_native_memory_committed_bytes bytes\n" + + "# HELP jvm_native_memory_committed_bytes Committed bytes of a given JVM. Committed memory represents the amount of memory the JVM is using right now.\n" + + "jvm_native_memory_committed_bytes{pool=\"Arena Chunk\"} 503216.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Arguments\"} 160.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Class\"} 616867.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Code\"} 7836080.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Compiler\"} 1926356.0\n" + + "jvm_native_memory_committed_bytes{pool=\"GC\"} 7.6530708E7\n" + + "jvm_native_memory_committed_bytes{pool=\"Internal\"} 242257.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Java Heap\"} 5.36870912E8\n" + + "jvm_native_memory_committed_bytes{pool=\"Metaspace\"} 2829952.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Module\"} 169168.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Native Memory Tracking\"} 373448.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Object Monitors\"} 832.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Other\"} 4096.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Safepoint\"} 8192.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Serviceability\"} 600.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Shared class space\"} 1.2386304E7\n" + + "jvm_native_memory_committed_bytes{pool=\"String Deduplication\"} 632.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Symbol\"} 1505072.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Synchronization\"} 31160.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Thread\"} 847280.0\n" + + "jvm_native_memory_committed_bytes{pool=\"Total\"} 6.42716389E8\n" + + "jvm_native_memory_committed_bytes{pool=\"Tracing\"} 33097.0\n" + + "# TYPE jvm_native_memory_reserved_bytes gauge\n" + + "# UNIT jvm_native_memory_reserved_bytes bytes\n" + + "# HELP jvm_native_memory_reserved_bytes Reserved bytes of a given JVM. Reserved memory represents the total amount of memory the JVM can potentially use.\n" + + "jvm_native_memory_reserved_bytes{pool=\"Arena Chunk\"} 503216.0\n" + + "jvm_native_memory_reserved_bytes{pool=\"Arguments\"} 160.0\n" + + "jvm_native_memory_reserved_bytes{pool=\"Class\"} 1.073899939E9\n" + + "jvm_native_memory_reserved_bytes{pool=\"Code\"} 2.53796784E8\n" + + "jvm_native_memory_reserved_bytes{pool=\"Compiler\"} 1926356.0\n" + + "jvm_native_memory_reserved_bytes{pool=\"GC\"} 3.73343252E8\n" + + "jvm_native_memory_reserved_bytes{pool=\"Internal\"} 242257.0\n" + + "jvm_native_memory_reserved_bytes{pool=\"Java Heap\"} 8.531214336E9\n" + + "jvm_native_memory_reserved_bytes{pool=\"Metaspace\"} 6.7120768E7\n" + + "jvm_native_memory_reserved_bytes{pool=\"Module\"} 169168.0\n" + + "jvm_native_memory_reserved_bytes{pool=\"Native Memory Tracking\"} 373448.0\n" + + "jvm_native_memory_reserved_bytes{pool=\"Object Monitors\"} 832.0\n" + + "jvm_native_memory_reserved_bytes{pool=\"Other\"} 4096.0\n" + + "jvm_native_memory_reserved_bytes{pool=\"Safepoint\"} 8192.0\n" + + "jvm_native_memory_reserved_bytes{pool=\"Serviceability\"} 600.0\n" + + "jvm_native_memory_reserved_bytes{pool=\"Shared class space\"} 1.6777216E7\n" + + "jvm_native_memory_reserved_bytes{pool=\"String Deduplication\"} 632.0\n" + + "jvm_native_memory_reserved_bytes{pool=\"Symbol\"} 1505072.0\n" + + "jvm_native_memory_reserved_bytes{pool=\"Synchronization\"} 31160.0\n" + + "jvm_native_memory_reserved_bytes{pool=\"Thread\"} 2.102008E7\n" + + "jvm_native_memory_reserved_bytes{pool=\"Total\"} 1.0341970661E10\n" + + "jvm_native_memory_reserved_bytes{pool=\"Tracing\"} 33097.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(snapshots)).isEqualTo(expected); } diff --git a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmRuntimeInfoMetricTest.java b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmRuntimeInfoMetricTest.java index a477065c9..35057bd51 100644 --- a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmRuntimeInfoMetricTest.java +++ b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmRuntimeInfoMetricTest.java @@ -21,12 +21,10 @@ public void testGoodCase() throws IOException { MetricSnapshots snapshots = registry.scrape(); String expected = -""" -# TYPE jvm_runtime info -# HELP jvm_runtime JVM runtime info -jvm_runtime_info{runtime="OpenJDK Runtime Environment",vendor="Oracle Corporation",version="1.8.0_382-b05"} 1 -# EOF -"""; + "# TYPE jvm_runtime info\n" + + "# HELP jvm_runtime JVM runtime info\n" + + "jvm_runtime_info{runtime=\"OpenJDK Runtime Environment\",vendor=\"Oracle Corporation\",version=\"1.8.0_382-b05\"} 1\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(snapshots)).isEqualTo(expected); } diff --git a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmThreadsMetricsTest.java b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmThreadsMetricsTest.java index cd651cc7f..b8063e299 100644 --- a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmThreadsMetricsTest.java +++ b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmThreadsMetricsTest.java @@ -55,36 +55,34 @@ public void testGoodCase() throws IOException { MetricSnapshots snapshots = registry.scrape(); String expected = -""" -# TYPE jvm_threads_current gauge -# HELP jvm_threads_current Current thread count of a JVM -jvm_threads_current 300.0 -# TYPE jvm_threads_daemon gauge -# HELP jvm_threads_daemon Daemon thread count of a JVM -jvm_threads_daemon 200.0 -# TYPE jvm_threads_deadlocked gauge -# HELP jvm_threads_deadlocked Cycles of JVM-threads that are in deadlock waiting to acquire object monitors or ownable synchronizers -jvm_threads_deadlocked 3.0 -# TYPE jvm_threads_deadlocked_monitor gauge -# HELP jvm_threads_deadlocked_monitor Cycles of JVM-threads that are in deadlock waiting to acquire object monitors -jvm_threads_deadlocked_monitor 3.0 -# TYPE jvm_threads_peak gauge -# HELP jvm_threads_peak Peak thread count of a JVM -jvm_threads_peak 301.0 -# TYPE jvm_threads_started counter -# HELP jvm_threads_started Started thread count of a JVM -jvm_threads_started_total 503.0 -# TYPE jvm_threads_state gauge -# HELP jvm_threads_state Current count of threads by state -jvm_threads_state{state="BLOCKED"} 1.0 -jvm_threads_state{state="NEW"} 0.0 -jvm_threads_state{state="RUNNABLE"} 2.0 -jvm_threads_state{state="TERMINATED"} 0.0 -jvm_threads_state{state="TIMED_WAITING"} 0.0 -jvm_threads_state{state="UNKNOWN"} 0.0 -jvm_threads_state{state="WAITING"} 0.0 -# EOF -"""; + "# TYPE jvm_threads_current gauge\n" + + "# HELP jvm_threads_current Current thread count of a JVM\n" + + "jvm_threads_current 300.0\n" + + "# TYPE jvm_threads_daemon gauge\n" + + "# HELP jvm_threads_daemon Daemon thread count of a JVM\n" + + "jvm_threads_daemon 200.0\n" + + "# TYPE jvm_threads_deadlocked gauge\n" + + "# HELP jvm_threads_deadlocked Cycles of JVM-threads that are in deadlock waiting to acquire object monitors or ownable synchronizers\n" + + "jvm_threads_deadlocked 3.0\n" + + "# TYPE jvm_threads_deadlocked_monitor gauge\n" + + "# HELP jvm_threads_deadlocked_monitor Cycles of JVM-threads that are in deadlock waiting to acquire object monitors\n" + + "jvm_threads_deadlocked_monitor 3.0\n" + + "# TYPE jvm_threads_peak gauge\n" + + "# HELP jvm_threads_peak Peak thread count of a JVM\n" + + "jvm_threads_peak 301.0\n" + + "# TYPE jvm_threads_started counter\n" + + "# HELP jvm_threads_started Started thread count of a JVM\n" + + "jvm_threads_started_total 503.0\n" + + "# TYPE jvm_threads_state gauge\n" + + "# HELP jvm_threads_state Current count of threads by state\n" + + "jvm_threads_state{state=\"BLOCKED\"} 1.0\n" + + "jvm_threads_state{state=\"NEW\"} 0.0\n" + + "jvm_threads_state{state=\"RUNNABLE\"} 2.0\n" + + "jvm_threads_state{state=\"TERMINATED\"} 0.0\n" + + "jvm_threads_state{state=\"TIMED_WAITING\"} 0.0\n" + + "jvm_threads_state{state=\"UNKNOWN\"} 0.0\n" + + "jvm_threads_state{state=\"WAITING\"} 0.0\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(snapshots)).isEqualTo(expected); } @@ -181,7 +179,13 @@ public long getId() { } } - private record TestRunnable(CountDownLatch countDownLatch) implements Runnable { + private static class TestRunnable implements Runnable { + private final CountDownLatch countDownLatch; + + TestRunnable(CountDownLatch countDownLatch) { + this.countDownLatch = countDownLatch; + } + @Override public void run() { try { diff --git a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/ProcessMetricsTest.java b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/ProcessMetricsTest.java index f5804ad7f..2a447a5ec 100644 --- a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/ProcessMetricsTest.java +++ b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/ProcessMetricsTest.java @@ -52,44 +52,36 @@ public void testGoodCase() throws IOException { MetricSnapshots snapshots = registry.scrape(); String expected = - """ - # TYPE process_cpu_seconds counter - # UNIT process_cpu_seconds seconds - # HELP process_cpu_seconds Total user and system CPU time spent in seconds. - process_cpu_seconds_total 0.072 - # TYPE process_max_fds gauge - # HELP process_max_fds Maximum number of open file descriptors. - process_max_fds 244.0 - # TYPE process_open_fds gauge - # HELP process_open_fds Number of open file descriptors. - process_open_fds 127.0 - """; + "# TYPE process_cpu_seconds counter\n" + + "# UNIT process_cpu_seconds seconds\n" + + "# HELP process_cpu_seconds Total user and system CPU time spent in seconds.\n" + + "process_cpu_seconds_total 0.072\n" + + "# TYPE process_max_fds gauge\n" + + "# HELP process_max_fds Maximum number of open file descriptors.\n" + + "process_max_fds 244.0\n" + + "# TYPE process_open_fds gauge\n" + + "# HELP process_open_fds Number of open file descriptors.\n" + + "process_open_fds 127.0\n"; // To allow running this test in non-linux environments if (ProcessMetrics.PROC_SELF_STATUS.canRead()) { expected += - """ - # TYPE process_resident_memory_bytes gauge - # UNIT process_resident_memory_bytes bytes - # HELP process_resident_memory_bytes Resident memory size in bytes. - process_resident_memory_bytes 1036288.0 - """; + "# TYPE process_resident_memory_bytes gauge\n" + + "# UNIT process_resident_memory_bytes bytes\n" + + "# HELP process_resident_memory_bytes Resident memory size in bytes.\n" + + "process_resident_memory_bytes 1036288.0\n"; } expected += - """ - # TYPE process_start_time_seconds gauge - # UNIT process_start_time_seconds seconds - # HELP process_start_time_seconds Start time of the process since unix epoch in seconds. - process_start_time_seconds 37.1 - """; + "# TYPE process_start_time_seconds gauge\n" + + "# UNIT process_start_time_seconds seconds\n" + + "# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.\n" + + "process_start_time_seconds 37.1\n"; // To allow running this test in non-linux environments if (ProcessMetrics.PROC_SELF_STATUS.canRead()) { expected += - """ - # TYPE process_virtual_memory_bytes gauge - # UNIT process_virtual_memory_bytes bytes - # HELP process_virtual_memory_bytes Virtual memory size in bytes. - process_virtual_memory_bytes 6180864.0 - """; + "# TYPE process_virtual_memory_bytes gauge\n" + + "# UNIT process_virtual_memory_bytes bytes\n" + + "# HELP process_virtual_memory_bytes Virtual memory size in bytes.\n" + + "process_virtual_memory_bytes 6180864.0\n"; } expected += "# EOF\n"; @@ -107,13 +99,11 @@ public void testMinimal() throws IOException { MetricSnapshots snapshots = registry.scrape(); String expected = - """ - # TYPE process_start_time_seconds gauge - # UNIT process_start_time_seconds seconds - # HELP process_start_time_seconds Start time of the process since unix epoch in seconds. - process_start_time_seconds 37.1 - # EOF - """; + "# TYPE process_start_time_seconds gauge\n" + + "# UNIT process_start_time_seconds seconds\n" + + "# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.\n" + + "process_start_time_seconds 37.1\n" + + "# EOF\n"; assertThat(convertToOpenMetricsFormat(snapshots)).isEqualTo(expected); } diff --git a/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/HistogramSnapshotTest.java b/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/HistogramSnapshotTest.java index 54eefbe66..8867c73e3 100644 --- a/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/HistogramSnapshotTest.java +++ b/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/HistogramSnapshotTest.java @@ -105,18 +105,18 @@ public void testGoodCaseComplete() { int i = 0; for (ClassicHistogramBucket bucket : data.getClassicBuckets()) { switch (i++) { - case 0 -> { + case 0: assertThat(bucket.getUpperBound()).isEqualTo(128.0); assertThat(bucket.getCount()).isEqualTo(7); - } - case 1 -> { + break; + case 1: assertThat(bucket.getUpperBound()).isEqualTo(1024.0); assertThat(bucket.getCount()).isEqualTo(15); - } - case 2 -> { + break; + case 2: assertThat(bucket.getUpperBound()).isEqualTo(Double.POSITIVE_INFINITY); assertThat(bucket.getCount()).isZero(); - } + break; } } assertThat(i).as("expecting 3 classic histogram buckets").isEqualTo(3); @@ -128,18 +128,18 @@ public void testGoodCaseComplete() { i = 0; for (NativeHistogramBucket bucket : data.getNativeBucketsForPositiveValues()) { switch (i++) { - case 0 -> { + case 0: assertThat(bucket.getBucketIndex()).isOne(); assertThat(bucket.getCount()).isEqualTo(12); - } - case 1 -> { + break; + case 1: assertThat(bucket.getBucketIndex()).isEqualTo(2); assertThat(bucket.getCount()).isEqualTo(3); - } - case 2 -> { + break; + case 2: assertThat(bucket.getBucketIndex()).isEqualTo(4); assertThat(bucket.getCount()).isEqualTo(2); - } + break; } } assertThat(i).as("expecting 3 native buckets for positive values").isEqualTo(3); @@ -147,14 +147,14 @@ public void testGoodCaseComplete() { assertThat(data.getNativeBucketsForNegativeValues().size()).isEqualTo(2); for (NativeHistogramBucket bucket : data.getNativeBucketsForNegativeValues()) { switch (i++) { - case 0 -> { + case 0: assertThat(bucket.getBucketIndex()).isEqualTo(-1); assertThat(bucket.getCount()).isOne(); - } - case 1 -> { + break; + case 1: assertThat(bucket.getBucketIndex()).isZero(); assertThat(bucket.getCount()).isEqualTo(2); - } + break; } } assertThat(i).as("expecting 2 native buckets for positive values").isEqualTo(2); diff --git a/prometheus-metrics-parent/pom.xml b/prometheus-metrics-parent/pom.xml index 075eaf782..c5b521b1a 100644 --- a/prometheus-metrics-parent/pom.xml +++ b/prometheus-metrics-parent/pom.xml @@ -68,29 +68,39 @@ - - com.diffplug.spotless - spotless-maven-plugin - 3.1.0 - - - - - ${spotless.skip} - - - - verify - - check - - - - + + java17-plus + + [17,) + + + + + com.diffplug.spotless + spotless-maven-plugin + 3.1.0 + + + + + ${spotless.skip} + + + + verify + + check + + + + + + + release