Skip to content

Commit

Permalink
Merge c552dff into c51eeb9
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceko committed Oct 18, 2016
2 parents c51eeb9 + c552dff commit 20f9307
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class WildflyRestMetricsTimerContextFactory {

private static final Logger LOGGER = LoggerFactory.getLogger(WildflyRestMetricsTimerContextFactory.class);
private static final BaseTimeContextFactory BASE_TIME_CONTEXT_FACTORY = new BaseTimeContextFactory("wildfly.rest.total");
private static final String URL_PARTS_TO_REMOVE = "/query|/command|/api|/view|/controller|/rest|/[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}|/$|^/";
private static final String URL_PARTS_TO_REMOVE = "/query|/command|/api|/view|/controller|/rest|/$|^/";
private static final String ID_PATTERN = "/[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}|/[0-9][A-Za-z0-9]*";


public static TimerContext timerContextOf(final String requestURL) {
Expand All @@ -21,6 +22,6 @@ public static TimerContext timerContextOf(final String requestURL) {
}

static String timerContextNameFrom(final String requestURL) {
return format("wildfly.rest.%s", requestURL.replaceAll(URL_PARTS_TO_REMOVE, ""));
return format("wildfly.rest.%s", requestURL.replaceAll(URL_PARTS_TO_REMOVE, "")).replaceAll(ID_PATTERN, "/{id}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@ public void setUp() throws Exception {
public void shouldCollectMetricsForRestRequests() throws Exception {
HttpServerExchange exchange1 = new HttpServerExchange("/example-query-view/query/view/rest/cakeshop/recipes");
HttpServerExchange exchange2 = new HttpServerExchange("/example-query-view/query/view/rest/cakeshop/recipes/163af847-effb-46a9-96bc-32a0f7526e14");
HttpServerExchange exchange3 = new HttpServerExchange("/example-query-controller/query/controller/rest/cakeshop/recipes");
HttpServerExchange exchange3 = new HttpServerExchange("/example-query-view/query/view/rest/cakeshop/recipes/163af847-effb-46a9-96bc-32a0f7526e15");
HttpServerExchange exchange4 = new HttpServerExchange("/example-query-controller/query/controller/rest/cakeshop/recipes");

agentHelper.onEntry(exchange1);
agentHelper.onEntry(exchange2);
agentHelper.onEntry(exchange3);
agentHelper.onEntry(exchange4);

agentHelper.onExit(exchange2);
agentHelper.onExit(exchange1);
agentHelper.onExit(exchange4);
agentHelper.onExit(exchange3);

assertThat(TimerRegistry.timerOf("wildfly.rest.example-query-view/cakeshop/recipes").getCount(), is(2L));
assertThat(TimerRegistry.timerOf("wildfly.rest.example-query-view/cakeshop/recipes").getCount(), is(1L));
assertThat(TimerRegistry.timerOf("wildfly.rest.example-query-view/cakeshop/recipes/{id}").getCount(), is(2L));
assertThat(TimerRegistry.timerOf("wildfly.rest.example-query-controller/cakeshop/recipes").getCount(), is(1L));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public void shouldConstructTimerName() throws Exception {
assertThat(timerContextNameFrom("/example-query-api/query/api/rest/cakeshop/recipes"),
is("wildfly.rest.example-query-api/cakeshop/recipes"));

assertThat(timerContextNameFrom("/example-query-api/query/api/rest/cakeshop/recipes/263af847-effb-46a9-96bc-32a0f7526e44"),
is("wildfly.rest.example-query-api/cakeshop/recipes"));

assertThat(timerContextNameFrom("/example-query-controller/query/controller/rest/cakeshop/recipes/"),
is("wildfly.rest.example-query-controller/cakeshop/recipes"));

Expand All @@ -32,6 +29,23 @@ public void shouldConstructTimerName() throws Exception {

}

@Test
public void shouldReplaceIdsWithPlaceHolders() throws Exception {

assertThat(timerContextNameFrom("/example-query-api/query/api/rest/cakeshop/recipes/263af847-effb-46a9-96bc-32a0f7526e44"),
is("wildfly.rest.example-query-api/cakeshop/recipes/{id}"));

assertThat(timerContextNameFrom("/example-query-api/query/api/rest/cakeshop/recipes/123aa"),
is("wildfly.rest.example-query-api/cakeshop/recipes/{id}"));

assertThat(timerContextNameFrom("/example-query-api/query/api/rest/cakeshop/recipes/263af847-effb-46a9-96bc-32a0f7526e44/cakes"),
is("wildfly.rest.example-query-api/cakeshop/recipes/{id}/cakes"));

assertThat(timerContextNameFrom("/example-query-api/query/api/rest/cakeshop/recipes/123aa/cakes"),
is("wildfly.rest.example-query-api/cakeshop/recipes/{id}/cakes"));

}

@Test
public void shouldCreateTimerContextForRestRequest() {

Expand Down

0 comments on commit 20f9307

Please sign in to comment.