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
36e4c7cf
Commit
36e4c7cf
authored
Nov 12, 2015
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make metrics aspect conditional on Spring AOP
Also changes pointcut to use the interface so you don't need proxyTargetClass=true. Fixes gh-636
parent
ef5785bf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
8 deletions
+22
-8
MetricsInterceptorConfiguration.java
...loud/netflix/metrics/MetricsInterceptorConfiguration.java
+18
-4
RestTemplateUrlTemplateCapturingAspect.java
...tflix/metrics/RestTemplateUrlTemplateCapturingAspect.java
+4
-4
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/metrics/MetricsInterceptorConfiguration.java
View file @
36e4c7cf
...
@@ -13,10 +13,12 @@
...
@@ -13,10 +13,12 @@
package
org
.
springframework
.
cloud
.
netflix
.
metrics
;
package
org
.
springframework
.
cloud
.
netflix
.
metrics
;
import
org.aspectj.lang.JoinPoint
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.boot.actuate.metrics.reader.MetricReader
;
import
org.springframework.boot.actuate.metrics.reader.MetricReader
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -47,13 +49,22 @@ public class MetricsInterceptorConfiguration {
...
@@ -47,13 +49,22 @@ public class MetricsInterceptorConfiguration {
}
}
@Configuration
@Configuration
@ConditionalOnClass
(
JoinPoint
.
class
)
@ConditionalOnProperty
(
value
=
"spring.aop.enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
@ConditionalOnBean
({
RestTemplate
.
class
})
@ConditionalOnBean
({
RestTemplate
.
class
})
static
class
MetricsRestTemplateConfiguration
{
static
class
MetricsRestTemplateAspectConfiguration
{
@Bean
@Bean
RestTemplateUrlTemplateCapturingAspect
restTemplateUrlTemplateCapturingAspect
()
{
RestTemplateUrlTemplateCapturingAspect
restTemplateUrlTemplateCapturingAspect
()
{
return
new
RestTemplateUrlTemplateCapturingAspect
();
return
new
RestTemplateUrlTemplateCapturingAspect
();
}
}
}
@Configuration
@ConditionalOnBean
({
RestTemplate
.
class
})
static
class
MetricsRestTemplateConfiguration
{
@Bean
@Bean
MetricsClientHttpRequestInterceptor
spectatorLoggingClientHttpRequestInterceptor
()
{
MetricsClientHttpRequestInterceptor
spectatorLoggingClientHttpRequestInterceptor
()
{
return
new
MetricsClientHttpRequestInterceptor
();
return
new
MetricsClientHttpRequestInterceptor
();
...
@@ -64,14 +75,17 @@ public class MetricsInterceptorConfiguration {
...
@@ -64,14 +75,17 @@ public class MetricsInterceptorConfiguration {
final
MetricsClientHttpRequestInterceptor
interceptor
)
{
final
MetricsClientHttpRequestInterceptor
interceptor
)
{
return
new
BeanPostProcessor
()
{
return
new
BeanPostProcessor
()
{
@Override
@Override
public
Object
postProcessBeforeInitialization
(
Object
bean
,
String
beanName
)
{
public
Object
postProcessBeforeInitialization
(
Object
bean
,
String
beanName
)
{
return
bean
;
return
bean
;
}
}
@Override
@Override
public
Object
postProcessAfterInitialization
(
Object
bean
,
String
beanName
)
{
public
Object
postProcessAfterInitialization
(
Object
bean
,
if
(
bean
instanceof
RestTemplate
)
String
beanName
)
{
if
(
bean
instanceof
RestTemplate
)
{
((
RestTemplate
)
bean
).
getInterceptors
().
add
(
interceptor
);
((
RestTemplate
)
bean
).
getInterceptors
().
add
(
interceptor
);
}
return
bean
;
return
bean
;
}
}
};
};
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/metrics/RestTemplateUrlTemplateCapturingAspect.java
View file @
36e4c7cf
/*
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2015 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* specific language governing permissions and limitations under the License.
...
@@ -25,7 +25,7 @@ import org.aspectj.lang.annotation.Aspect;
...
@@ -25,7 +25,7 @@ import org.aspectj.lang.annotation.Aspect;
*/
*/
@Aspect
@Aspect
public
class
RestTemplateUrlTemplateCapturingAspect
{
public
class
RestTemplateUrlTemplateCapturingAspect
{
@Around
(
"execution(* org.springframework.web.client.Rest
Template
.*(String, ..))"
)
@Around
(
"execution(* org.springframework.web.client.Rest
Operations+
.*(String, ..))"
)
void
captureUrlTemplate
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
void
captureUrlTemplate
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
try
{
try
{
String
urlTemplate
=
(
String
)
joinPoint
.
getArgs
()[
0
];
String
urlTemplate
=
(
String
)
joinPoint
.
getArgs
()[
0
];
...
...
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