-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix on RestPathAnnotationProcessor to ensure that the correct url tem…
…plate is computed for metrics
- Loading branch information
Showing
2 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...rc/test/java/io/quarkus/micrometer/deployment/binder/UriTagWithInterfaceResourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package io.quarkus.micrometer.deployment.binder; | ||
|
||
import static io.restassured.RestAssured.when; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.quarkus.micrometer.test.Util; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.vertx.http.runtime.CurrentVertxRequest; | ||
import io.restassured.RestAssured; | ||
import io.vertx.core.http.impl.HttpServerRequestInternal; | ||
|
||
class UriTagWithInterfaceResourceTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withConfigurationResource("test-logging.properties") | ||
.overrideConfigKey("quarkus.micrometer.binder-enabled-default", "false") | ||
.overrideConfigKey("quarkus.micrometer.binder.http-server.enabled", "true") | ||
.overrideConfigKey("quarkus.micrometer.binder.vertx.enabled", "true") | ||
.overrideConfigKey("quarkus.redis.devservices.enabled", "false") | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Util.class, | ||
InterfaceResourceReturningUrlTemplate.class, | ||
InterfaceResourceReturningUrlTemplateImpl.class)); | ||
|
||
@Inject | ||
MeterRegistry registry; | ||
|
||
@Test | ||
void testRequestUris() throws Exception { | ||
RestAssured.basePath = "/"; | ||
|
||
when().get("/class/path/method/path/test").then() | ||
.statusCode(200) | ||
.body(Matchers.is("/class/path/method/path/{param}")); | ||
|
||
Util.waitForMeters(registry.find("http.server.requests").timers(), 1); | ||
|
||
System.out.println("Server paths\n" + Util.listMeters(registry, "http.server.requests")); | ||
|
||
Assertions.assertEquals(1, | ||
registry.find("http.server.requests").tag("uri", "/class/path/method/path/{param}").timers().size(), | ||
Util.foundServerRequests(registry, "Servlet path (/servlet) should be returned by JAX-RS.")); | ||
} | ||
|
||
@Path("/class/path") | ||
public interface InterfaceResourceReturningUrlTemplate { | ||
|
||
@Path("method/path/{param}") | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
String getTemplatizedPath(@PathParam("param") String param); | ||
|
||
} | ||
|
||
public static class InterfaceResourceReturningUrlTemplateImpl implements InterfaceResourceReturningUrlTemplate { | ||
|
||
private final CurrentVertxRequest request; | ||
|
||
public InterfaceResourceReturningUrlTemplateImpl(CurrentVertxRequest request) { | ||
this.request = request; | ||
} | ||
|
||
@Override | ||
public String getTemplatizedPath(String param) { | ||
return ((HttpServerRequestInternal) request.getCurrent().request()).context().getLocal("UrlPathTemplate"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters