Commit e59d70ea authored by Phillip Webb's avatar Phillip Webb

Change micrometer properties to use adapters

Update configuration property classes used with micrometer so that
they no longer directly implement `Config` interfaces. Properties
are now adapted to Config implementations independently.

See gh-9970
parent 86926bf0
/*
* 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 <T> The properties type
* @param <C> The config type
* @author Phillip Webb
* @since 2.0.0
*/
public class PropertiesConfigAdapter<T, C> {
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 <V> the value type
* @return the property or fallback value
*/
protected final <V> V get(Function<T, V> getter, Function<C, V> fallback) {
V value = getter.apply(this.properties);
return (value != null ? value : fallback.apply(this.defaults));
}
}
...@@ -18,41 +18,93 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export; ...@@ -18,41 +18,93 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export;
import java.time.Duration; import java.time.Duration;
import io.micrometer.core.instrument.spectator.step.StepRegistryConfig;
/** /**
* Specialization of {@link RegistryProperties} for configuring a metrics registry that * Base class for properties that configure a metrics registry that pushes aggregated
* pushes aggregated metrics on a regular interval. * metrics on a regular interval.
* *
* @author Jon Schneider * @author Jon Schneider
* @author Andy Wilkinson * @author Andy Wilkinson
* @since 2.0.0 * @since 2.0.0
*/ */
public abstract class StepRegistryProperties extends RegistryProperties public abstract class StepRegistryProperties {
implements StepRegistryConfig {
/**
* 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) { public void setStep(Duration step) {
set("step", step); this.step = step;
}
public Boolean getEnabled() {
return this.enabled;
} }
public void setEnabled(Boolean enabled) { public void setEnabled(Boolean enabled) {
set("enabled", enabled); this.enabled = enabled;
} }
public void setBatchSize(Integer batchSize) { public Duration getConnectTimeout() {
set("batchSize", batchSize); return this.connectTimeout;
} }
public void setConnectTimeout(Duration connectTimeout) { public void setConnectTimeout(Duration connectTimeout) {
set("connectTimeout", connectTimeout); this.connectTimeout = connectTimeout;
}
public Duration getReadTimeout() {
return this.readTimeout;
} }
public void setReadTimeout(Duration readTimeout) { public void setReadTimeout(Duration readTimeout) {
set("readTimeout", readTimeout); this.readTimeout = readTimeout;
}
public Integer getNumThreads() {
return this.numThreads;
} }
public void setNumThreads(Integer 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;
} }
} }
/*
* 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 <T> The properties type
* @param <C> The config type
* @author Jon Schneider
* @author Phillip Webb
* @since 2.0.0
*/
public abstract class StepRegistryPropertiesConfigAdapter<T extends StepRegistryProperties, C extends StepRegistryConfig>
extends PropertiesConfigAdapter<T, C> 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);
}
}
...@@ -43,10 +43,16 @@ import org.springframework.context.annotation.Import; ...@@ -43,10 +43,16 @@ import org.springframework.context.annotation.Import;
@EnableConfigurationProperties(AtlasProperties.class) @EnableConfigurationProperties(AtlasProperties.class)
public class AtlasExportConfiguration { public class AtlasExportConfiguration {
@Bean
@ConditionalOnMissingBean(AtlasConfig.class)
public AtlasConfig atlasConfig(AtlasProperties atlasProperties) {
return new AtlasPropertiesConfigAdapter(atlasProperties);
}
@Bean @Bean
@ConditionalOnProperty(value = "spring.metrics.atlas.enabled", matchIfMissing = true) @ConditionalOnProperty(value = "spring.metrics.atlas.enabled", matchIfMissing = true)
public MetricsExporter atlasExporter(AtlasConfig config, Clock clock) { public MetricsExporter atlasExporter(AtlasConfig atlasConfig, Clock clock) {
return () -> new AtlasMeterRegistry(config, clock); return () -> new AtlasMeterRegistry(atlasConfig, clock);
} }
@Bean @Bean
......
...@@ -18,9 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.atlas; ...@@ -18,9 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.atlas;
import java.time.Duration; import java.time.Duration;
import com.netflix.spectator.atlas.AtlasConfig; import org.springframework.boot.actuate.autoconfigure.metrics.export.StepRegistryProperties;
import org.springframework.boot.actuate.autoconfigure.metrics.export.RegistryProperties;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
/** /**
...@@ -30,63 +28,97 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -30,63 +28,97 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @author Jon Schneider * @author Jon Schneider
*/ */
@ConfigurationProperties(prefix = "spring.metrics.atlas") @ConfigurationProperties(prefix = "spring.metrics.atlas")
public class AtlasProperties extends RegistryProperties implements AtlasConfig { public class AtlasProperties extends StepRegistryProperties {
@Override /**
protected String prefix() { * The URI for the Atlas backend.
return "spring.metrics.atlas"; */
private String uri;
/**
* 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;
/**
* Enable streaming to Atlas LWC.
*/
private Boolean lwcEnabled;
/**
* The frequency for refreshing config settings from the LWC service.
*/
private Duration configRefreshFrequency;
/**
* 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 setStep(Duration step) { public void setUri(String uri) {
set("step", step); this.uri = uri;
} }
public void setMeterTTL(Duration meterTTL) { public Duration getMeterTimeToLive() {
set("meterTTL", meterTTL); return this.meterTimeToLive;
} }
public void setEnabled(Boolean enabled) { public void setMeterTimeToLive(Duration meterTimeToLive) {
set("enabled", enabled); this.meterTimeToLive = meterTimeToLive;
} }
public void setNumThreads(Integer numThreads) { public Boolean getLwcEnabled() {
set("numThreads", numThreads); return this.lwcEnabled;
} }
public void setUri(String uri) { public void setLwcEnabled(Boolean lwcEnabled) {
set("uri", uri); this.lwcEnabled = lwcEnabled;
} }
public void setLwcEnabled(boolean lwcEnabled) { public Duration getConfigRefreshFrequency() {
set("lwcEnabled", lwcEnabled); return this.configRefreshFrequency;
} }
public void setConfigRefreshFrequency(Duration configRefreshFrequency) { public void setConfigRefreshFrequency(Duration configRefreshFrequency) {
set("configRefreshFrequency", configRefreshFrequency); this.configRefreshFrequency = configRefreshFrequency;
} }
public void setConfigTTL(Duration configTTL) { public Duration getConfigTimeToLive() {
set("configTTL", configTTL); return this.configTimeToLive;
} }
public void setConfigUri(String configUri) { public void setConfigTimeToLive(Duration configTimeToLive) {
set("configUri", configUri); this.configTimeToLive = configTimeToLive;
} }
public void setEvalUri(String evalUri) { public String getConfigUri() {
set("evalUri", evalUri); return this.configUri;
} }
public void setConnectTimeout(Duration connectTimeout) { public void setConfigUri(String configUri) {
set("connectTimeout", connectTimeout); this.configUri = configUri;
} }
public void setReadTimeout(Duration readTimeout) { public String getEvalUri() {
set("readTimeout", readTimeout); return this.evalUri;
} }
public void setBatchSize(Integer batchSize) { public void setEvalUri(String evalUri) {
set("batchSize", batchSize); this.evalUri = evalUri;
} }
} }
/*
* 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<AtlasProperties, AtlasConfig> 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);
}
}
...@@ -38,14 +38,21 @@ import org.springframework.context.annotation.Import; ...@@ -38,14 +38,21 @@ import org.springframework.context.annotation.Import;
*/ */
@Configuration @Configuration
@ConditionalOnClass(DatadogMeterRegistry.class) @ConditionalOnClass(DatadogMeterRegistry.class)
@ConditionalOnProperty("spring.metrics.datadog.api-key")
@Import(StringToDurationConverter.class) @Import(StringToDurationConverter.class)
@EnableConfigurationProperties(DatadogProperties.class) @EnableConfigurationProperties(DatadogProperties.class)
public class DatadogExportConfiguration { public class DatadogExportConfiguration {
@Bean
@ConditionalOnMissingBean
public DatadogConfig datadogConfig(DatadogProperties datadogProperties) {
return new DatadogPropertiesConfigAdapter(datadogProperties);
}
@Bean @Bean
@ConditionalOnProperty(value = "spring.metrics.datadog.enabled", matchIfMissing = true) @ConditionalOnProperty(value = "spring.metrics.datadog.enabled", matchIfMissing = true)
public MetricsExporter datadogExporter(DatadogConfig config, Clock clock) { public MetricsExporter datadogExporter(DatadogConfig datadogConfig, Clock clock) {
return () -> new DatadogMeterRegistry(config, clock); return () -> new DatadogMeterRegistry(datadogConfig, clock);
} }
@Bean @Bean
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.datadog; 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.actuate.autoconfigure.metrics.export.StepRegistryProperties;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
...@@ -28,23 +28,63 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -28,23 +28,63 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @since 2.0.0 * @since 2.0.0
*/ */
@ConfigurationProperties(prefix = "spring.metrics.datadog") @ConfigurationProperties(prefix = "spring.metrics.datadog")
public class DatadogProperties extends StepRegistryProperties implements DatadogConfig { public class DatadogProperties extends StepRegistryProperties {
@Override /**
public String prefix() { * Your API key, found in your account settings at datadoghq. This property is
return "spring.metrics.datadog"; * required.
} */
private String apiKey;
/**
* 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 DatadogProperties() { public String getApiKey() {
set("apiKey", "dummyKey"); // FIXME otherwise tests fail return this.apiKey;
} }
public void setApiKey(String apiKey) { public void setApiKey(String apiKey) {
set("apiKey", apiKey); this.apiKey = apiKey;
} }
public void setHostTag(String hostTag) { public String getHostTag() {
set("hostTag", hostTag); 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;
}
} }
/*
* 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<DatadogProperties, DatadogConfig>
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);
}
}
...@@ -43,11 +43,17 @@ import org.springframework.context.annotation.Import; ...@@ -43,11 +43,17 @@ import org.springframework.context.annotation.Import;
@EnableConfigurationProperties(GangliaProperties.class) @EnableConfigurationProperties(GangliaProperties.class)
public class GangliaExportConfiguration { public class GangliaExportConfiguration {
@Bean
@ConditionalOnMissingBean
public GangliaConfig gangliaConfig(GangliaProperties gangliaProperties) {
return new GangliaPropertiesConfigAdapter(gangliaProperties);
}
@Bean @Bean
@ConditionalOnProperty(value = "spring.metrics.ganglia.enabled", matchIfMissing = true) @ConditionalOnProperty(value = "spring.metrics.ganglia.enabled", matchIfMissing = true)
public MetricsExporter gangliaExporter(GangliaConfig config, public MetricsExporter gangliaExporter(GangliaConfig gangliaConfig,
HierarchicalNameMapper nameMapper, Clock clock) { HierarchicalNameMapper nameMapper, Clock clock) {
return () -> new GangliaMeterRegistry(config, nameMapper, clock); return () -> new GangliaMeterRegistry(gangliaConfig, nameMapper, clock);
} }
@Bean @Bean
......
...@@ -20,9 +20,7 @@ import java.time.Duration; ...@@ -20,9 +20,7 @@ import java.time.Duration;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import info.ganglia.gmetric4j.gmetric.GMetric; 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; import org.springframework.boot.context.properties.ConfigurationProperties;
/** /**
...@@ -32,47 +30,123 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -32,47 +30,123 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @since 2.0.0 * @since 2.0.0
*/ */
@ConfigurationProperties(prefix = "spring.metrics.ganglia") @ConfigurationProperties(prefix = "spring.metrics.ganglia")
public class GangliaProperties extends RegistryProperties implements GangliaConfig { public class GangliaProperties {
/**
* Enable publishing to the backend.
*/
private Boolean enabled = true;
/**
* The step size (reporting frequency) to use.
*/
private Duration step = Duration.ofMinutes(1);
/**
* The base time unit used to report rates.
*/
private TimeUnit rateUnits;
/**
* The base time unit used to report durations.
*/
private TimeUnit durationUnits;
/**
* Ganglia protocol version. Must be either 3.1 or 3.0.
*/
private String protocolVersion;
/**
* The UDP addressing mode, either unicast or multicast.
*/
private GMetric.UDPAddressingMode addressingMode;
/**
* The TTL for metrics on Ganglia.
*/
private Integer timeToLive;
/**
* Ganglia host used for publishing.
*/
private String host;
/**
* Ganglia port used for publishing.
*/
private Integer port;
public Boolean getEnabled() {
return this.enabled;
}
@Override public void setEnabled(Boolean enabled) {
public String prefix() { this.enabled = enabled;
return "spring.metrics.ganglia"; }
public Duration getStep() {
return this.step;
} }
public void setStep(Duration step) { public void setStep(Duration step) {
set("step", step); this.step = step;
}
public TimeUnit getRateUnits() {
return this.rateUnits;
} }
public void setRateUnits(TimeUnit rateUnits) { public void setRateUnits(TimeUnit rateUnits) {
set("rateUnits", rateUnits); this.rateUnits = rateUnits;
}
public TimeUnit getDurationUnits() {
return this.durationUnits;
} }
public void setDurationUnits(TimeUnit durationUnits) { public void setDurationUnits(TimeUnit durationUnits) {
set("durationUnits", durationUnits); this.durationUnits = durationUnits;
}
public String getProtocolVersion() {
return this.protocolVersion;
} }
public void setProtocolVersion(String protocolVersion) { public void setProtocolVersion(String protocolVersion) {
set("protocolVersion", protocolVersion); this.protocolVersion = protocolVersion;
}
public GMetric.UDPAddressingMode getAddressingMode() {
return this.addressingMode;
} }
public void setAddressingMode(GMetric.UDPAddressingMode addressingMode) { public void setAddressingMode(GMetric.UDPAddressingMode addressingMode) {
set("addressingMode", addressingMode); this.addressingMode = addressingMode;
} }
public void setTtl(Integer ttl) { public Integer getTimeToLive() {
set("ttl", ttl); return this.timeToLive;
}
public void setTimeToLive(Integer timeToLive) {
this.timeToLive = timeToLive;
}
public String getHost() {
return this.host;
} }
public void setHost(String host) { public void setHost(String host) {
set("host", host); this.host = host;
} }
public void setPort(Integer port) { public Integer getPort() {
set("port", port); return this.port;
} }
public void setEnabled(Boolean enabled) { public void setPort(Integer port) {
set("enabled", enabled); this.port = port;
} }
} }
/*
* 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<GangliaProperties, GangliaConfig>
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);
}
}
...@@ -43,11 +43,17 @@ import org.springframework.context.annotation.Import; ...@@ -43,11 +43,17 @@ import org.springframework.context.annotation.Import;
@EnableConfigurationProperties(GraphiteProperties.class) @EnableConfigurationProperties(GraphiteProperties.class)
public class GraphiteExportConfiguration { public class GraphiteExportConfiguration {
@Bean
@ConditionalOnMissingBean
public GraphiteConfig graphiteConfig(GraphiteProperties graphiteProperties) {
return new GraphitePropertiesConfigAdapter(graphiteProperties);
}
@Bean @Bean
@ConditionalOnProperty(value = "spring.metrics.graphite.enabled", matchIfMissing = true) @ConditionalOnProperty(value = "spring.metrics.graphite.enabled", matchIfMissing = true)
public MetricsExporter graphiteExporter(GraphiteConfig config, public MetricsExporter graphiteExporter(GraphiteConfig graphiteConfig,
HierarchicalNameMapper nameMapper, Clock clock) { HierarchicalNameMapper nameMapper, Clock clock) {
return () -> new GraphiteMeterRegistry(config, nameMapper, clock); return () -> new GraphiteMeterRegistry(graphiteConfig, nameMapper, clock);
} }
@Bean @Bean
......
...@@ -19,9 +19,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.graphite; ...@@ -19,9 +19,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.graphite;
import java.time.Duration; import java.time.Duration;
import java.util.concurrent.TimeUnit; 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; import org.springframework.boot.context.properties.ConfigurationProperties;
/** /**
...@@ -31,35 +28,82 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -31,35 +28,82 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @since 2.0.0 * @since 2.0.0
*/ */
@ConfigurationProperties(prefix = "spring.metrics.graphite") @ConfigurationProperties(prefix = "spring.metrics.graphite")
public class GraphiteProperties extends RegistryProperties implements GraphiteConfig { public class GraphiteProperties {
/**
* Enable publishing to the backend.
*/
private Boolean enabled = true;
/**
* The step size (reporting frequency) to use.
*/
private Duration step = Duration.ofMinutes(1);
/**
* The base time unit used to report rates.
*/
private TimeUnit rateUnits;
/**
* The base time unit used to report durations.
*/
private TimeUnit durationUnits;
/**
* Graphite host used for publishing.
*/
private String host;
/**
* Graphite port used for publishing.
*/
private Integer port;
public Boolean getEnabled() {
return this.enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
@Override public Duration getStep() {
public String prefix() { return this.step;
return "spring.metrics.graphite";
} }
public void setStep(Duration step) { public void setStep(Duration step) {
set("step", step); this.step = step;
}
public TimeUnit getRateUnits() {
return this.rateUnits;
} }
public void setRateUnits(TimeUnit rateUnits) { public void setRateUnits(TimeUnit rateUnits) {
set("rateUnits", rateUnits); this.rateUnits = rateUnits;
}
public TimeUnit getDurationUnits() {
return this.durationUnits;
} }
public void setDurationUnits(TimeUnit durationUnits) { public void setDurationUnits(TimeUnit durationUnits) {
set("durationUnits", durationUnits); this.durationUnits = durationUnits;
} }
public void setHost(String host) { public String getHost() {
set("host", host); return this.host;
} }
public void setPort(Integer port) { public void setHost(String host) {
set("port", port); this.host = host;
} }
public void setEnabled(Boolean enabled) { public Integer getPort() {
set("enabled", enabled); return this.port;
} }
public void setPort(Integer port) {
this.port = port;
}
} }
/*
* 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<GraphiteProperties, GraphiteConfig>
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);
}
}
...@@ -42,10 +42,16 @@ import org.springframework.context.annotation.Import; ...@@ -42,10 +42,16 @@ import org.springframework.context.annotation.Import;
@EnableConfigurationProperties(InfluxProperties.class) @EnableConfigurationProperties(InfluxProperties.class)
public class InfluxExportConfiguration { public class InfluxExportConfiguration {
@Bean
@ConditionalOnMissingBean(InfluxConfig.class)
public InfluxConfig influxConfig(InfluxProperties influxProperties) {
return new InfluxPropertiesConfigAdapter(influxProperties);
}
@Bean @Bean
@ConditionalOnProperty(value = "spring.metrics.influx.enabled", matchIfMissing = true) @ConditionalOnProperty(value = "spring.metrics.influx.enabled", matchIfMissing = true)
public MetricsExporter influxExporter(InfluxConfig config, Clock clock) { public MetricsExporter influxExporter(InfluxConfig influxConfig, Clock clock) {
return () -> new InfluxMeterRegistry(config, clock); return () -> new InfluxMeterRegistry(influxConfig, clock);
} }
@Bean @Bean
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.influx; package org.springframework.boot.actuate.autoconfigure.metrics.export.influx;
import io.micrometer.influx.InfluxConfig; import java.time.Duration;
import io.micrometer.influx.InfluxConsistency; import io.micrometer.influx.InfluxConsistency;
import org.springframework.boot.actuate.autoconfigure.metrics.export.StepRegistryProperties; import org.springframework.boot.actuate.autoconfigure.metrics.export.StepRegistryProperties;
...@@ -29,39 +30,127 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -29,39 +30,127 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @since 2.0.0 * @since 2.0.0
*/ */
@ConfigurationProperties(prefix = "spring.metrics.influx") @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;
/**
* 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;
@Override /**
public String prefix() { * The bucket filter clamping the bucket domain of timer percentiles histograms to
return "spring.metrics.influx"; * 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) { public void setDb(String db) {
set("db", db); this.db = db;
}
public InfluxConsistency getConsistency() {
return this.consistency;
} }
public void setConsistency(InfluxConsistency consistency) { public void setConsistency(InfluxConsistency consistency) {
set("consistency", consistency); this.consistency = consistency;
}
public String getUserName() {
return this.userName;
} }
public void setUserName(String userName) { public void setUserName(String userName) {
set("userName", userName); this.userName = userName;
}
public String getPassword() {
return this.password;
} }
public void setPassword(String password) { public void setPassword(String password) {
set("password", password); this.password = password;
}
public String getRetentionPolicy() {
return this.retentionPolicy;
} }
public void setRetentionPolicy(String retentionPolicy) { public void setRetentionPolicy(String retentionPolicy) {
set("retentionPolicy", retentionPolicy); this.retentionPolicy = retentionPolicy;
}
public String getUri() {
return this.uri;
} }
public void setUri(String uri) { public void setUri(String uri) {
set("uri", uri); this.uri = uri;
}
public Boolean getCompressed() {
return this.compressed;
} }
public void setCompressed(Boolean 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;
}
} }
/*
* 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<InfluxProperties, InfluxConfig>
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);
}
}
...@@ -42,11 +42,18 @@ import org.springframework.context.annotation.Configuration; ...@@ -42,11 +42,18 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(PrometheusProperties.class) @EnableConfigurationProperties(PrometheusProperties.class)
public class PrometheusExportConfiguration { public class PrometheusExportConfiguration {
@Bean
@ConditionalOnMissingBean
public PrometheusConfig prometheusConfig(PrometheusProperties prometheusProperties) {
return new PrometheusPropertiesConfigAdapter(prometheusProperties);
}
@Bean @Bean
@ConditionalOnProperty(value = "spring.metrics.prometheus.enabled", matchIfMissing = true) @ConditionalOnProperty(value = "spring.metrics.prometheus.enabled", matchIfMissing = true)
public MetricsExporter prometheusExporter(PrometheusConfig config, public MetricsExporter prometheusExporter(PrometheusConfig prometheusConfig,
CollectorRegistry collectorRegistry, Clock clock) { CollectorRegistry collectorRegistry, Clock clock) {
return () -> new PrometheusMeterRegistry(config, collectorRegistry, clock); return () -> new PrometheusMeterRegistry(prometheusConfig, collectorRegistry,
clock);
} }
@Bean @Bean
......
...@@ -16,9 +16,8 @@ ...@@ -16,9 +16,8 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus; 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; import org.springframework.boot.context.properties.ConfigurationProperties;
/** /**
...@@ -28,25 +27,63 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -28,25 +27,63 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @since 2.0.0 * @since 2.0.0
*/ */
@ConfigurationProperties(prefix = "spring.metrics.prometheus") @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; return this.enabled;
} }
public void setEnabled(boolean enabled) { public void setEnabled(Boolean enabled) {
this.enabled = enabled; this.enabled = enabled;
} }
public Boolean getDescriptions() {
return this.descriptions;
}
public void setDescriptions(Boolean descriptions) { public void setDescriptions(Boolean descriptions) {
set("descriptions", descriptions); this.descriptions = descriptions;
}
public Duration getTimerPercentilesMax() {
return this.timerPercentilesMax;
}
public void setTimerPercentilesMax(Duration timerPercentilesMax) {
this.timerPercentilesMax = timerPercentilesMax;
}
public Duration getTimerPercentilesMin() {
return this.timerPercentilesMin;
} }
@Override public void setTimerPercentilesMin(Duration timerPercentilesMin) {
public String prefix() { this.timerPercentilesMin = timerPercentilesMin;
return "spring.metrics.prometheus";
} }
} }
...@@ -14,31 +14,50 @@ ...@@ -14,31 +14,50 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.actuate.autoconfigure.metrics.export; package org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus;
import java.util.Properties; import java.time.Duration;
import org.springframework.boot.context.properties.ConfigurationProperties; import io.micrometer.prometheus.PrometheusConfig;
import org.springframework.boot.actuate.autoconfigure.metrics.export.PropertiesConfigAdapter;
/** /**
* Base {@link ConfigurationProperties} class for configuring a metrics registry. * Adapter to convert {@link PrometheusProperties} to a {@link PrometheusConfig}.
* *
* @author Jon Schneider * @author Jon Schneider
* @author Andy Wilkinson * @author Phillip Webb
* @since 2.0.0
*/ */
public abstract class RegistryProperties { class PrometheusPropertiesConfigAdapter
extends PropertiesConfigAdapter<PrometheusProperties, PrometheusConfig>
implements PrometheusConfig {
private final Properties properties = new Properties(); private static final PrometheusConfig DEFAULTS = (key) -> null;
protected abstract String prefix(); PrometheusPropertiesConfigAdapter(PrometheusProperties properties) {
super(properties, DEFAULTS);
}
@Override
public String get(String key) { public String get(String key) {
return this.properties.getProperty(key); return null;
}
@Override
public boolean descriptions() {
return get(PrometheusProperties::getDescriptions, PrometheusConfig::descriptions);
}
@Override
public Duration timerPercentilesMin() {
return get(PrometheusProperties::getTimerPercentilesMin,
PrometheusConfig::timerPercentilesMin);
} }
protected void set(String key, Object value) { @Override
this.properties.put(prefix() + "." + key, value.toString()); public Duration timerPercentilesMax() {
return get(PrometheusProperties::getTimerPercentilesMax,
PrometheusConfig::timerPercentilesMax);
} }
} }
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