Commit 10643b77 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Stop time web metrics when autotime is disabled"

See gh-19981
parent e323e05e
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -49,7 +49,7 @@ public class TestController { ...@@ -49,7 +49,7 @@ public class TestController {
@Timed @Timed
@GetMapping("test3") @GetMapping("test3")
public String test3() { public String test3() {
return "test2"; return "test3";
} }
} }
...@@ -71,8 +71,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. ...@@ -71,8 +71,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@ExtendWith(OutputCaptureExtension.class) @ExtendWith(OutputCaptureExtension.class)
class WebMvcMetricsAutoConfigurationTests { class WebMvcMetricsAutoConfigurationTests {
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner().with(MetricsRun.simple()) private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(WebMvcMetricsAutoConfiguration.class)); .with(MetricsRun.simple()).withConfiguration(AutoConfigurations.of(WebMvcMetricsAutoConfiguration.class));
@Test @Test
void backsOffWhenMeterRegistryIsMissing() { void backsOffWhenMeterRegistryIsMissing() {
...@@ -183,11 +183,12 @@ class WebMvcMetricsAutoConfigurationTests { ...@@ -183,11 +183,12 @@ class WebMvcMetricsAutoConfigurationTests {
.contains(LongTaskTimingHandlerInterceptor.class)); .contains(LongTaskTimingHandlerInterceptor.class));
} }
private MeterRegistry getInitializedMeterRegistry(AssertableWebApplicationContext context) throws Exception {
return getInitializedMeterRegistry(context, "/test0", "/test1", "/test2");
}
private MeterRegistry getInitializedMeterRegistry(AssertableWebApplicationContext context, String... urls) private MeterRegistry getInitializedMeterRegistry(AssertableWebApplicationContext context, String... urls)
throws Exception { throws Exception {
if (urls.length == 0) {
urls = new String[] { "/test0", "/test1", "/test2" };
}
assertThat(context).hasSingleBean(FilterRegistrationBean.class); assertThat(context).hasSingleBean(FilterRegistrationBean.class);
Filter filter = context.getBean(FilterRegistrationBean.class).getFilter(); Filter filter = context.getBean(FilterRegistrationBean.class).getFilter();
assertThat(filter).isInstanceOf(WebMvcMetricsFilter.class); assertThat(filter).isInstanceOf(WebMvcMetricsFilter.class);
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -144,11 +144,11 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter { ...@@ -144,11 +144,11 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter {
Builder builder = this.autoTimer.builder(this.metricName); Builder builder = this.autoTimer.builder(this.metricName);
timerSample.stop(getTimer(builder, handler, request, response, exception)); timerSample.stop(getTimer(builder, handler, request, response, exception));
} }
return; } else {
} for (Timed annotation : annotations) {
for (Timed annotation : annotations) { Builder builder = Timer.builder(annotation, this.metricName);
Builder builder = Timer.builder(annotation, this.metricName); timerSample.stop(getTimer(builder, handler, request, response, exception));
timerSample.stop(getTimer(builder, handler, request, response, exception)); }
} }
} }
......
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