From 22192c2b5cd56c45802526ec7190e945143dc980 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 12 Feb 2019 14:35:38 +0000 Subject: [PATCH] Polish "Make auto-config of RestTemplate metrics back off with no builder bean" Closes gh-15842 --- .../HttpClientMetricsAutoConfiguration.java | 3 ++- .../RestTemplateMetricsConfiguration.java | 2 +- ...RestTemplateMetricsConfigurationTests.java | 22 +++++++++---------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/HttpClientMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/HttpClientMetricsAutoConfiguration.java index dc3bc65e0d..b536805b0e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/HttpClientMetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/HttpClientMetricsAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -39,6 +39,7 @@ import org.springframework.core.annotation.Order; * @author Jon Schneider * @author Phillip Webb * @author Stephane Nicoll + * @author Raheela Aslam * @since 2.1.0 */ @Configuration diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfiguration.java index 67c6bac04c..1ae7929704 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfiguration.java @@ -35,7 +35,7 @@ import org.springframework.web.client.RestTemplate; * * @author Jon Schneider * @author Phillip Webb - * @author raheela.aslam + * @author Raheela Aslam */ @Configuration @ConditionalOnClass(RestTemplate.class) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfigurationTests.java index c73e5aaf94..8808478f96 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfigurationTests.java @@ -42,7 +42,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat * * @author Stephane Nicoll * @author Jon Schneider - * @author raheela.aslam + * @author Raheela Aslam */ public class RestTemplateMetricsConfigurationTests { @@ -100,6 +100,16 @@ public class RestTemplateMetricsConfigurationTests { }); } + @Test + public void backsOffWhenRestTemplateBuilderIsMissing() { + new ApplicationContextRunner().with(MetricsRun.simple()) + .withConfiguration( + AutoConfigurations.of(HttpClientMetricsAutoConfiguration.class)) + .run((context) -> assertThat(context) + .doesNotHaveBean(DefaultRestTemplateExchangeTagsProvider.class) + .doesNotHaveBean(MetricsRestTemplateCustomizer.class)); + } + private MeterRegistry getInitializedMeterRegistry( AssertableApplicationContext context) { MeterRegistry registry = context.getBean(MeterRegistry.class); @@ -133,14 +143,4 @@ public class RestTemplateMetricsConfigurationTests { return restTemplate; } - @Test - public void backsOffWhenRestTemplateBuilderIsMissing() { - new ApplicationContextRunner().with(MetricsRun.simple()) - .withConfiguration( - AutoConfigurations.of(HttpClientMetricsAutoConfiguration.class)) - .run((context) -> assertThat(context) - .doesNotHaveBean(DefaultRestTemplateExchangeTagsProvider.class) - .doesNotHaveBean(MetricsRestTemplateCustomizer.class)); - } - }