Polish "Stop time web metrics when autotime is disabled"

See gh-19981
This commit is contained in:
Stephane Nicoll 2020-02-04 09:58:11 +01:00
parent e323e05eea
commit 10643b7702
3 changed files with 14 additions and 13 deletions

View File

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -49,7 +49,7 @@ public class TestController {
@Timed
@GetMapping("test3")
public String test3() {
return "test2";
return "test3";
}
}

View File

@ -71,8 +71,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@ExtendWith(OutputCaptureExtension.class)
class WebMvcMetricsAutoConfigurationTests {
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner().with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(WebMvcMetricsAutoConfiguration.class));
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.with(MetricsRun.simple()).withConfiguration(AutoConfigurations.of(WebMvcMetricsAutoConfiguration.class));
@Test
void backsOffWhenMeterRegistryIsMissing() {
@ -183,11 +183,12 @@ class WebMvcMetricsAutoConfigurationTests {
.contains(LongTaskTimingHandlerInterceptor.class));
}
private MeterRegistry getInitializedMeterRegistry(AssertableWebApplicationContext context) throws Exception {
return getInitializedMeterRegistry(context, "/test0", "/test1", "/test2");
}
private MeterRegistry getInitializedMeterRegistry(AssertableWebApplicationContext context, String... urls)
throws Exception {
if (urls.length == 0) {
urls = new String[] { "/test0", "/test1", "/test2" };
}
assertThat(context).hasSingleBean(FilterRegistrationBean.class);
Filter filter = context.getBean(FilterRegistrationBean.class).getFilter();
assertThat(filter).isInstanceOf(WebMvcMetricsFilter.class);

View File

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -144,11 +144,11 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter {
Builder builder = this.autoTimer.builder(this.metricName);
timerSample.stop(getTimer(builder, handler, request, response, exception));
}
return;
}
for (Timed annotation : annotations) {
Builder builder = Timer.builder(annotation, this.metricName);
timerSample.stop(getTimer(builder, handler, request, response, exception));
} else {
for (Timed annotation : annotations) {
Builder builder = Timer.builder(annotation, this.metricName);
timerSample.stop(getTimer(builder, handler, request, response, exception));
}
}
}