diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/PropertiesConfigAdapter.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/PropertiesConfigAdapter.java new file mode 100644 index 00000000000..0c49ae258d6 --- /dev/null +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/PropertiesConfigAdapter.java @@ -0,0 +1,61 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.metrics.export; + +import java.util.function.Function; + +import org.springframework.util.Assert; + +/** + * Base class for properties to config adapters. + * + * @param The properties type + * @param The config type + * @author Phillip Webb + * @since 2.0.0 + */ +public class PropertiesConfigAdapter { + + private T properties; + + private C defaults; + + /** + * Create a new {@link PropertiesConfigAdapter} instance. + * @param properties the source properties + * @param defaults a config implementation providing default values + */ + public PropertiesConfigAdapter(T properties, C defaults) { + Assert.notNull(properties, "Properties must not be null"); + Assert.notNull(defaults, "Defaults must not be null"); + this.properties = properties; + this.defaults = defaults; + } + + /** + * Get the value from the properties or use a fallback from the {@code defaults}. + * @param getter the getter for the properties + * @param fallback the fallback method from the {@code defaults} + * @param the value type + * @return the property or fallback value + */ + protected final V get(Function getter, Function fallback) { + V value = getter.apply(this.properties); + return (value != null ? value : fallback.apply(this.defaults)); + } + +} diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/RegistryProperties.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/RegistryProperties.java deleted file mode 100644 index f2c36c57df8..00000000000 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/RegistryProperties.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2012-2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.metrics.export; - -import java.util.Properties; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * Base {@link ConfigurationProperties} class for configuring a metrics registry. - * - * @author Jon Schneider - * @author Andy Wilkinson - * @since 2.0.0 - */ -public abstract class RegistryProperties { - - private final Properties properties = new Properties(); - - protected abstract String prefix(); - - public String get(String key) { - return this.properties.getProperty(key); - } - - protected void set(String key, Object value) { - this.properties.put(prefix() + "." + key, value.toString()); - } - -} diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/StepRegistryProperties.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/StepRegistryProperties.java index bce50de53ae..2a56b1fe5a1 100644 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/StepRegistryProperties.java +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/StepRegistryProperties.java @@ -18,41 +18,93 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export; import java.time.Duration; -import io.micrometer.core.instrument.spectator.step.StepRegistryConfig; - /** - * Specialization of {@link RegistryProperties} for configuring a metrics registry that - * pushes aggregated metrics on a regular interval. + * Base class for properties that configure a metrics registry that pushes aggregated + * metrics on a regular interval. * * @author Jon Schneider * @author Andy Wilkinson * @since 2.0.0 */ -public abstract class StepRegistryProperties extends RegistryProperties - implements StepRegistryConfig { +public abstract class StepRegistryProperties { + + /** + * The step size (reporting frequency) to use. + */ + private Duration step = Duration.ofMinutes(1); + + /** + * Enable publishing to the backend. + */ + private Boolean enabled = true; + + /** + * The connection timeout for requests to the backend. + */ + private Duration connectTimeout; + + /** + * The read timeout for requests to the backend. + */ + private Duration readTimeout; + + /** + * The number of threads to use with the metrics publishing scheduler. + */ + private Integer numThreads; + + /** + * The number of measurements per request to use for the backend. If more measurements + * are found, then multiple requests will be made. + */ + private Integer batchSize; + + public Duration getStep() { + return this.step; + } public void setStep(Duration step) { - set("step", step); + this.step = step; + } + + public Boolean getEnabled() { + return this.enabled; } public void setEnabled(Boolean enabled) { - set("enabled", enabled); + this.enabled = enabled; } - public void setBatchSize(Integer batchSize) { - set("batchSize", batchSize); + public Duration getConnectTimeout() { + return this.connectTimeout; } public void setConnectTimeout(Duration connectTimeout) { - set("connectTimeout", connectTimeout); + this.connectTimeout = connectTimeout; + } + + public Duration getReadTimeout() { + return this.readTimeout; } public void setReadTimeout(Duration readTimeout) { - set("readTimeout", readTimeout); + this.readTimeout = readTimeout; + } + + public Integer getNumThreads() { + return this.numThreads; } public void setNumThreads(Integer numThreads) { - set("numThreads", numThreads); + this.numThreads = numThreads; + } + + public Integer getBatchSize() { + return this.batchSize; + } + + public void setBatchSize(Integer batchSize) { + this.batchSize = batchSize; } } diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/StepRegistryPropertiesConfigAdapter.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/StepRegistryPropertiesConfigAdapter.java new file mode 100644 index 00000000000..cf2fde0bdac --- /dev/null +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/StepRegistryPropertiesConfigAdapter.java @@ -0,0 +1,79 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.metrics.export; + +import java.time.Duration; + +import io.micrometer.core.instrument.spectator.step.StepRegistryConfig; + +/** + * Base class for {@link StepRegistryProperties} to {@link StepRegistryConfig} adapters. + * + * @param The properties type + * @param The config type + * @author Jon Schneider + * @author Phillip Webb + * @since 2.0.0 + */ +public abstract class StepRegistryPropertiesConfigAdapter + extends PropertiesConfigAdapter implements StepRegistryConfig { + + public StepRegistryPropertiesConfigAdapter(T properties, C defaults) { + super(properties, defaults); + } + + @Override + public String prefix() { + return null; + } + + @Override + public String get(String k) { + return null; + } + + @Override + public Duration step() { + return get(T::getStep, C::step); + } + + @Override + public boolean enabled() { + return get(T::getEnabled, C::enabled); + } + + @Override + public Duration connectTimeout() { + return get(T::getConnectTimeout, C::connectTimeout); + } + + @Override + public Duration readTimeout() { + return get(T::getReadTimeout, C::readTimeout); + } + + @Override + public int numThreads() { + return get(T::getNumThreads, C::numThreads); + } + + @Override + public int batchSize() { + return get(T::getBatchSize, C::batchSize); + } + +} diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasExportConfiguration.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasExportConfiguration.java index 3055a6b1f79..cb085acc034 100644 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasExportConfiguration.java +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasExportConfiguration.java @@ -43,10 +43,16 @@ import org.springframework.context.annotation.Import; @EnableConfigurationProperties(AtlasProperties.class) public class AtlasExportConfiguration { + @Bean + @ConditionalOnMissingBean(AtlasConfig.class) + public AtlasConfig atlasConfig(AtlasProperties atlasProperties) { + return new AtlasPropertiesConfigAdapter(atlasProperties); + } + @Bean @ConditionalOnProperty(value = "spring.metrics.atlas.enabled", matchIfMissing = true) - public MetricsExporter atlasExporter(AtlasConfig config, Clock clock) { - return () -> new AtlasMeterRegistry(config, clock); + public MetricsExporter atlasExporter(AtlasConfig atlasConfig, Clock clock) { + return () -> new AtlasMeterRegistry(atlasConfig, clock); } @Bean diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasProperties.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasProperties.java index ac50a96b57f..a8a48093bb5 100644 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasProperties.java +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasProperties.java @@ -18,9 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.atlas; import java.time.Duration; -import com.netflix.spectator.atlas.AtlasConfig; - -import org.springframework.boot.actuate.autoconfigure.metrics.export.RegistryProperties; +import org.springframework.boot.actuate.autoconfigure.metrics.export.StepRegistryProperties; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -30,63 +28,97 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Jon Schneider */ @ConfigurationProperties(prefix = "spring.metrics.atlas") -public class AtlasProperties extends RegistryProperties implements AtlasConfig { +public class AtlasProperties extends StepRegistryProperties { - @Override - protected String prefix() { - return "spring.metrics.atlas"; - } + /** + * The URI for the Atlas backend. + */ + private String uri; - public void setStep(Duration step) { - set("step", step); - } + /** + * The TTL for meters that do not have any activity. After this period the meter will + * be considered expired and will not get reported. + */ + private Duration meterTimeToLive; - public void setMeterTTL(Duration meterTTL) { - set("meterTTL", meterTTL); - } + /** + * Enable streaming to Atlas LWC. + */ + private Boolean lwcEnabled; - public void setEnabled(Boolean enabled) { - set("enabled", enabled); - } + /** + * The frequency for refreshing config settings from the LWC service. + */ + private Duration configRefreshFrequency; - public void setNumThreads(Integer numThreads) { - set("numThreads", numThreads); + /** + * The TTL for subscriptions from the LWC service. + */ + private Duration configTimeToLive; + + /** + * The URI for the Atlas LWC endpoint to retrieve current subscriptions. + */ + private String configUri; + + /** + * The URI for the Atlas LWC endpoint to evaluate the data for a subscription. + */ + private String evalUri; + + public String getUri() { + return this.uri; } public void setUri(String uri) { - set("uri", uri); + this.uri = uri; } - public void setLwcEnabled(boolean lwcEnabled) { - set("lwcEnabled", lwcEnabled); + public Duration getMeterTimeToLive() { + return this.meterTimeToLive; + } + + public void setMeterTimeToLive(Duration meterTimeToLive) { + this.meterTimeToLive = meterTimeToLive; + } + + public Boolean getLwcEnabled() { + return this.lwcEnabled; + } + + public void setLwcEnabled(Boolean lwcEnabled) { + this.lwcEnabled = lwcEnabled; + } + + public Duration getConfigRefreshFrequency() { + return this.configRefreshFrequency; } public void setConfigRefreshFrequency(Duration configRefreshFrequency) { - set("configRefreshFrequency", configRefreshFrequency); + this.configRefreshFrequency = configRefreshFrequency; } - public void setConfigTTL(Duration configTTL) { - set("configTTL", configTTL); + public Duration getConfigTimeToLive() { + return this.configTimeToLive; + } + + public void setConfigTimeToLive(Duration configTimeToLive) { + this.configTimeToLive = configTimeToLive; + } + + public String getConfigUri() { + return this.configUri; } public void setConfigUri(String configUri) { - set("configUri", configUri); + this.configUri = configUri; + } + + public String getEvalUri() { + return this.evalUri; } public void setEvalUri(String evalUri) { - set("evalUri", evalUri); + this.evalUri = evalUri; } - - public void setConnectTimeout(Duration connectTimeout) { - set("connectTimeout", connectTimeout); - } - - public void setReadTimeout(Duration readTimeout) { - set("readTimeout", readTimeout); - } - - public void setBatchSize(Integer batchSize) { - set("batchSize", batchSize); - } - } diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapter.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapter.java new file mode 100644 index 00000000000..3af61642060 --- /dev/null +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapter.java @@ -0,0 +1,111 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.metrics.export.atlas; + +import java.time.Duration; + +import com.netflix.spectator.atlas.AtlasConfig; + +import org.springframework.boot.actuate.autoconfigure.metrics.export.PropertiesConfigAdapter; + +/** + * Adapter to convert {@link AtlasProperties} to an {@link AtlasConfig}. + * + * @author Jon Schneider + * @author Phillip Webb + */ +class AtlasPropertiesConfigAdapter extends + PropertiesConfigAdapter implements AtlasConfig { + + private static final AtlasConfig DEFAUTLS = (k) -> null; + + AtlasPropertiesConfigAdapter(AtlasProperties properties) { + super(properties, DEFAUTLS); + } + + @Override + public String get(String key) { + return null; + } + + @Override + public Duration step() { + return get(AtlasProperties::getStep, AtlasConfig::step); + } + + @Override + public boolean enabled() { + return get(AtlasProperties::getEnabled, AtlasConfig::enabled); + } + + @Override + public Duration connectTimeout() { + return get(AtlasProperties::getConnectTimeout, AtlasConfig::connectTimeout); + } + + @Override + public Duration readTimeout() { + return get(AtlasProperties::getReadTimeout, AtlasConfig::readTimeout); + } + + @Override + public int numThreads() { + return get(AtlasProperties::getNumThreads, AtlasConfig::numThreads); + } + + @Override + public int batchSize() { + return get(AtlasProperties::getBatchSize, AtlasConfig::batchSize); + } + + @Override + public String uri() { + return get(AtlasProperties::getUri, AtlasConfig::uri); + } + + @Override + public Duration meterTTL() { + return get(AtlasProperties::getMeterTimeToLive, AtlasConfig::meterTTL); + } + + @Override + public boolean lwcEnabled() { + return get(AtlasProperties::getLwcEnabled, AtlasConfig::lwcEnabled); + } + + @Override + public Duration configRefreshFrequency() { + return get(AtlasProperties::getConfigRefreshFrequency, + AtlasConfig::configRefreshFrequency); + } + + @Override + public Duration configTTL() { + return get(AtlasProperties::getConfigTimeToLive, AtlasConfig::configTTL); + } + + @Override + public String configUri() { + return get(AtlasProperties::getConfigUri, AtlasConfig::configUri); + } + + @Override + public String evalUri() { + return get(AtlasProperties::getEvalUri, AtlasConfig::evalUri); + } + +} diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogExportConfiguration.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogExportConfiguration.java index 661b7754184..fb705332216 100644 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogExportConfiguration.java +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogExportConfiguration.java @@ -38,14 +38,21 @@ import org.springframework.context.annotation.Import; */ @Configuration @ConditionalOnClass(DatadogMeterRegistry.class) +@ConditionalOnProperty("spring.metrics.datadog.api-key") @Import(StringToDurationConverter.class) @EnableConfigurationProperties(DatadogProperties.class) public class DatadogExportConfiguration { + @Bean + @ConditionalOnMissingBean + public DatadogConfig datadogConfig(DatadogProperties datadogProperties) { + return new DatadogPropertiesConfigAdapter(datadogProperties); + } + @Bean @ConditionalOnProperty(value = "spring.metrics.datadog.enabled", matchIfMissing = true) - public MetricsExporter datadogExporter(DatadogConfig config, Clock clock) { - return () -> new DatadogMeterRegistry(config, clock); + public MetricsExporter datadogExporter(DatadogConfig datadogConfig, Clock clock) { + return () -> new DatadogMeterRegistry(datadogConfig, clock); } @Bean diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java index 244d2b52a99..9c944301311 100644 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java @@ -16,7 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.datadog; -import io.micrometer.datadog.DatadogConfig; +import java.time.Duration; import org.springframework.boot.actuate.autoconfigure.metrics.export.StepRegistryProperties; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -28,23 +28,63 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @since 2.0.0 */ @ConfigurationProperties(prefix = "spring.metrics.datadog") -public class DatadogProperties extends StepRegistryProperties implements DatadogConfig { +public class DatadogProperties extends StepRegistryProperties { - @Override - public String prefix() { - return "spring.metrics.datadog"; - } + /** + * Your API key, found in your account settings at datadoghq. This property is + * required. + */ + private String apiKey; - public DatadogProperties() { - set("apiKey", "dummyKey"); // FIXME otherwise tests fail + /** + * The tag that will be mapped to "host" when shipping metrics to datadog, or + * {@code null} if host should be omitted on publishing. + */ + private String hostTag; + + /** + * The bucket filter clamping the bucket domain of timer percentiles histograms to + * some max value. This is used to limit the number of buckets shipped to Prometheus + * to save on storage. + */ + private Duration timerPercentilesMax = Duration.ofMinutes(2); + + /** + * The bucket filter clamping the bucket domain of timer percentiles histograms to + * some min value. This is used to limit the number of buckets shipped to Prometheus + * to save on storage. + */ + private Duration timerPercentilesMin = Duration.ofMillis(10); + + public String getApiKey() { + return this.apiKey; } public void setApiKey(String apiKey) { - set("apiKey", apiKey); + this.apiKey = apiKey; } - public void setHostTag(String hostTag) { - set("hostTag", hostTag); + public String getHostTag() { + return this.hostTag; } + public void setHostKey(String hostKey) { + this.hostTag = hostKey; + } + + public Duration getTimerPercentilesMax() { + return this.timerPercentilesMax; + } + + public void setTimerPercentilesMax(Duration timerPercentilesMax) { + this.timerPercentilesMax = timerPercentilesMax; + } + + public Duration getTimerPercentilesMin() { + return this.timerPercentilesMin; + } + + public void setTimerPercentilesMin(Duration timerPercentilesMin) { + this.timerPercentilesMin = timerPercentilesMin; + } } diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapter.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapter.java new file mode 100644 index 00000000000..6066810d981 --- /dev/null +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapter.java @@ -0,0 +1,63 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.metrics.export.datadog; + +import java.time.Duration; + +import io.micrometer.datadog.DatadogConfig; + +import org.springframework.boot.actuate.autoconfigure.metrics.export.StepRegistryPropertiesConfigAdapter; + +/** + * Adapter to convert {@link DatadogProperties} to a {@link DatadogConfig}. + * + * @author Jon Schneider + * @author Phillip Webb + */ +class DatadogPropertiesConfigAdapter + extends StepRegistryPropertiesConfigAdapter + implements DatadogConfig { + + private static final DatadogConfig DEFAULTS = (k) -> null; + + DatadogPropertiesConfigAdapter(DatadogProperties properties) { + super(properties, DEFAULTS); + } + + @Override + public String apiKey() { + return get(DatadogProperties::getApiKey, DatadogConfig::apiKey); + } + + @Override + public String hostTag() { + return get(DatadogProperties::getHostTag, DatadogConfig::hostTag); + } + + @Override + public Duration timerPercentilesMax() { + return get(DatadogProperties::getTimerPercentilesMax, + DatadogConfig::timerPercentilesMax); + } + + @Override + public Duration timerPercentilesMin() { + return get(DatadogProperties::getTimerPercentilesMin, + DatadogConfig::timerPercentilesMin); + } + +} diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaExportConfiguration.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaExportConfiguration.java index 2fa1005e047..00bba708e00 100644 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaExportConfiguration.java +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaExportConfiguration.java @@ -43,11 +43,17 @@ import org.springframework.context.annotation.Import; @EnableConfigurationProperties(GangliaProperties.class) public class GangliaExportConfiguration { + @Bean + @ConditionalOnMissingBean + public GangliaConfig gangliaConfig(GangliaProperties gangliaProperties) { + return new GangliaPropertiesConfigAdapter(gangliaProperties); + } + @Bean @ConditionalOnProperty(value = "spring.metrics.ganglia.enabled", matchIfMissing = true) - public MetricsExporter gangliaExporter(GangliaConfig config, + public MetricsExporter gangliaExporter(GangliaConfig gangliaConfig, HierarchicalNameMapper nameMapper, Clock clock) { - return () -> new GangliaMeterRegistry(config, nameMapper, clock); + return () -> new GangliaMeterRegistry(gangliaConfig, nameMapper, clock); } @Bean diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaProperties.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaProperties.java index b0509becfc4..3d0574fc380 100644 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaProperties.java +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaProperties.java @@ -20,9 +20,7 @@ import java.time.Duration; import java.util.concurrent.TimeUnit; import info.ganglia.gmetric4j.gmetric.GMetric; -import io.micrometer.ganglia.GangliaConfig; -import org.springframework.boot.actuate.autoconfigure.metrics.export.RegistryProperties; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -32,47 +30,123 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @since 2.0.0 */ @ConfigurationProperties(prefix = "spring.metrics.ganglia") -public class GangliaProperties extends RegistryProperties implements GangliaConfig { +public class GangliaProperties { - @Override - public String prefix() { - return "spring.metrics.ganglia"; - } + /** + * Enable publishing to the backend. + */ + private Boolean enabled = true; - public void setStep(Duration step) { - set("step", step); - } + /** + * The step size (reporting frequency) to use. + */ + private Duration step = Duration.ofMinutes(1); - public void setRateUnits(TimeUnit rateUnits) { - set("rateUnits", rateUnits); - } + /** + * The base time unit used to report rates. + */ + private TimeUnit rateUnits; - public void setDurationUnits(TimeUnit durationUnits) { - set("durationUnits", durationUnits); - } + /** + * The base time unit used to report durations. + */ + private TimeUnit durationUnits; - public void setProtocolVersion(String protocolVersion) { - set("protocolVersion", protocolVersion); - } + /** + * Ganglia protocol version. Must be either 3.1 or 3.0. + */ + private String protocolVersion; - public void setAddressingMode(GMetric.UDPAddressingMode addressingMode) { - set("addressingMode", addressingMode); - } + /** + * The UDP addressing mode, either unicast or multicast. + */ + private GMetric.UDPAddressingMode addressingMode; - public void setTtl(Integer ttl) { - set("ttl", ttl); - } + /** + * The TTL for metrics on Ganglia. + */ + private Integer timeToLive; - public void setHost(String host) { - set("host", host); - } + /** + * Ganglia host used for publishing. + */ + private String host; - public void setPort(Integer port) { - set("port", port); + /** + * Ganglia port used for publishing. + */ + private Integer port; + + public Boolean getEnabled() { + return this.enabled; } public void setEnabled(Boolean enabled) { - set("enabled", enabled); + this.enabled = enabled; + } + + public Duration getStep() { + return this.step; + } + + public void setStep(Duration step) { + this.step = step; + } + + public TimeUnit getRateUnits() { + return this.rateUnits; + } + + public void setRateUnits(TimeUnit rateUnits) { + this.rateUnits = rateUnits; + } + + public TimeUnit getDurationUnits() { + return this.durationUnits; + } + + public void setDurationUnits(TimeUnit durationUnits) { + this.durationUnits = durationUnits; + } + + public String getProtocolVersion() { + return this.protocolVersion; + } + + public void setProtocolVersion(String protocolVersion) { + this.protocolVersion = protocolVersion; + } + + public GMetric.UDPAddressingMode getAddressingMode() { + return this.addressingMode; + } + + public void setAddressingMode(GMetric.UDPAddressingMode addressingMode) { + this.addressingMode = addressingMode; + } + + public Integer getTimeToLive() { + return this.timeToLive; + } + + public void setTimeToLive(Integer timeToLive) { + this.timeToLive = timeToLive; + } + + public String getHost() { + return this.host; + } + + public void setHost(String host) { + this.host = host; + } + + public Integer getPort() { + return this.port; + } + + public void setPort(Integer port) { + this.port = port; } } diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapter.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapter.java new file mode 100644 index 00000000000..6499905b4ff --- /dev/null +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapter.java @@ -0,0 +1,93 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.metrics.export.ganglia; + +import java.time.Duration; +import java.util.concurrent.TimeUnit; + +import info.ganglia.gmetric4j.gmetric.GMetric; +import io.micrometer.ganglia.GangliaConfig; + +import org.springframework.boot.actuate.autoconfigure.metrics.export.PropertiesConfigAdapter; + +/** + * Adapter to convert {@link GangliaProperties} to a {@link GangliaConfig}. + * + * @author Jon Schneider + * @author Phillip Webb + */ +class GangliaPropertiesConfigAdapter + extends PropertiesConfigAdapter + implements GangliaConfig { + + private static final GangliaConfig DEFAULTS = (k) -> null; + + GangliaPropertiesConfigAdapter(GangliaProperties properties) { + super(properties, DEFAULTS); + } + + @Override + public String get(String k) { + return null; + } + + @Override + public boolean enabled() { + return get(GangliaProperties::getEnabled, GangliaConfig::enabled); + } + + @Override + public Duration step() { + return get(GangliaProperties::getStep, GangliaConfig::step); + } + + @Override + public TimeUnit rateUnits() { + return get(GangliaProperties::getRateUnits, GangliaConfig::rateUnits); + } + + @Override + public TimeUnit durationUnits() { + return get(GangliaProperties::getDurationUnits, GangliaConfig::durationUnits); + } + + @Override + public String protocolVersion() { + return get(GangliaProperties::getProtocolVersion, GangliaConfig::protocolVersion); + } + + @Override + public GMetric.UDPAddressingMode addressingMode() { + return get(GangliaProperties::getAddressingMode, GangliaConfig::addressingMode); + } + + @Override + public int ttl() { + return get(GangliaProperties::getTimeToLive, GangliaConfig::ttl); + } + + @Override + public String host() { + return get(GangliaProperties::getHost, GangliaConfig::host); + } + + @Override + public int port() { + return get(GangliaProperties::getPort, GangliaConfig::port); + } + +} diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteExportConfiguration.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteExportConfiguration.java index f36e49b57ea..79d025f6142 100644 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteExportConfiguration.java +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteExportConfiguration.java @@ -43,11 +43,17 @@ import org.springframework.context.annotation.Import; @EnableConfigurationProperties(GraphiteProperties.class) public class GraphiteExportConfiguration { + @Bean + @ConditionalOnMissingBean + public GraphiteConfig graphiteConfig(GraphiteProperties graphiteProperties) { + return new GraphitePropertiesConfigAdapter(graphiteProperties); + } + @Bean @ConditionalOnProperty(value = "spring.metrics.graphite.enabled", matchIfMissing = true) - public MetricsExporter graphiteExporter(GraphiteConfig config, + public MetricsExporter graphiteExporter(GraphiteConfig graphiteConfig, HierarchicalNameMapper nameMapper, Clock clock) { - return () -> new GraphiteMeterRegistry(config, nameMapper, clock); + return () -> new GraphiteMeterRegistry(graphiteConfig, nameMapper, clock); } @Bean diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteProperties.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteProperties.java index f856633fdc0..06114a9b2f6 100644 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteProperties.java +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteProperties.java @@ -19,9 +19,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.graphite; import java.time.Duration; import java.util.concurrent.TimeUnit; -import io.micrometer.graphite.GraphiteConfig; - -import org.springframework.boot.actuate.autoconfigure.metrics.export.RegistryProperties; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -31,35 +28,82 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @since 2.0.0 */ @ConfigurationProperties(prefix = "spring.metrics.graphite") -public class GraphiteProperties extends RegistryProperties implements GraphiteConfig { +public class GraphiteProperties { + /** + * Enable publishing to the backend. + */ + private Boolean enabled = true; - @Override - public String prefix() { - return "spring.metrics.graphite"; - } + /** + * The step size (reporting frequency) to use. + */ + private Duration step = Duration.ofMinutes(1); - public void setStep(Duration step) { - set("step", step); - } + /** + * The base time unit used to report rates. + */ + private TimeUnit rateUnits; - public void setRateUnits(TimeUnit rateUnits) { - set("rateUnits", rateUnits); - } + /** + * The base time unit used to report durations. + */ + private TimeUnit durationUnits; - public void setDurationUnits(TimeUnit durationUnits) { - set("durationUnits", durationUnits); - } + /** + * Graphite host used for publishing. + */ + private String host; - public void setHost(String host) { - set("host", host); - } + /** + * Graphite port used for publishing. + */ + private Integer port; - public void setPort(Integer port) { - set("port", port); + public Boolean getEnabled() { + return this.enabled; } public void setEnabled(Boolean enabled) { - set("enabled", enabled); + this.enabled = enabled; } + public Duration getStep() { + return this.step; + } + + public void setStep(Duration step) { + this.step = step; + } + + public TimeUnit getRateUnits() { + return this.rateUnits; + } + + public void setRateUnits(TimeUnit rateUnits) { + this.rateUnits = rateUnits; + } + + public TimeUnit getDurationUnits() { + return this.durationUnits; + } + + public void setDurationUnits(TimeUnit durationUnits) { + this.durationUnits = durationUnits; + } + + public String getHost() { + return this.host; + } + + public void setHost(String host) { + this.host = host; + } + + public Integer getPort() { + return this.port; + } + + public void setPort(Integer port) { + this.port = port; + } } diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapter.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapter.java new file mode 100644 index 00000000000..61365e04668 --- /dev/null +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapter.java @@ -0,0 +1,77 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.metrics.export.graphite; + +import java.time.Duration; +import java.util.concurrent.TimeUnit; + +import io.micrometer.graphite.GraphiteConfig; + +import org.springframework.boot.actuate.autoconfigure.metrics.export.PropertiesConfigAdapter; + +/** + * Adapter to convert {@link GraphiteProperties} to a {@link GraphiteConfig}. + * + * @author Jon Schneider + * @author Phillip Webb + */ +class GraphitePropertiesConfigAdapter + extends PropertiesConfigAdapter + implements GraphiteConfig { + + private static final GraphiteConfig DEFAULTS = (k) -> null; + + GraphitePropertiesConfigAdapter(GraphiteProperties properties) { + super(properties, DEFAULTS); + } + + @Override + public String get(String k) { + return null; + } + + @Override + public boolean enabled() { + return get(GraphiteProperties::getEnabled, GraphiteConfig::enabled); + } + + @Override + public Duration step() { + return get(GraphiteProperties::getStep, GraphiteConfig::step); + } + + @Override + public TimeUnit rateUnits() { + return get(GraphiteProperties::getRateUnits, GraphiteConfig::rateUnits); + } + + @Override + public TimeUnit durationUnits() { + return get(GraphiteProperties::getDurationUnits, GraphiteConfig::durationUnits); + } + + @Override + public String host() { + return get(GraphiteProperties::getHost, GraphiteConfig::host); + } + + @Override + public int port() { + return get(GraphiteProperties::getPort, GraphiteConfig::port); + } + +} diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxExportConfiguration.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxExportConfiguration.java index 365c90fc6eb..907a7031fc7 100644 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxExportConfiguration.java +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxExportConfiguration.java @@ -42,10 +42,16 @@ import org.springframework.context.annotation.Import; @EnableConfigurationProperties(InfluxProperties.class) public class InfluxExportConfiguration { + @Bean + @ConditionalOnMissingBean(InfluxConfig.class) + public InfluxConfig influxConfig(InfluxProperties influxProperties) { + return new InfluxPropertiesConfigAdapter(influxProperties); + } + @Bean @ConditionalOnProperty(value = "spring.metrics.influx.enabled", matchIfMissing = true) - public MetricsExporter influxExporter(InfluxConfig config, Clock clock) { - return () -> new InfluxMeterRegistry(config, clock); + public MetricsExporter influxExporter(InfluxConfig influxConfig, Clock clock) { + return () -> new InfluxMeterRegistry(influxConfig, clock); } @Bean diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxProperties.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxProperties.java index c1e482c5045..e0da46d3af2 100644 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxProperties.java +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxProperties.java @@ -16,7 +16,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.influx; -import io.micrometer.influx.InfluxConfig; +import java.time.Duration; + import io.micrometer.influx.InfluxConsistency; import org.springframework.boot.actuate.autoconfigure.metrics.export.StepRegistryProperties; @@ -29,39 +30,127 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @since 2.0.0 */ @ConfigurationProperties(prefix = "spring.metrics.influx") -public class InfluxProperties extends StepRegistryProperties implements InfluxConfig { +public class InfluxProperties extends StepRegistryProperties { + /** + * The tag that will be mapped to "host" when shipping metrics to Influx, or + * {@code null} if host should be omitted on publishing. + */ + private String db; - @Override - public String prefix() { - return "spring.metrics.influx"; + /** + * The write consistency for each point. + */ + private InfluxConsistency consistency; + + /** + * Authenticate requests with this user. If not specified, the registry will not + * attempt to present credentials to Influx. + */ + private String userName; + + /** + * Authenticate requests with this password. + */ + private String password; + + /** + * Influx writes to the DEFAULT retention policy if one is not specified. + */ + private String retentionPolicy; + + /** + * The URI for the Influx backend. + */ + private String uri; + + /** + * Enable GZIP compression of metrics batches published to Influx. + */ + private Boolean compressed; + + /** + * The bucket filter clamping the bucket domain of timer percentiles histograms to + * some max value. This is used to limit the number of buckets shipped to Prometheus + * to save on storage. + */ + private Duration timerPercentilesMax = Duration.ofMinutes(2); + + /** + * The bucket filter clamping the bucket domain of timer percentiles histograms to + * some min value. This is used to limit the number of buckets shipped to Prometheus + * to save on storage. + */ + private Duration timerPercentilesMin = Duration.ofMillis(10); + + public String getDb() { + return this.db; } public void setDb(String db) { - set("db", db); + this.db = db; + } + + public InfluxConsistency getConsistency() { + return this.consistency; } public void setConsistency(InfluxConsistency consistency) { - set("consistency", consistency); + this.consistency = consistency; + } + + public String getUserName() { + return this.userName; } public void setUserName(String userName) { - set("userName", userName); + this.userName = userName; + } + + public String getPassword() { + return this.password; } public void setPassword(String password) { - set("password", password); + this.password = password; + } + + public String getRetentionPolicy() { + return this.retentionPolicy; } public void setRetentionPolicy(String retentionPolicy) { - set("retentionPolicy", retentionPolicy); + this.retentionPolicy = retentionPolicy; + } + + public String getUri() { + return this.uri; } public void setUri(String uri) { - set("uri", uri); + this.uri = uri; + } + + public Boolean getCompressed() { + return this.compressed; } public void setCompressed(Boolean compressed) { - set("compressed", compressed); + this.compressed = compressed; } + public Duration getTimerPercentilesMax() { + return this.timerPercentilesMax; + } + + public void setTimerPercentilesMax(Duration timerPercentilesMax) { + this.timerPercentilesMax = timerPercentilesMax; + } + + public Duration getTimerPercentilesMin() { + return this.timerPercentilesMin; + } + + public void setTimerPercentilesMin(Duration timerPercentilesMin) { + this.timerPercentilesMin = timerPercentilesMin; + } } diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapter.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapter.java new file mode 100644 index 00000000000..eb68b172965 --- /dev/null +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapter.java @@ -0,0 +1,89 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.metrics.export.influx; + +import java.time.Duration; + +import io.micrometer.influx.InfluxConfig; +import io.micrometer.influx.InfluxConsistency; + +import org.springframework.boot.actuate.autoconfigure.metrics.export.StepRegistryPropertiesConfigAdapter; + +/** + * Adapter to convert {@link InfluxProperties} to an {@link InfluxConfig}. + * + * @author Jon Schneider + * @author Phillip Webb + */ +class InfluxPropertiesConfigAdapter + extends StepRegistryPropertiesConfigAdapter + implements InfluxConfig { + + private static final InfluxConfig DEFAULTS = (k) -> null; + + InfluxPropertiesConfigAdapter(InfluxProperties properties) { + super(properties, DEFAULTS); + } + + @Override + public String db() { + return get(InfluxProperties::getDb, InfluxConfig::db); + } + + @Override + public InfluxConsistency consistency() { + return get(InfluxProperties::getConsistency, InfluxConfig::consistency); + } + + @Override + public String userName() { + return get(InfluxProperties::getUserName, InfluxConfig::userName); + } + + @Override + public String password() { + return get(InfluxProperties::getPassword, InfluxConfig::password); + } + + @Override + public String retentionPolicy() { + return get(InfluxProperties::getRetentionPolicy, InfluxConfig::retentionPolicy); + } + + @Override + public String uri() { + return get(InfluxProperties::getUri, InfluxConfig::uri); + } + + @Override + public boolean compressed() { + return get(InfluxProperties::getCompressed, InfluxConfig::compressed); + } + + @Override + public Duration timerPercentilesMax() { + return get(InfluxProperties::getTimerPercentilesMax, + InfluxConfig::timerPercentilesMax); + } + + @Override + public Duration timerPercentilesMin() { + return get(InfluxProperties::getTimerPercentilesMin, + InfluxConfig::timerPercentilesMin); + } + +} diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusExportConfiguration.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusExportConfiguration.java index 2535566ff1f..26b5754056d 100644 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusExportConfiguration.java +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusExportConfiguration.java @@ -42,11 +42,18 @@ import org.springframework.context.annotation.Configuration; @EnableConfigurationProperties(PrometheusProperties.class) public class PrometheusExportConfiguration { + @Bean + @ConditionalOnMissingBean + public PrometheusConfig prometheusConfig(PrometheusProperties prometheusProperties) { + return new PrometheusPropertiesConfigAdapter(prometheusProperties); + } + @Bean @ConditionalOnProperty(value = "spring.metrics.prometheus.enabled", matchIfMissing = true) - public MetricsExporter prometheusExporter(PrometheusConfig config, + public MetricsExporter prometheusExporter(PrometheusConfig prometheusConfig, CollectorRegistry collectorRegistry, Clock clock) { - return () -> new PrometheusMeterRegistry(config, collectorRegistry, clock); + return () -> new PrometheusMeterRegistry(prometheusConfig, collectorRegistry, + clock); } @Bean diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusProperties.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusProperties.java index 1a0869d6b1c..d5cef59c584 100644 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusProperties.java +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusProperties.java @@ -16,9 +16,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus; -import io.micrometer.prometheus.PrometheusConfig; +import java.time.Duration; -import org.springframework.boot.actuate.autoconfigure.metrics.export.RegistryProperties; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -28,25 +27,63 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @since 2.0.0 */ @ConfigurationProperties(prefix = "spring.metrics.prometheus") -public class PrometheusProperties extends RegistryProperties implements PrometheusConfig { +public class PrometheusProperties { - private boolean enabled = true; + /** + * Enable publishing to Prometheus. + */ + private Boolean enabled = true; - public boolean isEnabled() { + /** + * Enable publishing descriptions as part of the scrape payload to Prometheus. Turn + * this off to minimize the amount of data sent on each scrape. + */ + private Boolean descriptions = true; + + /** + * The bucket filter clamping the bucket domain of timer percentiles histograms to + * some max value. This is used to limit the number of buckets shipped to Prometheus + * to save on storage. + */ + private Duration timerPercentilesMax = Duration.ofMinutes(2); + + /** + * The bucket filter clamping the bucket domain of timer percentiles histograms to + * some min value. This is used to limit the number of buckets shipped to Prometheus + * to save on storage. + */ + private Duration timerPercentilesMin = Duration.ofMillis(10); + + public Boolean getEnabled() { return this.enabled; } - public void setEnabled(boolean enabled) { + public void setEnabled(Boolean enabled) { this.enabled = enabled; } - public void setDescriptions(Boolean descriptions) { - set("descriptions", descriptions); + public Boolean getDescriptions() { + return this.descriptions; } - @Override - public String prefix() { - return "spring.metrics.prometheus"; + public void setDescriptions(Boolean descriptions) { + this.descriptions = descriptions; + } + + public Duration getTimerPercentilesMax() { + return this.timerPercentilesMax; + } + + public void setTimerPercentilesMax(Duration timerPercentilesMax) { + this.timerPercentilesMax = timerPercentilesMax; + } + + public Duration getTimerPercentilesMin() { + return this.timerPercentilesMin; + } + + public void setTimerPercentilesMin(Duration timerPercentilesMin) { + this.timerPercentilesMin = timerPercentilesMin; } } diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapter.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapter.java new file mode 100644 index 00000000000..d153c3be157 --- /dev/null +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapter.java @@ -0,0 +1,63 @@ +/* + * Copyright 2012-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus; + +import java.time.Duration; + +import io.micrometer.prometheus.PrometheusConfig; + +import org.springframework.boot.actuate.autoconfigure.metrics.export.PropertiesConfigAdapter; + +/** + * Adapter to convert {@link PrometheusProperties} to a {@link PrometheusConfig}. + * + * @author Jon Schneider + * @author Phillip Webb + */ +class PrometheusPropertiesConfigAdapter + extends PropertiesConfigAdapter + implements PrometheusConfig { + + private static final PrometheusConfig DEFAULTS = (key) -> null; + + PrometheusPropertiesConfigAdapter(PrometheusProperties properties) { + super(properties, DEFAULTS); + } + + @Override + public String get(String key) { + return null; + } + + @Override + public boolean descriptions() { + return get(PrometheusProperties::getDescriptions, PrometheusConfig::descriptions); + } + + @Override + public Duration timerPercentilesMin() { + return get(PrometheusProperties::getTimerPercentilesMin, + PrometheusConfig::timerPercentilesMin); + } + + @Override + public Duration timerPercentilesMax() { + return get(PrometheusProperties::getTimerPercentilesMax, + PrometheusConfig::timerPercentilesMax); + } + +}