Skip to content

Commit

Permalink
Add "host" tag to JettyClientMetrics.(micrometer-metrics#2054)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennys Fredericci committed Jul 22, 2020
1 parent 363b9d8 commit 28e86a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public final class JettyClientTags {

private static final Tag METHOD_UNKNOWN = Tag.of("method", "UNKNOWN");

private static final Tag HOST_UNKNOWN = Tag.of("host", "UNKNOWN");

private static final Pattern TRAILING_SLASH_PATTERN = Pattern.compile("/$");

private static final Pattern MULTIPLE_SLASH_PATTERN = Pattern.compile("//+");
Expand All @@ -63,6 +65,17 @@ public static Tag method(Request request) {
return (request != null) ? Tag.of("method", request.getMethod()) : METHOD_UNKNOWN;
}

/**
* Creates a {@code host} tag based on the {@link Request#getHost()
* method} of the given {@code request}.
*
* @param request the request
* @return the host tag derived from request result.
*/
public static Tag host(Request request) {
return (request != null) ? Tag.of("host", request.getHost()) : HOST_UNKNOWN;
}

/**
* Creates a {@code status} tag based on the status of the given {@code result}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public interface JettyClientTagsProvider {
* @return tags to associate with metrics recorded for the request
*/
default Iterable<Tag> httpRequestTags(Result result) {
return Tags.of(JettyClientTags.method(result.getRequest()), JettyClientTags.uri(result, this::uriPattern),
return Tags.of(JettyClientTags.method(result.getRequest()),
JettyClientTags.host(result.getRequest()),
JettyClientTags.uri(result, this::uriPattern),
JettyClientTags.exception(result), JettyClientTags.status(result),
JettyClientTags.outcome(result));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void successfulRequest() throws Exception {
.tag("outcome", "SUCCESS")
.tag("status", "200")
.tag("uri", "/ok")
.tag("host", "localhost")
.timer().count()).isEqualTo(1);
}

Expand All @@ -114,6 +115,7 @@ void requestSize() throws Exception {
.tag("outcome", "SUCCESS")
.tag("status", "200")
.tag("uri", "/ok")
.tag("host", "localhost")
.summary().totalAmount()).isEqualTo("123456".length());
}

Expand All @@ -129,6 +131,7 @@ void serverError() throws Exception {
.tag("outcome", "SERVER_ERROR")
.tag("status", "500")
.tag("uri", "/error")
.tag("host", "localhost")
.timer().count()).isEqualTo(1);
}

Expand All @@ -144,6 +147,7 @@ void handlerWrapperUncheckedException() throws Exception {
.tag("outcome", "SERVER_ERROR")
.tag("status", "500")
.tag("uri", "/errorUnchecked")
.tag("host", "localhost")
.timer().count()).isEqualTo(1);
}

Expand All @@ -159,6 +163,7 @@ void notFound() throws Exception {
.tag("outcome", "CLIENT_ERROR")
.tag("status", "404")
.tag("uri", "NOT_FOUND")
.tag("host", "localhost")
.timer().count()).isEqualTo(1);
}
}

0 comments on commit 28e86a5

Please sign in to comment.