Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
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
openSource
spring-cloud-netflix
Commits
82d8a110
Commit
82d8a110
authored
Jan 31, 2016
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Defensive coding to avoid potential NPE
Fixes gh-803
parent
2e9ff4c7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
8 deletions
+15
-8
DefaultMetricsTagProvider.java
...work/cloud/netflix/metrics/DefaultMetricsTagProvider.java
+15
-8
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/metrics/DefaultMetricsTagProvider.java
View file @
82d8a110
...
@@ -16,6 +16,7 @@ package org.springframework.cloud.netflix.metrics;
...
@@ -16,6 +16,7 @@ package org.springframework.cloud.netflix.metrics;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
...
@@ -33,13 +34,14 @@ public class DefaultMetricsTagProvider implements MetricsTagProvider {
...
@@ -33,13 +34,14 @@ public class DefaultMetricsTagProvider implements MetricsTagProvider {
public
Map
<
String
,
String
>
clientHttpRequestTags
(
HttpRequest
request
,
public
Map
<
String
,
String
>
clientHttpRequestTags
(
HttpRequest
request
,
ClientHttpResponse
response
)
{
ClientHttpResponse
response
)
{
String
urlTemplate
=
RestTemplateUrlTemplateHolder
.
getRestTemplateUrlTemplate
();
String
urlTemplate
=
RestTemplateUrlTemplateHolder
.
getRestTemplateUrlTemplate
();
if
(
urlTemplate
==
null
)
if
(
urlTemplate
==
null
)
{
urlTemplate
=
"none"
;
urlTemplate
=
"none"
;
}
String
status
;
String
status
;
try
{
try
{
status
=
(
response
==
null
)
?
"CLIENT_ERROR"
:
((
Integer
)
response
status
=
(
response
==
null
)
?
"CLIENT_ERROR"
.
getRawStatusCode
()).
toString
();
:
((
Integer
)
response
.
getRawStatusCode
()).
toString
();
}
}
catch
(
IOException
e
)
{
catch
(
IOException
e
)
{
status
=
"IO_ERROR"
;
status
=
"IO_ERROR"
;
...
@@ -60,17 +62,22 @@ public class DefaultMetricsTagProvider implements MetricsTagProvider {
...
@@ -60,17 +62,22 @@ public class DefaultMetricsTagProvider implements MetricsTagProvider {
tags
.
put
(
"method"
,
request
.
getMethod
());
tags
.
put
(
"method"
,
request
.
getMethod
());
tags
.
put
(
"status"
,
((
Integer
)
response
.
getStatus
()).
toString
());
tags
.
put
(
"status"
,
((
Integer
)
response
.
getStatus
()).
toString
());
String
uri
=
sanitizeUrlTemplate
(
request
String
uri
=
(
String
)
request
.
getAttribute
(
HandlerMapping
.
BEST_MATCHING_PATTERN_ATTRIBUTE
).
toString
()
.
getAttribute
(
HandlerMapping
.
BEST_MATCHING_PATTERN_ATTRIBUTE
);
.
substring
(
1
));
if
(
uri
==
null
)
{
uri
=
request
.
getPathInfo
();
}
uri
=
sanitizeUrlTemplate
(
uri
.
substring
(
1
));
tags
.
put
(
"uri"
,
uri
.
isEmpty
()
?
"root"
:
uri
);
tags
.
put
(
"uri"
,
uri
.
isEmpty
()
?
"root"
:
uri
);
Object
exception
=
request
.
getAttribute
(
"exception"
);
Object
exception
=
request
.
getAttribute
(
"exception"
);
if
(
exception
!=
null
)
if
(
exception
!=
null
)
{
tags
.
put
(
"exception"
,
exception
.
getClass
().
getSimpleName
());
tags
.
put
(
"exception"
,
exception
.
getClass
().
getSimpleName
());
}
if
(
caller
!=
null
)
if
(
caller
!=
null
)
{
tags
.
put
(
"caller"
,
caller
);
tags
.
put
(
"caller"
,
caller
);
}
return
tags
;
return
tags
;
}
}
...
...
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