Skip to content

Commit

Permalink
Add http_method tag to micrometer metrics (#1968)
Browse files Browse the repository at this point in the history
* Add http_method tag to micrometer metrics

* Limit line length to 100 chars

* Applies eclipse-java-style to AbstractMetricsTestBase

* Fix AbstractMetricsTestBase format
  • Loading branch information
rnavarropiris authored Mar 17, 2023
1 parent f3b5943 commit 6c7f3d7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ protected void recordSuccess(RequestTemplate template, Response response) {
response.status() / 100 + "xx",
"http_status",
String.valueOf(response.status()),
"http_method",
template.methodMetadata().template().method(),
"uri",
template.methodMetadata().template().path()),
metricSuppliers.meters())
Expand All @@ -72,6 +74,8 @@ protected void recordFailure(RequestTemplate template, FeignException e) {
e.status() / 100 + "xx",
"http_status",
String.valueOf(e.status()),
"http_method",
template.methodMetadata().template().method(),
"uri",
template.methodMetadata().template().path()),
metricSuppliers.meters())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected void recordSuccess(RequestTemplate template, Response response) {
httpResponseCode(template)
.tagged("http_status", String.valueOf(response.status()))
.tagged("status_group", response.status() / 100 + "xx")
.tagged("http_method", template.methodMetadata().template().method())
.tagged("uri", template.methodMetadata().template().path()))
.inc();
}
Expand All @@ -65,6 +66,7 @@ protected void recordFailure(RequestTemplate template, FeignException e) {
ExceptionUtils.getRootCause(e).getClass().getSimpleName())
.tagged("http_status", String.valueOf(e.status()))
.tagged("status_group", e.status() / 100 + "xx")
.tagged("http_method", template.methodMetadata().template().method())
.tagged("uri", template.methodMetadata().template().path()))
.inc();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected void countResponseCode(
e,
Tag.of("http_status", String.valueOf(responseStatus)),
Tag.of("status_group", responseStatus / 100 + "xx"),
Tag.of("http_method", template.methodMetadata().template().method()),
Tag.of("uri", template.methodMetadata().template().path()))
.and(extraTags);
meterRegistry.counter(metricName.name("http_response_code"), allTags).increment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ public interface SimpleSource {
String get(String body);
}


public interface CompletableSource {

@RequestLine("GET /get")
CompletableFuture<String> get(String body);
}


protected MR metricsRegistry;

@Before
Expand Down Expand Up @@ -169,7 +171,8 @@ public void clientPropagatesUncheckedException() {
}

assertThat(
getMetric("http_response_code", "http_status", "404", "status_group", "4xx"),
getMetric("http_response_code", "http_status", "404", "status_group", "4xx",
"http_method", "GET"),
notNullValue());
}

Expand Down

0 comments on commit 6c7f3d7

Please sign in to comment.