Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
1acff410
Commit
1acff410
authored
Aug 29, 2019
by
Johnny Lim
Committed by
Andy Wilkinson
Aug 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve handling of non-standard status codes in RestTemplate metrics
See gh-17991
parent
7f8b3a7b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
23 deletions
+42
-23
RestTemplateExchangeTags.java
.../actuate/metrics/web/client/RestTemplateExchangeTags.java
+21
-18
WebClientExchangeTags.java
...te/metrics/web/reactive/client/WebClientExchangeTags.java
+2
-2
RestTemplateExchangeTagsTests.java
...ate/metrics/web/client/RestTemplateExchangeTagsTests.java
+18
-2
WebClientExchangeTagsTests.java
...trics/web/reactive/client/WebClientExchangeTagsTests.java
+1
-1
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTags.java
View file @
1acff410
...
@@ -18,6 +18,9 @@ package org.springframework.boot.actuate.metrics.web.client;
...
@@ -18,6 +18,9 @@ package org.springframework.boot.actuate.metrics.web.client;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URI
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
io.micrometer.core.instrument.Tag
;
import
io.micrometer.core.instrument.Tag
;
...
@@ -54,6 +57,18 @@ public final class RestTemplateExchangeTags {
...
@@ -54,6 +57,18 @@ public final class RestTemplateExchangeTags {
private
static
final
Tag
OUTCOME_SERVER_ERROR
=
Tag
.
of
(
"outcome"
,
"SERVER_ERROR"
);
private
static
final
Tag
OUTCOME_SERVER_ERROR
=
Tag
.
of
(
"outcome"
,
"SERVER_ERROR"
);
private
static
final
Map
<
HttpStatus
.
Series
,
Tag
>
SERIES_OUTCOMES
;
static
{
Map
<
HttpStatus
.
Series
,
Tag
>
seriesOutcomes
=
new
HashMap
<>();
seriesOutcomes
.
put
(
HttpStatus
.
Series
.
INFORMATIONAL
,
OUTCOME_INFORMATIONAL
);
seriesOutcomes
.
put
(
HttpStatus
.
Series
.
SUCCESSFUL
,
OUTCOME_SUCCESS
);
seriesOutcomes
.
put
(
HttpStatus
.
Series
.
REDIRECTION
,
OUTCOME_REDIRECTION
);
seriesOutcomes
.
put
(
HttpStatus
.
Series
.
CLIENT_ERROR
,
OUTCOME_CLIENT_ERROR
);
seriesOutcomes
.
put
(
HttpStatus
.
Series
.
SERVER_ERROR
,
OUTCOME_SERVER_ERROR
);
SERIES_OUTCOMES
=
Collections
.
unmodifiableMap
(
seriesOutcomes
);
}
private
RestTemplateExchangeTags
()
{
private
RestTemplateExchangeTags
()
{
}
}
...
@@ -132,7 +147,7 @@ public final class RestTemplateExchangeTags {
...
@@ -132,7 +147,7 @@ public final class RestTemplateExchangeTags {
/**
/**
* Creates an {@code outcome} {@code Tag} derived from the
* Creates an {@code outcome} {@code Tag} derived from the
* {@link ClientHttpResponse#getStatusCode() status} of the given {@code response}.
* {@link ClientHttpResponse#get
Raw
StatusCode() status} of the given {@code response}.
* @param response the response
* @param response the response
* @return the outcome tag
* @return the outcome tag
* @since 2.2.0
* @since 2.2.0
...
@@ -140,28 +155,16 @@ public final class RestTemplateExchangeTags {
...
@@ -140,28 +155,16 @@ public final class RestTemplateExchangeTags {
public
static
Tag
outcome
(
ClientHttpResponse
response
)
{
public
static
Tag
outcome
(
ClientHttpResponse
response
)
{
try
{
try
{
if
(
response
!=
null
)
{
if
(
response
!=
null
)
{
HttpStatus
statusCode
=
response
.
getStatusCode
();
HttpStatus
.
Series
series
=
HttpStatus
.
Series
.
resolve
(
response
.
getRawStatusCode
());
if
(
statusCode
.
is1xxInformational
())
{
if
(
series
!=
null
)
{
return
OUTCOME_INFORMATIONAL
;
return
SERIES_OUTCOMES
.
getOrDefault
(
series
,
OUTCOME_UNKNOWN
);
}
if
(
statusCode
.
is2xxSuccessful
())
{
return
OUTCOME_SUCCESS
;
}
if
(
statusCode
.
is3xxRedirection
())
{
return
OUTCOME_REDIRECTION
;
}
if
(
statusCode
.
is4xxClientError
())
{
return
OUTCOME_CLIENT_ERROR
;
}
if
(
statusCode
.
is5xxServerError
())
{
return
OUTCOME_SERVER_ERROR
;
}
}
}
}
return
OUTCOME_UNKNOWN
;
}
}
catch
(
IOException
|
IllegalArgumentException
ex
)
{
catch
(
IOException
|
IllegalArgumentException
ex
)
{
return
OUTCOME_UNKNOWN
;
// Continue
}
}
return
OUTCOME_UNKNOWN
;
}
}
}
}
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTags.java
View file @
1acff410
...
@@ -140,7 +140,7 @@ public final class WebClientExchangeTags {
...
@@ -140,7 +140,7 @@ public final class WebClientExchangeTags {
/**
/**
* Creates an {@code outcome} {@code Tag} derived from the
* Creates an {@code outcome} {@code Tag} derived from the
* {@link ClientResponse#
s
tatusCode() status} of the given {@code response}.
* {@link ClientResponse#
rawS
tatusCode() status} of the given {@code response}.
* @param response the response
* @param response the response
* @return the outcome tag
* @return the outcome tag
* @since 2.2.0
* @since 2.2.0
...
@@ -154,7 +154,7 @@ public final class WebClientExchangeTags {
...
@@ -154,7 +154,7 @@ public final class WebClientExchangeTags {
}
}
}
}
}
}
catch
(
IllegalArgumentException
ex
c
)
{
catch
(
IllegalArgumentException
ex
)
{
// Continue
// Continue
}
}
return
OUTCOME_UNKNOWN
;
return
OUTCOME_UNKNOWN
;
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTagsTests.java
View file @
1acff410
...
@@ -81,7 +81,7 @@ class RestTemplateExchangeTagsTests {
...
@@ -81,7 +81,7 @@ class RestTemplateExchangeTagsTests {
@Test
@Test
void
outcomeTagIsUnknownWhenResponseThrowsIOException
()
throws
Exception
{
void
outcomeTagIsUnknownWhenResponseThrowsIOException
()
throws
Exception
{
ClientHttpResponse
response
=
mock
(
ClientHttpResponse
.
class
);
ClientHttpResponse
response
=
mock
(
ClientHttpResponse
.
class
);
given
(
response
.
getStatusCode
()).
willThrow
(
IOException
.
class
);
given
(
response
.
get
Raw
StatusCode
()).
willThrow
(
IOException
.
class
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
response
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
response
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"UNKNOWN"
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"UNKNOWN"
);
}
}
...
@@ -89,7 +89,23 @@ class RestTemplateExchangeTagsTests {
...
@@ -89,7 +89,23 @@ class RestTemplateExchangeTagsTests {
@Test
@Test
void
outcomeTagIsUnknownForCustomResponseStatus
()
throws
Exception
{
void
outcomeTagIsUnknownForCustomResponseStatus
()
throws
Exception
{
ClientHttpResponse
response
=
mock
(
ClientHttpResponse
.
class
);
ClientHttpResponse
response
=
mock
(
ClientHttpResponse
.
class
);
given
(
response
.
getStatusCode
()).
willThrow
(
IllegalArgumentException
.
class
);
given
(
response
.
getRawStatusCode
()).
willThrow
(
IllegalArgumentException
.
class
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
response
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"UNKNOWN"
);
}
@Test
void
outcomeTagIsClientErrorWhenResponseIsNonStandardInKnownSeries
()
throws
IOException
{
ClientHttpResponse
response
=
mock
(
ClientHttpResponse
.
class
);
given
(
response
.
getRawStatusCode
()).
willReturn
(
490
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
response
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"CLIENT_ERROR"
);
}
@Test
void
outcomeTagIsUnknownWhenResponseStatusIsInUnknownSeries
()
throws
IOException
{
ClientHttpResponse
response
=
mock
(
ClientHttpResponse
.
class
);
given
(
response
.
getRawStatusCode
()).
willReturn
(
701
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
response
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
response
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"UNKNOWN"
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"UNKNOWN"
);
}
}
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTagsTests.java
View file @
1acff410
...
@@ -148,7 +148,7 @@ class WebClientExchangeTagsTests {
...
@@ -148,7 +148,7 @@ class WebClientExchangeTagsTests {
}
}
@Test
@Test
void
outcomeTagIs
Server
ErrorWhenResponseIsNonStandardInKnownSeries
()
{
void
outcomeTagIs
Client
ErrorWhenResponseIsNonStandardInKnownSeries
()
{
given
(
this
.
response
.
rawStatusCode
()).
willReturn
(
490
);
given
(
this
.
response
.
rawStatusCode
()).
willReturn
(
490
);
Tag
tag
=
WebClientExchangeTags
.
outcome
(
this
.
response
);
Tag
tag
=
WebClientExchangeTags
.
outcome
(
this
.
response
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"CLIENT_ERROR"
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"CLIENT_ERROR"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment