Polish "Stop time web metrics when autotime is disabled"

See gh-19981
pull/20222/head
Stephane Nicoll 5 years ago
parent e323e05eea
commit 10643b7702

@ -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";
}
}

@ -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);

@ -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));
}
}
}

Loading…
Cancel
Save