Skip to content

Commit

Permalink
Extend test of annotated Gauge metrics
Browse files Browse the repository at this point in the history
Define multiple `@Gauge` metrics in a class and verify that all of them
are being recorded.
  • Loading branch information
jsmrcka committed May 18, 2022
1 parent 6a2386e commit 793bb08
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@ public String simpleScenario() {

@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/gauge")
public long highestPrimeNumberSoFar() {
return getDefaultGauge();
@Path("/gauges")
public long gauges() {
return getFirstGauge() + getSecondGauge() + getThirdGauge();
}

@Gauge(name = "simple_gauge_mp", unit = MetricUnits.NONE)
public long getDefaultGauge() {
@Gauge(name = "first_gauge_mp", unit = MetricUnits.NONE)
public long getFirstGauge() {
return DEFAULT_GAUGE_VALUE;
}

@Gauge(name = "second_gauge_mp", unit = MetricUnits.NONE)
public long getSecondGauge() {
return DEFAULT_GAUGE_VALUE;
}

@Gauge(unit = MetricUnits.NONE)
public long getThirdGauge() {
return DEFAULT_GAUGE_VALUE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.hamcrest.Matchers.containsString;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import io.quarkus.test.scenarios.QuarkusScenario;
Expand All @@ -16,7 +17,9 @@ public class UsingMicroProfilePingPongResourceIT {
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 GAUGE_FORMAT = "simple_gauge_mp{scope=\"application\",} %s";
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;

@Test
Expand All @@ -25,10 +28,11 @@ public void testShouldReturnCountOne() {
thenCounterIs(1);
}

@Tag("QUARKUS-1545")
@Test
public void testShouldReturnDefaultGauge() {
whenCallPingPong("/gauge", "" + DEFAULT_GAUGE_VALUE);
thenGaugeIs(DEFAULT_GAUGE_VALUE);
public void testShouldReturnGauges() {
whenCallPingPong("/gauges", "" + DEFAULT_GAUGE_VALUE * 3);
thenGaugesAreSampled(DEFAULT_GAUGE_VALUE);
}

private void whenCallPingPong(String path, String expectedBody) {
Expand All @@ -44,9 +48,11 @@ private void thenCounterIs(int expectedCounter) {
.body(containsString(String.format(COUNTER_FORMAT, expectedCounter)));
}

private void thenGaugeIs(double expectedGauge) {
private void thenGaugesAreSampled(double expectedGauge) {
when().get("/q/metrics").then()
.statusCode(HttpStatus.SC_OK)
.body(containsString(String.format(GAUGE_FORMAT, expectedGauge)));
.body(containsString(String.format(FIRST_GAUGE_FORMAT, expectedGauge)),
containsString(String.format(SECOND_GAUGE_FORMAT, expectedGauge)),
containsString(String.format(THIRD_GAUGE_FORMAT, expectedGauge)));
}
}

0 comments on commit 793bb08

Please sign in to comment.