Merge pull request #15842 from Raheela Aslam

* gh-15842:
  Polish "Make auto-config of RestTemplate metrics back off with no builder bean"
  Make auto-config of RestTemplate metrics back off with no builder bean

Closes gh-15842
pull/15937/head
Andy Wilkinson 6 years ago
commit fc67e4472c

@ -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.
@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@ -38,11 +39,12 @@ import org.springframework.core.annotation.Order;
* @author Jon Schneider
* @author Phillip Webb
* @author Stephane Nicoll
* @author Raheela Aslam
* @since 2.1.0
*/
@Configuration
@AutoConfigureAfter({ MetricsAutoConfiguration.class,
SimpleMetricsExportAutoConfiguration.class })
SimpleMetricsExportAutoConfiguration.class, RestTemplateAutoConfiguration.class })
@ConditionalOnClass(MeterRegistry.class)
@ConditionalOnBean(MeterRegistry.class)
@Import({ RestTemplateMetricsConfiguration.class, WebClientMetricsConfiguration.class })

@ -22,8 +22,10 @@ import org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties;
import org.springframework.boot.actuate.metrics.web.client.DefaultRestTemplateExchangeTagsProvider;
import org.springframework.boot.actuate.metrics.web.client.MetricsRestTemplateCustomizer;
import org.springframework.boot.actuate.metrics.web.client.RestTemplateExchangeTagsProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@ -33,9 +35,11 @@ import org.springframework.web.client.RestTemplate;
*
* @author Jon Schneider
* @author Phillip Webb
* @author Raheela Aslam
*/
@Configuration
@ConditionalOnClass(RestTemplate.class)
@ConditionalOnBean(RestTemplateBuilder.class)
class RestTemplateMetricsConfiguration {
private final MetricsProperties properties;

@ -21,6 +21,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
import org.springframework.boot.actuate.metrics.web.client.DefaultRestTemplateExchangeTagsProvider;
import org.springframework.boot.actuate.metrics.web.client.MetricsRestTemplateCustomizer;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
@ -41,6 +42,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
*
* @author Stephane Nicoll
* @author Jon Schneider
* @author Raheela Aslam
*/
public class RestTemplateMetricsConfigurationTests {
@ -98,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);

Loading…
Cancel
Save