Skip to content

Commit

Permalink
Merge pull request quarkus-qe#447 from pjgg/feat/QUARKUS-1571
Browse files Browse the repository at this point in the history
Gauge annotation is not registered or showing up
  • Loading branch information
Pablo Gonzalez Granados authored Jan 5, 2022
2 parents 8b55155 + 938aa16 commit cc4f2f3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,33 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.metrics.MetricUnits;
import org.eclipse.microprofile.metrics.annotation.Counted;
import org.eclipse.microprofile.metrics.annotation.Gauge;

@Path("/using-microprofile-pingpong")
public class UsingMicroProfilePingPongResource {

private static final String PING_PONG = "ping pong";
private static final long DEFAULT_GAUGE_VALUE = 100L;

@GET
@Counted(name = "simple_mp", absolute = true)
@Counted(name = "simple_counter_mp", absolute = true)
@Produces(MediaType.TEXT_PLAIN)
@Path("/counter")
public String simpleScenario() {
return PING_PONG;
}
}

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

@Gauge(name = "simple_gauge_mp", unit = MetricUnits.NONE)
public long getDefaultGauge() {
return DEFAULT_GAUGE_VALUE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,40 @@
@QuarkusScenario
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_mp_total{scope=\"application\",} %s.0";
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 long DEFAULT_GAUGE_VALUE = 100;

@Test
public void testShouldReturnCountOne() {
whenCallPingPong();
whenCallPingPong("/counter", PING_PONG);
thenCounterIs(1);
}

private void whenCallPingPong() {
@Test
public void testShouldReturnDefaultGauge() {
whenCallPingPong("/gauge", "" + DEFAULT_GAUGE_VALUE);
thenGaugeIs(DEFAULT_GAUGE_VALUE);
}

private void whenCallPingPong(String path, String expectedBody) {
given()
.when().get(PING_PONG_ENDPOINT)
.when().get(PING_PONG_ENDPOINT + path)
.then().statusCode(HttpStatus.SC_OK)
.body(is("ping pong"));
.body(is(expectedBody));
}

private void thenCounterIs(int expectedCounter) {
when().get("/q/metrics").then()
.statusCode(HttpStatus.SC_OK)
.body(containsString(String.format(COUNTER_FORMAT, expectedCounter)));
}

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

0 comments on commit cc4f2f3

Please sign in to comment.