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 {
@ConditionalOnWebApplication
static class MetricsWebResourceConfiguration extends WebMvcConfigurerAdapter {
@Bean
MetricsHandlerInterceptor spectatorMonitoringWebResourceInterceptor() {
MetricsHandlerInterceptor servoMonitoringWebResourceInterceptor() {
return new MetricsHandlerInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(spectatorMonitoringWebResourceInterceptor());
registry.addInterceptor(servoMonitoringWebResourceInterceptor());
}
}
......
......@@ -26,11 +26,11 @@ import org.aspectj.lang.annotation.Aspect;
@Aspect
public class RestTemplateUrlTemplateCapturingAspect {
@Around("execution(* org.springframework.web.client.RestOperations+.*(String, ..))")
void captureUrlTemplate(ProceedingJoinPoint joinPoint) throws Throwable {
Object captureUrlTemplate(ProceedingJoinPoint joinPoint) throws Throwable {
try {
String urlTemplate = (String) joinPoint.getArgs()[0];
RestTemplateUrlTemplateHolder.setRestTemplateUrlTemplate(urlTemplate);
joinPoint.proceed();
return joinPoint.proceed();
}
finally {
RestTemplateUrlTemplateHolder.clear();
......
......@@ -13,7 +13,8 @@
package org.springframework.cloud.netflix.metrics;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -62,8 +63,8 @@ public class MetricsClientHttpRequestInterceptorTests {
MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
mockServer.expect(MockRestRequestMatchers.requestTo("/test/123"))
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET))
.andRespond(MockRestResponseCreators.withSuccess("{\"status\" : \"OK\"}", MediaType.APPLICATION_JSON));
restTemplate.getForObject("/test/{id}", String.class, 123);
.andRespond(MockRestResponseCreators.withSuccess("OK", MediaType.APPLICATION_JSON));
String s = restTemplate.getForObject("/test/{id}", String.class, 123);
MonitorConfig.Builder builder = new MonitorConfig.Builder("metricName")
.withTag("method", "GET")
......@@ -73,7 +74,9 @@ public class MetricsClientHttpRequestInterceptorTests {
BasicTimer timer = servoMonitorCache.getTimer(builder.build());
Assert.assertEquals(1L, (long) timer.getCount());
assertEquals(1L, (long) timer.getCount());
assertEquals("OK", s);
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