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
d5ae59da
Commit
d5ae59da
authored
Jan 08, 2019
by
Brian Clozel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
Closes gh-15594
parent
21df40b6
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
81 additions
and
44 deletions
+81
-44
DefaultRestTemplateExchangeTagsProvider.java
...s/web/client/DefaultRestTemplateExchangeTagsProvider.java
+1
-1
RestTemplateExchangeTags.java
.../actuate/metrics/web/client/RestTemplateExchangeTags.java
+23
-21
DefaultWebClientExchangeTagsProvider.java
...reactive/client/DefaultWebClientExchangeTagsProvider.java
+1
-1
WebClientExchangeTags.java
...te/metrics/web/reactive/client/WebClientExchangeTags.java
+11
-6
RestTemplateExchangeTagsTests.java
...ate/metrics/web/client/RestTemplateExchangeTagsTests.java
+36
-13
DefaultWebClientExchangeTagsProviderTests.java
...ive/client/DefaultWebClientExchangeTagsProviderTests.java
+1
-1
WebClientExchangeTagsTests.java
...trics/web/reactive/client/WebClientExchangeTagsTests.java
+8
-1
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/client/DefaultRestTemplateExchangeTagsProvider.java
View file @
d5ae59da
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTags.java
View file @
d5ae59da
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -35,6 +35,7 @@ import org.springframework.web.client.RestTemplate;
...
@@ -35,6 +35,7 @@ import org.springframework.web.client.RestTemplate;
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Jon Schneider
* @author Jon Schneider
* @author Nishant Raut
* @author Nishant Raut
* @author Brian Clozel
* @since 2.0.0
* @since 2.0.0
*/
*/
public
final
class
RestTemplateExchangeTags
{
public
final
class
RestTemplateExchangeTags
{
...
@@ -137,36 +138,37 @@ public final class RestTemplateExchangeTags {
...
@@ -137,36 +138,37 @@ public final class RestTemplateExchangeTags {
* @since 2.2.0
* @since 2.2.0
*/
*/
public
static
Tag
outcome
(
ClientHttpResponse
response
)
{
public
static
Tag
outcome
(
ClientHttpResponse
response
)
{
if
(
response
!=
null
)
{
HttpStatus
status
=
extractStatus
(
response
);
HttpStatus
status
=
extractStatus
(
response
);
if
(
status
!=
null
)
{
if
(
status
!=
null
)
{
if
(
status
.
is1xxInformational
())
{
if
(
status
.
is1xxInformational
())
{
return
OUTCOME_INFORMATIONAL
;
return
OUTCOME_INFORMATIONAL
;
}
}
if
(
status
.
is2xxSuccessful
())
{
if
(
status
.
is2xxSuccessful
())
{
return
OUTCOME_SUCCESS
;
return
OUTCOME_SUCCESS
;
}
}
if
(
status
.
is3xxRedirection
())
{
if
(
status
.
is3xxRedirection
())
{
return
OUTCOME_REDIRECTION
;
return
OUTCOME_REDIRECTION
;
}
}
if
(
status
.
is4xxClientError
())
{
if
(
status
.
is4xxClientError
())
{
return
OUTCOME_CLIENT_ERROR
;
return
OUTCOME_CLIENT_ERROR
;
}
}
if
(
status
.
is5xxServerError
())
{
return
OUTCOME_SERVER_ERROR
;
}
}
return
OUTCOME_SERVER_ERROR
;
}
}
return
OUTCOME_UNKNOWN
;
return
OUTCOME_UNKNOWN
;
}
}
private
static
HttpStatus
extractStatus
(
ClientHttpResponse
response
)
{
private
static
HttpStatus
extractStatus
(
ClientHttpResponse
response
)
{
try
{
try
{
return
response
.
getStatusCode
();
if
(
response
!=
null
)
{
return
response
.
getStatusCode
();
}
return
null
;
}
}
catch
(
IOException
ex
)
{
catch
(
IOException
|
IllegalArgumentException
exc
)
{
return
null
;
return
null
;
}
}
}
}
}
}
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProvider.java
View file @
d5ae59da
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTags.java
View file @
d5ae59da
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -133,9 +133,9 @@ public final class WebClientExchangeTags {
...
@@ -133,9 +133,9 @@ public final class WebClientExchangeTags {
* @since 2.2.0
* @since 2.2.0
*/
*/
public
static
Tag
outcome
(
ClientResponse
response
)
{
public
static
Tag
outcome
(
ClientResponse
response
)
{
if
(
response
!=
null
)
{
try
{
HttpStatus
status
=
response
.
statusCode
();
if
(
response
!=
null
)
{
if
(
status
!=
null
)
{
HttpStatus
status
=
response
.
statusCode
();
if
(
status
.
is1xxInformational
())
{
if
(
status
.
is1xxInformational
())
{
return
OUTCOME_INFORMATIONAL
;
return
OUTCOME_INFORMATIONAL
;
}
}
...
@@ -148,10 +148,15 @@ public final class WebClientExchangeTags {
...
@@ -148,10 +148,15 @@ public final class WebClientExchangeTags {
if
(
status
.
is4xxClientError
())
{
if
(
status
.
is4xxClientError
())
{
return
OUTCOME_CLIENT_ERROR
;
return
OUTCOME_CLIENT_ERROR
;
}
}
if
(
status
.
is5xxServerError
())
{
return
OUTCOME_SERVER_ERROR
;
}
}
}
return
OUTCOME_SERVER_ERROR
;
return
OUTCOME_UNKNOWN
;
}
catch
(
IllegalArgumentException
exc
)
{
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 @
d5ae59da
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -16,23 +16,28 @@
...
@@ -16,23 +16,28 @@
package
org
.
springframework
.
boot
.
actuate
.
metrics
.
web
.
client
;
package
org
.
springframework
.
boot
.
actuate
.
metrics
.
web
.
client
;
import
java.io.IOException
;
import
io.micrometer.core.instrument.Tag
;
import
io.micrometer.core.instrument.Tag
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.mock.http.client.MockClientHttpResponse
;
import
org.springframework.mock.http.client.MockClientHttpResponse
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
/**
* Tests for {@link RestTemplateExchangeTags}.
* Tests for {@link RestTemplateExchangeTags}.
*
*
* @author Nishant Raut
* @author Nishant Raut
* @author Brian Clozel
* @author Brian Clozel
*/
*/
public
class
RestTemplateExchangeTagsTests
{
public
class
RestTemplateExchangeTagsTests
{
private
MockClientHttpResponse
response
;
@Test
@Test
public
void
outcomeTagIsUnknownWhenResponseStatusIsNull
()
{
public
void
outcomeTagIsUnknownWhenResponseStatusIsNull
()
{
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
null
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
null
);
...
@@ -41,40 +46,58 @@ public class RestTemplateExchangeTagsTests {
...
@@ -41,40 +46,58 @@ public class RestTemplateExchangeTagsTests {
@Test
@Test
public
void
outcomeTagIsInformationalWhenResponseIs1xx
()
{
public
void
outcomeTagIsInformationalWhenResponseIs1xx
()
{
this
.
response
=
new
MockClientHttpResponse
(
"foo"
.
getBytes
(),
HttpStatus
.
CONTINUE
);
ClientHttpResponse
response
=
new
MockClientHttpResponse
(
"foo"
.
getBytes
(),
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
this
.
response
);
HttpStatus
.
CONTINUE
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
response
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"INFORMATIONAL"
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"INFORMATIONAL"
);
}
}
@Test
@Test
public
void
outcomeTagIsSuccessWhenResponseIs2xx
()
{
public
void
outcomeTagIsSuccessWhenResponseIs2xx
()
{
this
.
response
=
new
MockClientHttpResponse
(
"foo"
.
getBytes
(),
HttpStatus
.
OK
);
ClientHttpResponse
response
=
new
MockClientHttpResponse
(
"foo"
.
getBytes
(),
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
this
.
response
);
HttpStatus
.
OK
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
response
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"SUCCESS"
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"SUCCESS"
);
}
}
@Test
@Test
public
void
outcomeTagIsRedirectionWhenResponseIs3xx
()
{
public
void
outcomeTagIsRedirectionWhenResponseIs3xx
()
{
this
.
response
=
new
MockClientHttpResponse
(
"foo"
.
getBytes
(),
ClientHttpResponse
response
=
new
MockClientHttpResponse
(
"foo"
.
getBytes
(),
HttpStatus
.
MOVED_PERMANENTLY
);
HttpStatus
.
MOVED_PERMANENTLY
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
this
.
response
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
response
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"REDIRECTION"
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"REDIRECTION"
);
}
}
@Test
@Test
public
void
outcomeTagIsClientErrorWhenResponseIs4xx
()
{
public
void
outcomeTagIsClientErrorWhenResponseIs4xx
()
{
this
.
response
=
new
MockClientHttpResponse
(
"foo"
.
getBytes
(),
ClientHttpResponse
response
=
new
MockClientHttpResponse
(
"foo"
.
getBytes
(),
HttpStatus
.
BAD_REQUEST
);
HttpStatus
.
BAD_REQUEST
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
this
.
response
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
response
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"CLIENT_ERROR"
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"CLIENT_ERROR"
);
}
}
@Test
@Test
public
void
outcomeTagIsServerErrorWhenResponseIs5xx
()
{
public
void
outcomeTagIsServerErrorWhenResponseIs5xx
()
{
this
.
response
=
new
MockClientHttpResponse
(
"foo"
.
getBytes
(),
ClientHttpResponse
response
=
new
MockClientHttpResponse
(
"foo"
.
getBytes
(),
HttpStatus
.
BAD_GATEWAY
);
HttpStatus
.
BAD_GATEWAY
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
this
.
response
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
response
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"SERVER_ERROR"
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"SERVER_ERROR"
);
}
}
@Test
public
void
outcomeTagIsUnknownWhenResponseThrowsIOException
()
throws
Exception
{
ClientHttpResponse
response
=
mock
(
ClientHttpResponse
.
class
);
given
(
response
.
getStatusCode
()).
willThrow
(
IOException
.
class
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
response
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"UNKNOWN"
);
}
@Test
public
void
outcomeTagIsUnknownForCustomResponseStatus
()
throws
Exception
{
ClientHttpResponse
response
=
mock
(
ClientHttpResponse
.
class
);
given
(
response
.
getStatusCode
()).
willThrow
(
IllegalArgumentException
.
class
);
Tag
tag
=
RestTemplateExchangeTags
.
outcome
(
response
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"UNKNOWN"
);
}
}
}
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProviderTests.java
View file @
d5ae59da
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTagsTests.java
View file @
d5ae59da
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -155,4 +155,11 @@ public class WebClientExchangeTagsTests {
...
@@ -155,4 +155,11 @@ public class WebClientExchangeTagsTests {
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"SERVER_ERROR"
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"SERVER_ERROR"
);
}
}
@Test
public
void
outcomeTagIsUknownWhenResponseStatusIsUknown
()
{
given
(
this
.
response
.
statusCode
()).
willThrow
(
IllegalArgumentException
.
class
);
Tag
tag
=
WebClientExchangeTags
.
outcome
(
this
.
response
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"UNKNOWN"
);
}
}
}
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