From c27474af13e2ab28feddca374850f52448128c34 Mon Sep 17 00:00:00 2001 From: Fedor Dudinskiy Date: Fri, 13 Jan 2023 08:47:02 +0100 Subject: [PATCH] Adapt to the new format of Prometheus metrics Starting from Quarkus 2.16, the trailing comma was dropped from Prometheus metrics This change either allows tests to use both options, or disables them on older Quarkus versions. See https://github.com/quarkusio/quarkus/issues/30343 for details --- .../micrometer/oidc/BaseMicrometerOidcSecurityIT.java | 6 ++++-- .../ts/micrometer/prometheus/HttpServerMetricsIT.java | 8 +++++++- .../ts/micrometer/prometheus/MicroProfileApiIT.java | 10 ++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/monitoring/micrometer-prometheus-oidc/src/test/java/io/quarkus/ts/micrometer/oidc/BaseMicrometerOidcSecurityIT.java b/monitoring/micrometer-prometheus-oidc/src/test/java/io/quarkus/ts/micrometer/oidc/BaseMicrometerOidcSecurityIT.java index 34ee84344..556423537 100644 --- a/monitoring/micrometer-prometheus-oidc/src/test/java/io/quarkus/ts/micrometer/oidc/BaseMicrometerOidcSecurityIT.java +++ b/monitoring/micrometer-prometheus-oidc/src/test/java/io/quarkus/ts/micrometer/oidc/BaseMicrometerOidcSecurityIT.java @@ -13,8 +13,10 @@ import io.quarkus.test.bootstrap.KeycloakService; import io.quarkus.test.bootstrap.RestService; +import io.quarkus.test.scenarios.annotations.DisabledOnQuarkusVersion; import io.quarkus.test.services.KeycloakContainer; +@DisabledOnQuarkusVersion(version = "(2\\.[2-9]\\..*)|(2\\.1[0-5]\\..*)", reason = "Fixed in Quarkus 2.16") public abstract class BaseMicrometerOidcSecurityIT { static final String NORMAL_USER = "test-normal-user"; @@ -24,8 +26,8 @@ public abstract class BaseMicrometerOidcSecurityIT { static final int ASSERT_SERVICE_TIMEOUT_MINUTES = 1; static final String USER_PATH = "/user"; static final String HTTP_METRIC = "http_server_requests_seconds_count{method=\"GET\","; - static final String OK_HTTP_CALL_METRIC = HTTP_METRIC + "outcome=\"SUCCESS\",status=\"200\",uri=\"%s\",}"; - static final String UNAUTHORIZED_HTTP_CALL_METRIC = HTTP_METRIC + "outcome=\"CLIENT_ERROR\",status=\"401\",uri=\"%s\",}"; + static final String OK_HTTP_CALL_METRIC = HTTP_METRIC + "outcome=\"SUCCESS\",status=\"200\",uri=\"%s\"}"; + static final String UNAUTHORIZED_HTTP_CALL_METRIC = HTTP_METRIC + "outcome=\"CLIENT_ERROR\",status=\"401\",uri=\"%s\"}"; //TODO Remove workaround after Keycloak is fixed https://github.com/keycloak/keycloak/issues/9916 @KeycloakContainer(command = { "start-dev --import-realm" }) diff --git a/monitoring/micrometer-prometheus/src/test/java/io/quarkus/ts/micrometer/prometheus/HttpServerMetricsIT.java b/monitoring/micrometer-prometheus/src/test/java/io/quarkus/ts/micrometer/prometheus/HttpServerMetricsIT.java index 4efcf8ba0..46ce7f514 100644 --- a/monitoring/micrometer-prometheus/src/test/java/io/quarkus/ts/micrometer/prometheus/HttpServerMetricsIT.java +++ b/monitoring/micrometer-prometheus/src/test/java/io/quarkus/ts/micrometer/prometheus/HttpServerMetricsIT.java @@ -22,7 +22,13 @@ public class HttpServerMetricsIT { private static final int ASSERT_METRICS_TIMEOUT_MINUTES = 1; private static final List HTTP_SERVER_REQUESTS_METRICS_SUFFIX = Arrays.asList("count", "sum", "max"); - private static final String HTTP_SERVER_REQUESTS_METRICS_FORMAT = "http_server_requests_seconds_%s{method=\"GET\",outcome=\"SUCCESS\",status=\"200\",uri=\"%s\",}"; + /* + * In versions before 2.16 metrics have format '{a,b,}' (with trailing comma) + * Starting from 2.16 the format changed to '{a,b}' + * See https://github.com/quarkusio/quarkus/issues/30343 for details + * TODO: add '}' to the end, when this stabilizes + */ + private static final String HTTP_SERVER_REQUESTS_METRICS_FORMAT = "http_server_requests_seconds_%s{method=\"GET\",outcome=\"SUCCESS\",status=\"200\",uri=\"%s\""; private static final String PING_PONG_ENDPOINT = "/without-metrics-pingpong"; @Test diff --git a/monitoring/micrometer-prometheus/src/test/java/io/quarkus/ts/micrometer/prometheus/MicroProfileApiIT.java b/monitoring/micrometer-prometheus/src/test/java/io/quarkus/ts/micrometer/prometheus/MicroProfileApiIT.java index 4f6908410..f4f4fa1f4 100644 --- a/monitoring/micrometer-prometheus/src/test/java/io/quarkus/ts/micrometer/prometheus/MicroProfileApiIT.java +++ b/monitoring/micrometer-prometheus/src/test/java/io/quarkus/ts/micrometer/prometheus/MicroProfileApiIT.java @@ -10,18 +10,20 @@ import org.junit.jupiter.api.Test; import io.quarkus.test.scenarios.QuarkusScenario; +import io.quarkus.test.scenarios.annotations.DisabledOnQuarkusVersion; import io.restassured.response.ValidatableResponse; import io.restassured.specification.RequestSpecification; @QuarkusScenario +@DisabledOnQuarkusVersion(version = "(2\\.[2-9]\\..*)|(2\\.1[0-5]\\..*)", reason = "Fixed in Quarkus 2.16") public class MicroProfileApiIT { private static final String PING_PONG = "ping pong"; private static final String PING_PONG_ENDPOINT = "/using-microprofile-pingpong"; - private static final String COUNTER_FORMAT = "simple_counter_mp_total{scope=\"application\",} %s.0"; - private static final String FIRST_GAUGE_FORMAT = "first_gauge_mp{scope=\"application\",} %s"; - private static final String SECOND_GAUGE_FORMAT = "second_gauge_mp{scope=\"application\",} %s"; - private static final String THIRD_GAUGE_FORMAT = "getThirdGauge{scope=\"application\",} %s"; + private static final String COUNTER_FORMAT = "simple_counter_mp_total{scope=\"application\"} %s.0"; + private static final String FIRST_GAUGE_FORMAT = "first_gauge_mp{scope=\"application\"} %s"; + private static final String SECOND_GAUGE_FORMAT = "second_gauge_mp{scope=\"application\"} %s"; + private static final String THIRD_GAUGE_FORMAT = "getThirdGauge{scope=\"application\"} %s"; private static final long DEFAULT_GAUGE_VALUE = 100; private static final long GAUGE_INCREMENT = 1;