Skip to content

Commit 8c14009

Browse files
committed
Fix key to disable the metrics filter
Commit d0cf6b5 introduced a `endpoints.metrics.filter.enabled` property key meant to disable the filter. Unfortunately, the `endpoints.metrics` namespace is already managed so setting this property will fail. We now use the same key than the one used to disable the metrics endpoint. Closes gh-4365
1 parent 791e304 commit 8c14009

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
@ConditionalOnClass({ Servlet.class, ServletRegistration.class,
4747
OncePerRequestFilter.class, HandlerMapping.class })
4848
@AutoConfigureAfter(MetricRepositoryAutoConfiguration.class)
49-
@ConditionalOnProperty(name = "endpoints.metrics.filter.enabled", matchIfMissing = true)
49+
@ConditionalOnProperty(name = "endpoints.metrics.enabled", matchIfMissing = true)
5050
public class MetricFilterAutoConfiguration {
5151

5252
@Autowired

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import org.springframework.boot.actuate.metrics.CounterService;
3333
import org.springframework.boot.actuate.metrics.GaugeService;
34+
import org.springframework.boot.test.EnvironmentTestUtils;
3435
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3536
import org.springframework.context.annotation.Bean;
3637
import org.springframework.context.annotation.Configuration;
@@ -77,6 +78,7 @@
7778
*
7879
* @author Phillip Webb
7980
* @author Andy Wilkinson
81+
* @@author Stephane Nicoll
8082
*/
8183
public class MetricFilterAutoConfigurationTests {
8284

@@ -175,6 +177,16 @@ public void skipsFilterIfMissingServices() throws Exception {
175177
context.close();
176178
}
177179

180+
@Test
181+
public void skipsFilterIfPropertyDisabled() throws Exception {
182+
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
183+
EnvironmentTestUtils.addEnvironment(context, "endpoints.metrics.enabled:false");
184+
context.register(Config.class, MetricFilterAutoConfiguration.class);
185+
context.refresh();
186+
assertThat(context.getBeansOfType(Filter.class).size(), equalTo(0));
187+
context.close();
188+
}
189+
178190
@Test
179191
public void controllerMethodThatThrowsUnhandledException() throws Exception {
180192
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(

0 commit comments

Comments
 (0)