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
6819922d
Unverified
Commit
6819922d
authored
Aug 29, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix MetricsTagProvider for non web apps.
Guard creating and creation of classes that use it with @ConditionalOnClass(name = "javax.servlet.http.HttpServletRequest") fixes gh-1302
parent
ec726e86
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
16 deletions
+35
-16
MetricsClientHttpRequestInterceptor.java
.../netflix/metrics/MetricsClientHttpRequestInterceptor.java
+17
-14
MetricsInterceptorConfiguration.java
...loud/netflix/metrics/MetricsInterceptorConfiguration.java
+14
-2
ServoMetricsAutoConfiguration.java
.../netflix/metrics/servo/ServoMetricsAutoConfiguration.java
+4
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/metrics/MetricsClientHttpRequestInterceptor.java
View file @
6819922d
...
...
@@ -18,8 +18,6 @@ import java.util.Collection;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cloud.netflix.metrics.servo.ServoMonitorCache
;
import
org.springframework.http.HttpRequest
;
import
org.springframework.http.client.ClientHttpRequestExecution
;
...
...
@@ -43,17 +41,22 @@ public class MetricsClientHttpRequestInterceptor implements ClientHttpRequestInt
* Boot (Actuator) provides a more general purpose abstraction for dimensional metrics
* systems, this can be moved there and rewritten against that abstraction.
*/
@Autowired
MonitorRegistry
registry
;
private
final
MonitorRegistry
registry
;
@Autowired
Collection
<
MetricsTagProvider
>
tagProviders
;
private
final
Collection
<
MetricsTagProvider
>
tagProviders
;
@Autowired
ServoMonitorCache
servoMonitorCache
;
private
final
ServoMonitorCache
servoMonitorCache
;
@Value
(
"${netflix.metrics.restClient.metricName:restclient}"
)
String
metricName
;
private
final
String
metricName
;
public
MetricsClientHttpRequestInterceptor
(
MonitorRegistry
registry
,
Collection
<
MetricsTagProvider
>
tagProviders
,
ServoMonitorCache
servoMonitorCache
,
String
metricName
)
{
this
.
registry
=
registry
;
this
.
tagProviders
=
tagProviders
;
this
.
servoMonitorCache
=
servoMonitorCache
;
this
.
metricName
=
metricName
;
}
@Override
public
ClientHttpResponse
intercept
(
HttpRequest
request
,
byte
[]
body
,
...
...
@@ -68,8 +71,8 @@ public class MetricsClientHttpRequestInterceptor implements ClientHttpRequestInt
finally
{
SmallTagMap
.
Builder
builder
=
SmallTagMap
.
builder
();
for
(
MetricsTagProvider
tagProvider
:
tagProviders
)
{
for
(
Map
.
Entry
<
String
,
String
>
tag
:
tagProvider
.
clientHttpRequestTags
(
request
,
response
).
entrySet
())
{
for
(
Map
.
Entry
<
String
,
String
>
tag
:
tagProvider
.
clientHttpRequestTags
(
request
,
response
).
entrySet
())
{
builder
.
add
(
Tags
.
newTag
(
tag
.
getKey
(),
tag
.
getValue
()));
}
}
...
...
@@ -78,8 +81,8 @@ public class MetricsClientHttpRequestInterceptor implements ClientHttpRequestInt
.
builder
(
metricName
);
monitorConfigBuilder
.
withTags
(
builder
);
servoMonitorCache
.
getTimer
(
monitorConfigBuilder
.
build
())
.
record
(
System
.
nanoTime
()
-
startTime
,
TimeUnit
.
NANOSECONDS
);
servoMonitorCache
.
getTimer
(
monitorConfigBuilder
.
build
())
.
record
(
System
.
nanoTime
()
-
startTime
,
TimeUnit
.
NANOSECONDS
);
}
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/metrics/MetricsInterceptorConfiguration.java
View file @
6819922d
...
...
@@ -15,14 +15,17 @@ package org.springframework.cloud.netflix.metrics;
import
java.util.ArrayList
;
import
com.netflix.servo.MonitorRegistry
;
import
org.aspectj.lang.JoinPoint
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.boot.actuate.metrics.reader.MetricReader
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.cloud.netflix.metrics.servo.ServoMonitorCache
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -34,6 +37,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
import
com.netflix.servo.monitor.Monitors
;
import
java.util.Collection
;
/**
* @author Jon Schneider
*/
...
...
@@ -71,11 +76,18 @@ public class MetricsInterceptorConfiguration {
@Configuration
@ConditionalOnBean
({
RestTemplate
.
class
})
@ConditionalOnClass
(
name
=
"javax.servlet.http.HttpServletRequest"
)
static
class
MetricsRestTemplateConfiguration
{
@Value
(
"${netflix.metrics.restClient.metricName:restclient}"
)
String
metricName
;
@Bean
MetricsClientHttpRequestInterceptor
spectatorLoggingClientHttpRequestInterceptor
()
{
return
new
MetricsClientHttpRequestInterceptor
();
MetricsClientHttpRequestInterceptor
spectatorLoggingClientHttpRequestInterceptor
(
MonitorRegistry
registry
,
Collection
<
MetricsTagProvider
>
tagProviders
,
ServoMonitorCache
servoMonitorCache
)
{
return
new
MetricsClientHttpRequestInterceptor
(
registry
,
tagProviders
,
servoMonitorCache
,
this
.
metricName
);
}
@Bean
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/metrics/servo/ServoMetricsAutoConfiguration.java
View file @
6819922d
...
...
@@ -95,8 +95,12 @@ public class ServoMetricsAutoConfiguration {
return
new
ServoMetricServices
(
monitorRegistry
);
}
@Configuration
@ConditionalOnClass
(
name
=
"javax.servlet.http.HttpServletRequest"
)
protected
static
class
MetricsTagConfiguration
{
@Bean
public
MetricsTagProvider
defaultMetricsTagProvider
()
{
return
new
DefaultMetricsTagProvider
();
}
}
}
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