From 809a3965c961752bcbbc4bcae488f34be062d480 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Tue, 18 Jun 2019 15:29:22 +0200 Subject: [PATCH] Add missing outcome tag for WebClient metrics On error cases, the "outcome" tag would be missing from recorded metrics for the `WebClient`. This commit fixes this issue and improves the reference documentation by mentioning the tag values used for error cases, when the client response is not received (I/O errors, client error, etc). Fixes gh-17219 --- .../client/DefaultWebClientExchangeTagsProvider.java | 10 +++------- .../DefaultWebClientExchangeTagsProviderTests.java | 4 ++-- .../src/main/asciidoc/production-ready-features.adoc | 5 +++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProvider.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProvider.java index df3b6861e3..b746b8ac4f 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProvider.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProvider.java @@ -37,13 +37,9 @@ public class DefaultWebClientExchangeTagsProvider implements WebClientExchangeTa Tag method = WebClientExchangeTags.method(request); Tag uri = WebClientExchangeTags.uri(request); Tag clientName = WebClientExchangeTags.clientName(request); - if (response != null) { - return Arrays.asList(method, uri, clientName, WebClientExchangeTags.status(response), - WebClientExchangeTags.outcome(response)); - } - else { - return Arrays.asList(method, uri, clientName, WebClientExchangeTags.status(throwable)); - } + return Arrays.asList(method, uri, clientName, + (response != null) ? WebClientExchangeTags.status(response) : WebClientExchangeTags.status(throwable), + WebClientExchangeTags.outcome(response)); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProviderTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProviderTests.java index 1de116f44c..64ac5882af 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProviderTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProviderTests.java @@ -77,14 +77,14 @@ class DefaultWebClientExchangeTagsProviderTests { void tagsWhenIoExceptionShouldReturnIoErrorStatus() { Iterable tags = this.tagsProvider.tags(this.request, null, new IOException()); assertThat(tags).containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/projects/{project}"), - Tag.of("clientName", "example.org"), Tag.of("status", "IO_ERROR")); + Tag.of("clientName", "example.org"), Tag.of("status", "IO_ERROR"), Tag.of("outcome", "UNKNOWN")); } @Test void tagsWhenExceptionShouldReturnClientErrorStatus() { Iterable tags = this.tagsProvider.tags(this.request, null, new IllegalArgumentException()); assertThat(tags).containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/projects/{project}"), - Tag.of("clientName", "example.org"), Tag.of("status", "CLIENT_ERROR")); + Tag.of("clientName", "example.org"), Tag.of("status", "CLIENT_ERROR"), Tag.of("outcome", "UNKNOWN")); } } diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index 7113dcdba8..998a4f56b9 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -1981,10 +1981,11 @@ following information: |`outcome` |Request's outcome based on the status code of the response. 1xx is `INFORMATIONAL`, 2xx is `SUCCESS`, 3xx is `REDIRECTION`, 4xx `CLIENT_ERROR`, and 5xx is -`SERVER_ERROR` +`SERVER_ERROR`, `UNKNOWN` otherwise |`status` -|Response's HTTP status code (for example, `200` or `500`) +|Response's HTTP status code if available (for example, `200` or `500`), +or `IO_ERROR` in case or I/O issues, `CLIENT_ERROR` otherwise |`uri` |Request's URI template prior to variable substitution, if possible (for example,