Skip to content

Commit

Permalink
Adapt to the new format of Prometheus metrics
Browse files Browse the repository at this point in the history
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 quarkusio/quarkus#30343 for details
  • Loading branch information
fedinskiy committed Jan 13, 2023
1 parent f731da1 commit c27474a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ public class HttpServerMetricsIT {
private static final int ASSERT_METRICS_TIMEOUT_MINUTES = 1;
private static final List<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit c27474a

Please sign in to comment.