Commit 713e6b84 by Spencer Gibb

Merge pull request #639 from jkschneider/metrics-aop-fix

* metrics-aop-fix: RestTemplate metrics collection join point now returns a value
parents 024d9946 be140748
...@@ -39,13 +39,13 @@ public class MetricsInterceptorConfiguration { ...@@ -39,13 +39,13 @@ public class MetricsInterceptorConfiguration {
@ConditionalOnWebApplication @ConditionalOnWebApplication
static class MetricsWebResourceConfiguration extends WebMvcConfigurerAdapter { static class MetricsWebResourceConfiguration extends WebMvcConfigurerAdapter {
@Bean @Bean
MetricsHandlerInterceptor spectatorMonitoringWebResourceInterceptor() { MetricsHandlerInterceptor servoMonitoringWebResourceInterceptor() {
return new MetricsHandlerInterceptor(); return new MetricsHandlerInterceptor();
} }
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(spectatorMonitoringWebResourceInterceptor()); registry.addInterceptor(servoMonitoringWebResourceInterceptor());
} }
} }
......
...@@ -26,11 +26,11 @@ import org.aspectj.lang.annotation.Aspect; ...@@ -26,11 +26,11 @@ import org.aspectj.lang.annotation.Aspect;
@Aspect @Aspect
public class RestTemplateUrlTemplateCapturingAspect { public class RestTemplateUrlTemplateCapturingAspect {
@Around("execution(* org.springframework.web.client.RestOperations+.*(String, ..))") @Around("execution(* org.springframework.web.client.RestOperations+.*(String, ..))")
void captureUrlTemplate(ProceedingJoinPoint joinPoint) throws Throwable { Object captureUrlTemplate(ProceedingJoinPoint joinPoint) throws Throwable {
try { try {
String urlTemplate = (String) joinPoint.getArgs()[0]; String urlTemplate = (String) joinPoint.getArgs()[0];
RestTemplateUrlTemplateHolder.setRestTemplateUrlTemplate(urlTemplate); RestTemplateUrlTemplateHolder.setRestTemplateUrlTemplate(urlTemplate);
joinPoint.proceed(); return joinPoint.proceed();
} }
finally { finally {
RestTemplateUrlTemplateHolder.clear(); RestTemplateUrlTemplateHolder.clear();
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
package org.springframework.cloud.netflix.metrics; package org.springframework.cloud.netflix.metrics;
import org.junit.Assert; import static org.junit.Assert.assertEquals;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -62,8 +63,8 @@ public class MetricsClientHttpRequestInterceptorTests { ...@@ -62,8 +63,8 @@ public class MetricsClientHttpRequestInterceptorTests {
MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate); MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
mockServer.expect(MockRestRequestMatchers.requestTo("/test/123")) mockServer.expect(MockRestRequestMatchers.requestTo("/test/123"))
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) .andExpect(MockRestRequestMatchers.method(HttpMethod.GET))
.andRespond(MockRestResponseCreators.withSuccess("{\"status\" : \"OK\"}", MediaType.APPLICATION_JSON)); .andRespond(MockRestResponseCreators.withSuccess("OK", MediaType.APPLICATION_JSON));
restTemplate.getForObject("/test/{id}", String.class, 123); String s = restTemplate.getForObject("/test/{id}", String.class, 123);
MonitorConfig.Builder builder = new MonitorConfig.Builder("metricName") MonitorConfig.Builder builder = new MonitorConfig.Builder("metricName")
.withTag("method", "GET") .withTag("method", "GET")
...@@ -73,7 +74,9 @@ public class MetricsClientHttpRequestInterceptorTests { ...@@ -73,7 +74,9 @@ public class MetricsClientHttpRequestInterceptorTests {
BasicTimer timer = servoMonitorCache.getTimer(builder.build()); BasicTimer timer = servoMonitorCache.getTimer(builder.build());
Assert.assertEquals(1L, (long) timer.getCount()); assertEquals(1L, (long) timer.getCount());
assertEquals("OK", s);
mockServer.verify(); mockServer.verify();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment