Merge pull request #14886 from Artsiom Yudovin

* gh-14886:
  Polish "Handle StepRegistry connect/read timeout deprecation"
  Handle StepRegistry connect/read timeout deprecation
pull/30512/head
Andy Wilkinson 6 years ago
commit ac9c003a65

@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.appoptics;
import io.micrometer.appoptics.AppOpticsConfig;
import io.micrometer.appoptics.AppOpticsMeterRegistry;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.ipc.http.HttpUrlConnectionSender;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
@ -38,6 +39,7 @@ import org.springframework.context.annotation.Configuration;
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to AppOptics.
*
* @author Stephane Nicoll
* @author Artsiom Yudovin
* @since 2.1.0
*/
@Configuration
@ -50,17 +52,27 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(AppOpticsProperties.class)
public class AppOpticsMetricsExportAutoConfiguration {
private final AppOpticsProperties properties;
public AppOpticsMetricsExportAutoConfiguration(AppOpticsProperties properties) {
this.properties = properties;
}
@Bean
@ConditionalOnMissingBean
public AppOpticsConfig appOpticsConfig(AppOpticsProperties appOpticsProperties) {
return new AppOpticsPropertiesConfigAdapter(appOpticsProperties);
public AppOpticsConfig appOpticsConfig() {
return new AppOpticsPropertiesConfigAdapter(this.properties);
}
@Bean
@ConditionalOnMissingBean
public AppOpticsMeterRegistry appOpticsMeterRegistry(AppOpticsConfig config,
Clock clock) {
return new AppOpticsMeterRegistry(config, clock);
return AppOpticsMeterRegistry.builder(config).clock(clock)
.httpClient(
new HttpUrlConnectionSender(this.properties.getConnectTimeout(),
this.properties.getReadTimeout()))
.build();
}
}

@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.datadog;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.ipc.http.HttpUrlConnectionSender;
import io.micrometer.datadog.DatadogConfig;
import io.micrometer.datadog.DatadogMeterRegistry;
@ -38,6 +39,7 @@ import org.springframework.context.annotation.Configuration;
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Datadog.
*
* @author Jon Schneider
* @author Artsiom Yudovin
* @since 2.0.0
*/
@Configuration
@ -50,17 +52,27 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(DatadogProperties.class)
public class DatadogMetricsExportAutoConfiguration {
private final DatadogProperties properties;
public DatadogMetricsExportAutoConfiguration(DatadogProperties properties) {
this.properties = properties;
}
@Bean
@ConditionalOnMissingBean
public DatadogConfig datadogConfig(DatadogProperties datadogProperties) {
return new DatadogPropertiesConfigAdapter(datadogProperties);
public DatadogConfig datadogConfig() {
return new DatadogPropertiesConfigAdapter(this.properties);
}
@Bean
@ConditionalOnMissingBean
public DatadogMeterRegistry datadogMeterRegistry(DatadogConfig datadogConfig,
Clock clock) {
return new DatadogMeterRegistry(datadogConfig, clock);
return DatadogMeterRegistry.builder(datadogConfig).clock(clock)
.httpClient(
new HttpUrlConnectionSender(this.properties.getConnectTimeout(),
this.properties.getReadTimeout()))
.build();
}
}

@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.dynatrace;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.ipc.http.HttpUrlConnectionSender;
import io.micrometer.dynatrace.DynatraceConfig;
import io.micrometer.dynatrace.DynatraceMeterRegistry;
@ -38,6 +39,7 @@ import org.springframework.context.annotation.Configuration;
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Dynatrace.
*
* @author Andy Wilkinson
* @author Artsiom Yudovin
* @since 2.1.0
*/
@Configuration
@ -50,17 +52,27 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(DynatraceProperties.class)
public class DynatraceMetricsExportAutoConfiguration {
private final DynatraceProperties properties;
public DynatraceMetricsExportAutoConfiguration(DynatraceProperties properties) {
this.properties = properties;
}
@Bean
@ConditionalOnMissingBean
public DynatraceConfig dynatraceConfig(DynatraceProperties dynatraceProperties) {
return new DynatracePropertiesConfigAdapter(dynatraceProperties);
public DynatraceConfig dynatraceConfig() {
return new DynatracePropertiesConfigAdapter(this.properties);
}
@Bean
@ConditionalOnMissingBean
public DynatraceMeterRegistry dynatraceMeterRegistry(DynatraceConfig dynatraceConfig,
Clock clock) {
return new DynatraceMeterRegistry(dynatraceConfig, clock);
return DynatraceMeterRegistry.builder(dynatraceConfig).clock(clock)
.httpClient(
new HttpUrlConnectionSender(this.properties.getConnectTimeout(),
this.properties.getReadTimeout()))
.build();
}
}

@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.elastic;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.ipc.http.HttpUrlConnectionSender;
import io.micrometer.elastic.ElasticConfig;
import io.micrometer.elastic.ElasticMeterRegistry;
@ -38,6 +39,7 @@ import org.springframework.context.annotation.Configuration;
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Elastic.
*
* @author Andy Wilkinson
* @author Artsiom Yudovin
* @since 2.1.0
*/
@Configuration
@ -50,17 +52,27 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(ElasticProperties.class)
public class ElasticMetricsExportAutoConfiguration {
private final ElasticProperties properties;
public ElasticMetricsExportAutoConfiguration(ElasticProperties properties) {
this.properties = properties;
}
@Bean
@ConditionalOnMissingBean
public ElasticConfig elasticConfig(ElasticProperties elasticProperties) {
return new ElasticPropertiesConfigAdapter(elasticProperties);
public ElasticConfig elasticConfig() {
return new ElasticPropertiesConfigAdapter(this.properties);
}
@Bean
@ConditionalOnMissingBean
public ElasticMeterRegistry elasticMeterRegistry(ElasticConfig elasticConfig,
Clock clock) {
return new ElasticMeterRegistry(elasticConfig, clock);
return ElasticMeterRegistry.builder(elasticConfig).clock(clock)
.httpClient(
new HttpUrlConnectionSender(this.properties.getConnectTimeout(),
this.properties.getReadTimeout()))
.build();
}
}

@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.humio;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.ipc.http.HttpUrlConnectionSender;
import io.micrometer.humio.HumioConfig;
import io.micrometer.humio.HumioMeterRegistry;
@ -38,6 +39,7 @@ import org.springframework.context.annotation.Configuration;
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Humio.
*
* @author Andy Wilkinson
* @author Artsiom Yudovin
* @since 2.1.0
*/
@Configuration
@ -50,16 +52,27 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(HumioProperties.class)
public class HumioMetricsExportAutoConfiguration {
private final HumioProperties properties;
public HumioMetricsExportAutoConfiguration(HumioProperties properties) {
this.properties = properties;
}
@Bean
@ConditionalOnMissingBean
public HumioConfig humioConfig(HumioProperties humioProperties) {
return new HumioPropertiesConfigAdapter(humioProperties);
public HumioConfig humioConfig() {
return new HumioPropertiesConfigAdapter(this.properties);
}
@Bean
@ConditionalOnMissingBean
public HumioMeterRegistry humioMeterRegistry(HumioConfig humioConfig, Clock clock) {
return new HumioMeterRegistry(humioConfig, clock);
return HumioMeterRegistry.builder(humioConfig).clock(clock)
.httpClient(
new HttpUrlConnectionSender(this.properties.getConnectTimeout(),
this.properties.getReadTimeout()))
.build();
}
}

@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.influx;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.ipc.http.HttpUrlConnectionSender;
import io.micrometer.influx.InfluxConfig;
import io.micrometer.influx.InfluxMeterRegistry;
@ -38,6 +39,7 @@ import org.springframework.context.annotation.Configuration;
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Influx.
*
* @author Jon Schneider
* @author Artsiom Yudovin
* @since 2.0.0
*/
@Configuration
@ -50,17 +52,28 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(InfluxProperties.class)
public class InfluxMetricsExportAutoConfiguration {
private final InfluxProperties properties;
public InfluxMetricsExportAutoConfiguration(InfluxProperties properties) {
this.properties = properties;
}
@Bean
@ConditionalOnMissingBean
public InfluxConfig influxConfig(InfluxProperties influxProperties) {
return new InfluxPropertiesConfigAdapter(influxProperties);
public InfluxConfig influxConfig() {
return new InfluxPropertiesConfigAdapter(this.properties);
}
@Bean
@ConditionalOnMissingBean
public InfluxMeterRegistry influxMeterRegistry(InfluxConfig influxConfig,
Clock clock) {
return new InfluxMeterRegistry(influxConfig, clock);
public InfluxMeterRegistry influxMeterRegistry(InfluxConfig influxConfig, Clock clock,
InfluxProperties influxProperties) {
return InfluxMeterRegistry.builder(influxConfig).clock(clock)
.httpClient(
new HttpUrlConnectionSender(this.properties.getConnectTimeout(),
this.properties.getReadTimeout()))
.build();
}
}

@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.kairos;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.ipc.http.HttpUrlConnectionSender;
import io.micrometer.kairos.KairosConfig;
import io.micrometer.kairos.KairosMeterRegistry;
@ -38,6 +39,7 @@ import org.springframework.context.annotation.Configuration;
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to KairosDB.
*
* @author Stephane Nicoll
* @author Artsiom Yudovin
* @since 2.1.0
*/
@Configuration
@ -50,17 +52,28 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(KairosProperties.class)
public class KairosMetricsExportAutoConfiguration {
private final KairosProperties properties;
public KairosMetricsExportAutoConfiguration(KairosProperties properties) {
this.properties = properties;
}
@Bean
@ConditionalOnMissingBean
public KairosConfig kairosConfig(KairosProperties kairosProperties) {
return new KairosPropertiesConfigAdapter(kairosProperties);
public KairosConfig kairosConfig() {
return new KairosPropertiesConfigAdapter(this.properties);
}
@Bean
@ConditionalOnMissingBean
public KairosMeterRegistry kairosMeterRegistry(KairosConfig kairosConfig,
Clock clock) {
return new KairosMeterRegistry(kairosConfig, clock);
return KairosMeterRegistry.builder(kairosConfig).clock(clock)
.httpClient(
new HttpUrlConnectionSender(this.properties.getConnectTimeout(),
this.properties.getReadTimeout()))
.build();
}
}

@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.ipc.http.HttpUrlConnectionSender;
import io.micrometer.newrelic.NewRelicConfig;
import io.micrometer.newrelic.NewRelicMeterRegistry;
@ -39,6 +40,7 @@ import org.springframework.context.annotation.Configuration;
*
* @author Jon Schneider
* @author Andy Wilkinson
* @author Artsiom Yudovin
* @since 2.0.0
*/
@Configuration
@ -51,17 +53,28 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(NewRelicProperties.class)
public class NewRelicMetricsExportAutoConfiguration {
private final NewRelicProperties properties;
public NewRelicMetricsExportAutoConfiguration(NewRelicProperties properties) {
this.properties = properties;
}
@Bean
@ConditionalOnMissingBean
public NewRelicConfig newRelicConfig(NewRelicProperties props) {
return new NewRelicPropertiesConfigAdapter(props);
public NewRelicConfig newRelicConfig() {
return new NewRelicPropertiesConfigAdapter(this.properties);
}
@Bean
@ConditionalOnMissingBean
public NewRelicMeterRegistry newRelicMeterRegistry(NewRelicConfig newRelicConfig,
Clock clock) {
return new NewRelicMeterRegistry(newRelicConfig, clock);
return NewRelicMeterRegistry.builder(newRelicConfig).clock(clock)
.httpClient(
new HttpUrlConnectionSender(this.properties.getConnectTimeout(),
this.properties.getReadTimeout()))
.build();
}
}

@ -26,6 +26,7 @@ import io.micrometer.core.instrument.step.StepRegistryConfig;
* @param <T> the properties type
* @author Jon Schneider
* @author Phillip Webb
* @author Artsiom Yudovin
* @since 2.0.0
*/
public abstract class StepRegistryPropertiesConfigAdapter<T extends StepRegistryProperties>
@ -55,16 +56,6 @@ public abstract class StepRegistryPropertiesConfigAdapter<T extends StepRegistry
return get(T::isEnabled, StepRegistryConfig.super::enabled);
}
@Override
public Duration connectTimeout() {
return get(T::getConnectTimeout, StepRegistryConfig.super::connectTimeout);
}
@Override
public Duration readTimeout() {
return get(T::getReadTimeout, StepRegistryConfig.super::readTimeout);
}
@Override
public int numThreads() {
return get(T::getNumThreads, StepRegistryConfig.super::numThreads);

@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.ipc.http.HttpUrlConnectionSender;
import io.micrometer.wavefront.WavefrontConfig;
import io.micrometer.wavefront.WavefrontMeterRegistry;
@ -38,6 +39,7 @@ import org.springframework.context.annotation.Configuration;
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Wavefront.
*
* @author Jon Schneider
* @author Artsiom Yudovin
* @since 2.0.0
*/
@Configuration
@ -50,17 +52,27 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(WavefrontProperties.class)
public class WavefrontMetricsExportAutoConfiguration {
private final WavefrontProperties properties;
public WavefrontMetricsExportAutoConfiguration(WavefrontProperties properties) {
this.properties = properties;
}
@Bean
@ConditionalOnMissingBean
public WavefrontConfig wavefrontConfig(WavefrontProperties props) {
return new WavefrontPropertiesConfigAdapter(props);
public WavefrontConfig wavefrontConfig() {
return new WavefrontPropertiesConfigAdapter(this.properties);
}
@Bean
@ConditionalOnMissingBean
public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig wavefrontConfig,
Clock clock) {
return new WavefrontMeterRegistry(wavefrontConfig, clock);
return WavefrontMeterRegistry.builder(wavefrontConfig).clock(clock)
.httpClient(
new HttpUrlConnectionSender(this.properties.getConnectTimeout(),
this.properties.getReadTimeout()))
.build();
}
}

@ -16,7 +16,6 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.humio;
import java.time.Duration;
import java.util.Collections;
import org.junit.Test;
@ -38,14 +37,6 @@ public class HumioPropertiesConfigAdapterTests {
.isEqualTo("ABC123");
}
@Test
public void whenPropertiesConnectTimeoutIsSetAdapterConnectTimeoutReturnsIt() {
HumioProperties properties = new HumioProperties();
properties.setConnectTimeout(Duration.ofSeconds(10));
assertThat(new HumioPropertiesConfigAdapter(properties).connectTimeout())
.isEqualTo(Duration.ofSeconds(10));
}
@Test
public void whenPropertiesRepositoryIsSetAdapterRepositoryReturnsIt() {
HumioProperties properties = new HumioProperties();

@ -28,6 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @param <P> properties used by the tests
* @param <A> adapter used by the tests
* @author Stephane Nicoll
* @author Artsiom Yudovin
*/
public abstract class StepRegistryPropertiesConfigAdapterTests<P extends StepRegistryProperties, A extends StepRegistryPropertiesConfigAdapter<P>> {
@ -50,22 +51,6 @@ public abstract class StepRegistryPropertiesConfigAdapterTests<P extends StepReg
assertThat(createConfigAdapter(properties).enabled()).isFalse();
}
@Test
public void whenPropertiesConnectTimeoutIsSetAdapterConnectTimeoutReturnsIt() {
P properties = createProperties();
properties.setConnectTimeout(Duration.ofMinutes(42));
assertThat(createConfigAdapter(properties).connectTimeout())
.isEqualTo(Duration.ofMinutes(42));
}
@Test
public void whenPropertiesReadTimeoutIsSetAdapterReadTimeoutReturnsIt() {
P properties = createProperties();
properties.setReadTimeout(Duration.ofMillis(42));
assertThat(createConfigAdapter(properties).readTimeout())
.isEqualTo(Duration.ofMillis(42));
}
@Test
public void whenPropertiesNumThreadsIsSetAdapterNumThreadsReturnsIt() {
P properties = createProperties();

Loading…
Cancel
Save