Skip to content

Commit 10643b7

Browse files
committed
Polish "Stop time web metrics when autotime is disabled"
See gh-19981
1 parent e323e05 commit 10643b7

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/TestController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,7 +49,7 @@ public String test2() {
4949
@Timed
5050
@GetMapping("test3")
5151
public String test3() {
52-
return "test2";
52+
return "test3";
5353
}
5454

5555
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfigurationTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
@ExtendWith(OutputCaptureExtension.class)
7272
class WebMvcMetricsAutoConfigurationTests {
7373

74-
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner().with(MetricsRun.simple())
75-
.withConfiguration(AutoConfigurations.of(WebMvcMetricsAutoConfiguration.class));
74+
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
75+
.with(MetricsRun.simple()).withConfiguration(AutoConfigurations.of(WebMvcMetricsAutoConfiguration.class));
7676

7777
@Test
7878
void backsOffWhenMeterRegistryIsMissing() {
@@ -183,11 +183,12 @@ void longTaskTimingInterceptorIsRegistered() {
183183
.contains(LongTaskTimingHandlerInterceptor.class));
184184
}
185185

186+
private MeterRegistry getInitializedMeterRegistry(AssertableWebApplicationContext context) throws Exception {
187+
return getInitializedMeterRegistry(context, "/test0", "/test1", "/test2");
188+
}
189+
186190
private MeterRegistry getInitializedMeterRegistry(AssertableWebApplicationContext context, String... urls)
187191
throws Exception {
188-
if (urls.length == 0) {
189-
urls = new String[] { "/test0", "/test1", "/test2" };
190-
}
191192
assertThat(context).hasSingleBean(FilterRegistrationBean.class);
192193
Filter filter = context.getBean(FilterRegistrationBean.class).getFilter();
193194
assertThat(filter).isInstanceOf(WebMvcMetricsFilter.class);

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -144,11 +144,11 @@ private void record(TimingContext timingContext, HttpServletRequest request, Htt
144144
Builder builder = this.autoTimer.builder(this.metricName);
145145
timerSample.stop(getTimer(builder, handler, request, response, exception));
146146
}
147-
return;
148-
}
149-
for (Timed annotation : annotations) {
150-
Builder builder = Timer.builder(annotation, this.metricName);
151-
timerSample.stop(getTimer(builder, handler, request, response, exception));
147+
} else {
148+
for (Timed annotation : annotations) {
149+
Builder builder = Timer.builder(annotation, this.metricName);
150+
timerSample.stop(getTimer(builder, handler, request, response, exception));
151+
}
152152
}
153153
}
154154

0 commit comments

Comments
 (0)