Commit a12bab45 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Fix PropertiesConfigAdapter delegation logic"

Closes gh-11135
parent 9163d65b
......@@ -26,6 +26,7 @@ import org.springframework.util.Assert;
*
* @param <T> The properties type
* @author Phillip Webb
* @author Nikolay Rybak
* @since 2.0.0
*/
public class PropertiesConfigAdapter<T> {
......
......@@ -60,17 +60,20 @@ class GangliaPropertiesConfigAdapter
@Override
public TimeUnit durationUnits() {
return get(GangliaProperties::getDurationUnits, GangliaConfig.super::durationUnits);
return get(GangliaProperties::getDurationUnits,
GangliaConfig.super::durationUnits);
}
@Override
public String protocolVersion() {
return get(GangliaProperties::getProtocolVersion, GangliaConfig.super::protocolVersion);
return get(GangliaProperties::getProtocolVersion,
GangliaConfig.super::protocolVersion);
}
@Override
public GMetric.UDPAddressingMode addressingMode() {
return get(GangliaProperties::getAddressingMode, GangliaConfig.super::addressingMode);
return get(GangliaProperties::getAddressingMode,
GangliaConfig.super::addressingMode);
}
@Override
......
......@@ -60,7 +60,8 @@ class GraphitePropertiesConfigAdapter
@Override
public TimeUnit durationUnits() {
return get(GraphiteProperties::getDurationUnits, GraphiteConfig.super::durationUnits);
return get(GraphiteProperties::getDurationUnits,
GraphiteConfig.super::durationUnits);
}
@Override
......
......@@ -57,7 +57,8 @@ class InfluxPropertiesConfigAdapter
@Override
public String retentionPolicy() {
return get(InfluxProperties::getRetentionPolicy, InfluxConfig.super::retentionPolicy);
return get(InfluxProperties::getRetentionPolicy,
InfluxConfig.super::retentionPolicy);
}
@Override
......
......@@ -43,7 +43,8 @@ class PrometheusPropertiesConfigAdapter
@Override
public boolean descriptions() {
return get(PrometheusProperties::getDescriptions, PrometheusConfig.super::descriptions);
return get(PrometheusProperties::getDescriptions,
PrometheusConfig.super::descriptions);
}
@Override
......
......@@ -63,12 +63,14 @@ public class StatsdPropertiesConfigAdapter extends
@Override
public int maxPacketLength() {
return get(StatsdProperties::getMaxPacketLength, StatsdConfig.super::maxPacketLength);
return get(StatsdProperties::getMaxPacketLength,
StatsdConfig.super::maxPacketLength);
}
@Override
public Duration pollingFrequency() {
return get(StatsdProperties::getPollingFrequency, StatsdConfig.super::pollingFrequency);
return get(StatsdProperties::getPollingFrequency,
StatsdConfig.super::pollingFrequency);
}
@Override
......
......@@ -16,49 +16,32 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.datadog;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
import io.micrometer.datadog.DatadogMeterRegistry;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link DatadogExportConfiguration}.
* Tests for {@link DatadogPropertiesConfigAdapter}.
*
* @author Nikolay Rybak
* @author Stephane Nicoll
*/
@RunWith(SpringRunner.class)
public class DatadogExportConfigurationTests {
public class DatadogPropertiesConfigAdapterTests {
@Test
public void apiKeyInferUri() {
DatadogProperties properties = new DatadogProperties();
properties.setApiKey("my-key");
assertThat(new DatadogPropertiesConfigAdapter(properties).uri())
.contains("?api_key=my-key");
}
/**
* Validated that {@link DatadogMeterRegistry} can be started by only specifying Datadog API key.
*/
@Test
public void datadogMeterRegistryIsConfiguredWithApiKeyOnly() {
new ApplicationContextRunner()
.withPropertyValues("spring.metrics.export.atlas.enabled=false",
"spring.metrics.export.datadog.enabled=true",
"spring.metrics.export.ganglia.enabled=false",
"spring.metrics.export.graphite.enabled=false",
"spring.metrics.export.influx.enabled=false",
"spring.metrics.export.jmx.enabled=false",
"spring.metrics.export.prometheus.enabled=false",
"spring.metrics.export.statsd.enabled=false",
"spring.metrics.export.datadog.api-key=APIKEY")
.withConfiguration(AutoConfigurations.of(MetricsAutoConfiguration.class))
.run((context) -> {
CompositeMeterRegistry meterRegistry = context
.getBean(CompositeMeterRegistry.class);
assertThat(meterRegistry.getRegistries()).hasSize(1);
assertThat(meterRegistry.getRegistries())
.hasOnlyElementsOfType(DatadogMeterRegistry.class);
});
public void uriCanBeSet() {
DatadogProperties properties = new DatadogProperties();
properties.setUri("https://app.example.com/api/v1/series");
properties.setApiKey("my-key");
assertThat(new DatadogPropertiesConfigAdapter(properties).uri())
.isEqualTo("https://app.example.com/api/v1/series");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment