Browse Source

Introduce specialized interfaces in PropertiesConfigAdapter

Closes gh-47226
pull/47229/head
Moritz Halbritter 3 months ago
parent
commit
96afc3f944
  1. 7
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/appoptics/AppOpticsPropertiesConfigAdapter.java
  2. 30
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/atlas/AtlasPropertiesConfigAdapter.java
  3. 8
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/datadog/DatadogPropertiesConfigAdapter.java
  4. 22
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/dynatrace/DynatracePropertiesConfigAdapter.java
  5. 18
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/elastic/ElasticPropertiesConfigAdapter.java
  6. 14
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/ganglia/GangliaPropertiesConfigAdapter.java
  7. 18
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/graphite/GraphitePropertiesConfigAdapter.java
  8. 4
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/humio/HumioPropertiesConfigAdapter.java
  9. 22
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/influx/InfluxPropertiesConfigAdapter.java
  10. 4
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/jmx/JmxPropertiesConfigAdapter.java
  11. 4
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/kairos/KairosPropertiesConfigAdapter.java
  12. 11
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/newrelic/NewRelicPropertiesConfigAdapter.java
  13. 18
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapter.java
  14. 5
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/prometheus/PrometheusPropertiesConfigAdapter.java
  15. 51
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/properties/PropertiesConfigAdapter.java
  16. 6
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/properties/PushRegistryPropertiesConfigAdapter.java
  17. 4
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/simple/SimplePropertiesConfigAdapter.java
  18. 13
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/stackdriver/StackdriverPropertiesConfigAdapter.java
  19. 20
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/statsd/StatsdPropertiesConfigAdapter.java

7
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/appoptics/AppOpticsPropertiesConfigAdapter.java

@ -40,23 +40,22 @@ class AppOpticsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt @@ -40,23 +40,22 @@ class AppOpticsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt
@Override
public String uri() {
return getRequired(AppOpticsProperties::getUri, AppOpticsConfig.super::uri);
return obtain(AppOpticsProperties::getUri, AppOpticsConfig.super::uri);
}
@Override
public String apiToken() {
return getRequired(AppOpticsProperties::getApiToken, AppOpticsConfig.super::apiToken);
return obtain(AppOpticsProperties::getApiToken, AppOpticsConfig.super::apiToken);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String hostTag() {
return get(AppOpticsProperties::getHostTag, AppOpticsConfig.super::hostTag);
}
@Override
public boolean floorTimes() {
return getRequired(AppOpticsProperties::isFloorTimes, AppOpticsConfig.super::floorTimes);
return obtain(AppOpticsProperties::isFloorTimes, AppOpticsConfig.super::floorTimes);
}
}

30
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/atlas/AtlasPropertiesConfigAdapter.java

@ -42,77 +42,77 @@ class AtlasPropertiesConfigAdapter extends PropertiesConfigAdapter<AtlasProperti @@ -42,77 +42,77 @@ class AtlasPropertiesConfigAdapter extends PropertiesConfigAdapter<AtlasProperti
@Override
public Duration step() {
return getRequired(AtlasProperties::getStep, AtlasConfig.super::step);
return obtain(AtlasProperties::getStep, AtlasConfig.super::step);
}
@Override
public boolean enabled() {
return getRequired(AtlasProperties::isEnabled, AtlasConfig.super::enabled);
return obtain(AtlasProperties::isEnabled, AtlasConfig.super::enabled);
}
@Override
public Duration connectTimeout() {
return getRequired(AtlasProperties::getConnectTimeout, AtlasConfig.super::connectTimeout);
return obtain(AtlasProperties::getConnectTimeout, AtlasConfig.super::connectTimeout);
}
@Override
public Duration readTimeout() {
return getRequired(AtlasProperties::getReadTimeout, AtlasConfig.super::readTimeout);
return obtain(AtlasProperties::getReadTimeout, AtlasConfig.super::readTimeout);
}
@Override
public int numThreads() {
return getRequired(AtlasProperties::getNumThreads, AtlasConfig.super::numThreads);
return obtain(AtlasProperties::getNumThreads, AtlasConfig.super::numThreads);
}
@Override
public int batchSize() {
return getRequired(AtlasProperties::getBatchSize, AtlasConfig.super::batchSize);
return obtain(AtlasProperties::getBatchSize, AtlasConfig.super::batchSize);
}
@Override
public String uri() {
return getRequired(AtlasProperties::getUri, AtlasConfig.super::uri);
return obtain(AtlasProperties::getUri, AtlasConfig.super::uri);
}
@Override
public Duration meterTTL() {
return getRequired(AtlasProperties::getMeterTimeToLive, AtlasConfig.super::meterTTL);
return obtain(AtlasProperties::getMeterTimeToLive, AtlasConfig.super::meterTTL);
}
@Override
public boolean lwcEnabled() {
return getRequired(AtlasProperties::isLwcEnabled, AtlasConfig.super::lwcEnabled);
return obtain(AtlasProperties::isLwcEnabled, AtlasConfig.super::lwcEnabled);
}
@Override
public Duration lwcStep() {
return getRequired(AtlasProperties::getLwcStep, AtlasConfig.super::lwcStep);
return obtain(AtlasProperties::getLwcStep, AtlasConfig.super::lwcStep);
}
@Override
public boolean lwcIgnorePublishStep() {
return getRequired(AtlasProperties::isLwcIgnorePublishStep, AtlasConfig.super::lwcIgnorePublishStep);
return obtain(AtlasProperties::isLwcIgnorePublishStep, AtlasConfig.super::lwcIgnorePublishStep);
}
@Override
public Duration configRefreshFrequency() {
return getRequired(AtlasProperties::getConfigRefreshFrequency, AtlasConfig.super::configRefreshFrequency);
return obtain(AtlasProperties::getConfigRefreshFrequency, AtlasConfig.super::configRefreshFrequency);
}
@Override
public Duration configTTL() {
return getRequired(AtlasProperties::getConfigTimeToLive, AtlasConfig.super::configTTL);
return obtain(AtlasProperties::getConfigTimeToLive, AtlasConfig.super::configTTL);
}
@Override
public String configUri() {
return getRequired(AtlasProperties::getConfigUri, AtlasConfig.super::configUri);
return obtain(AtlasProperties::getConfigUri, AtlasConfig.super::configUri);
}
@Override
public String evalUri() {
return getRequired(AtlasProperties::getEvalUri, AtlasConfig.super::evalUri);
return obtain(AtlasProperties::getEvalUri, AtlasConfig.super::evalUri);
}
}

8
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/datadog/DatadogPropertiesConfigAdapter.java

@ -41,29 +41,27 @@ class DatadogPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter @@ -41,29 +41,27 @@ class DatadogPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter
@Override
public String apiKey() {
return getRequired(DatadogProperties::getApiKey, DatadogConfig.super::apiKey);
return obtain(DatadogProperties::getApiKey, DatadogConfig.super::apiKey);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String applicationKey() {
return get(DatadogProperties::getApplicationKey, DatadogConfig.super::applicationKey);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String hostTag() {
return get(DatadogProperties::getHostTag, DatadogConfig.super::hostTag);
}
@Override
public String uri() {
return getRequired(DatadogProperties::getUri, DatadogConfig.super::uri);
return obtain(DatadogProperties::getUri, DatadogConfig.super::uri);
}
@Override
public boolean descriptions() {
return getRequired(DatadogProperties::isDescriptions, DatadogConfig.super::descriptions);
return obtain(DatadogProperties::isDescriptions, DatadogConfig.super::descriptions);
}
}

22
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/dynatrace/DynatracePropertiesConfigAdapter.java

@ -46,60 +46,58 @@ class DynatracePropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt @@ -46,60 +46,58 @@ class DynatracePropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt
@Override
public String apiToken() {
return getRequired(DynatraceProperties::getApiToken, DynatraceConfig.super::apiToken);
return obtain(DynatraceProperties::getApiToken, DynatraceConfig.super::apiToken);
}
@Override
public String deviceId() {
return getRequired(v1(V1::getDeviceId), DynatraceConfig.super::deviceId);
return obtain(v1(V1::getDeviceId), DynatraceConfig.super::deviceId);
}
@Override
public String technologyType() {
return getRequired(v1(V1::getTechnologyType), DynatraceConfig.super::technologyType);
return obtain(v1(V1::getTechnologyType), DynatraceConfig.super::technologyType);
}
@Override
public String uri() {
return getRequired(DynatraceProperties::getUri, DynatraceConfig.super::uri);
return obtain(DynatraceProperties::getUri, DynatraceConfig.super::uri);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String group() {
return get(v1(V1::getGroup), DynatraceConfig.super::group);
}
@Override
public DynatraceApiVersion apiVersion() {
return getRequired((properties) -> (properties.getV1().getDeviceId() != null) ? DynatraceApiVersion.V1
return obtain((properties) -> (properties.getV1().getDeviceId() != null) ? DynatraceApiVersion.V1
: DynatraceApiVersion.V2, DynatraceConfig.super::apiVersion);
}
@Override
public String metricKeyPrefix() {
return getRequired(v2(V2::getMetricKeyPrefix), DynatraceConfig.super::metricKeyPrefix);
return obtain(v2(V2::getMetricKeyPrefix), DynatraceConfig.super::metricKeyPrefix);
}
@Override
public Map<String, String> defaultDimensions() {
return getRequired(v2(V2::getDefaultDimensions), DynatraceConfig.super::defaultDimensions);
return obtain(v2(V2::getDefaultDimensions), DynatraceConfig.super::defaultDimensions);
}
@Override
public boolean enrichWithDynatraceMetadata() {
return getRequired(v2(V2::isEnrichWithDynatraceMetadata), DynatraceConfig.super::enrichWithDynatraceMetadata);
return obtain(v2(V2::isEnrichWithDynatraceMetadata), DynatraceConfig.super::enrichWithDynatraceMetadata);
}
@Override
public boolean useDynatraceSummaryInstruments() {
return getRequired(v2(V2::isUseDynatraceSummaryInstruments),
DynatraceConfig.super::useDynatraceSummaryInstruments);
return obtain(v2(V2::isUseDynatraceSummaryInstruments), DynatraceConfig.super::useDynatraceSummaryInstruments);
}
@Override
public boolean exportMeterMetadata() {
return getRequired(v2(V2::isExportMeterMetadata), DynatraceConfig.super::exportMeterMetadata);
return obtain(v2(V2::isExportMeterMetadata), DynatraceConfig.super::exportMeterMetadata);
}
private <V> Getter<DynatraceProperties, V> v1(Getter<V1, V> getter) {

18
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/elastic/ElasticPropertiesConfigAdapter.java

@ -40,61 +40,57 @@ class ElasticPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter @@ -40,61 +40,57 @@ class ElasticPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter
@Override
public String host() {
return getRequired(ElasticProperties::getHost, ElasticConfig.super::host);
return obtain(ElasticProperties::getHost, ElasticConfig.super::host);
}
@Override
public String index() {
return getRequired(ElasticProperties::getIndex, ElasticConfig.super::index);
return obtain(ElasticProperties::getIndex, ElasticConfig.super::index);
}
@Override
public String indexDateFormat() {
return getRequired(ElasticProperties::getIndexDateFormat, ElasticConfig.super::indexDateFormat);
return obtain(ElasticProperties::getIndexDateFormat, ElasticConfig.super::indexDateFormat);
}
@Override
public String indexDateSeparator() {
return getRequired(ElasticProperties::getIndexDateSeparator, ElasticConfig.super::indexDateSeparator);
return obtain(ElasticProperties::getIndexDateSeparator, ElasticConfig.super::indexDateSeparator);
}
@Override
public String timestampFieldName() {
return getRequired(ElasticProperties::getTimestampFieldName, ElasticConfig.super::timestampFieldName);
return obtain(ElasticProperties::getTimestampFieldName, ElasticConfig.super::timestampFieldName);
}
@Override
public boolean autoCreateIndex() {
return getRequired(ElasticProperties::isAutoCreateIndex, ElasticConfig.super::autoCreateIndex);
return obtain(ElasticProperties::isAutoCreateIndex, ElasticConfig.super::autoCreateIndex);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String userName() {
return get(ElasticProperties::getUserName, ElasticConfig.super::userName);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String password() {
return get(ElasticProperties::getPassword, ElasticConfig.super::password);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String pipeline() {
return get(ElasticProperties::getPipeline, ElasticConfig.super::pipeline);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String apiKeyCredentials() {
return get(ElasticProperties::getApiKeyCredentials, ElasticConfig.super::apiKeyCredentials);
}
@Override
public boolean enableSource() {
return getRequired(ElasticProperties::isEnableSource, ElasticConfig.super::enableSource);
return obtain(ElasticProperties::isEnableSource, ElasticConfig.super::enableSource);
}
}

14
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/ganglia/GangliaPropertiesConfigAdapter.java

@ -49,37 +49,37 @@ class GangliaPropertiesConfigAdapter extends PropertiesConfigAdapter<GangliaProp @@ -49,37 +49,37 @@ class GangliaPropertiesConfigAdapter extends PropertiesConfigAdapter<GangliaProp
@Override
public boolean enabled() {
return getRequired(GangliaProperties::isEnabled, GangliaConfig.super::enabled);
return obtain(GangliaProperties::isEnabled, GangliaConfig.super::enabled);
}
@Override
public Duration step() {
return getRequired(GangliaProperties::getStep, GangliaConfig.super::step);
return obtain(GangliaProperties::getStep, GangliaConfig.super::step);
}
@Override
public TimeUnit durationUnits() {
return getRequired(GangliaProperties::getDurationUnits, GangliaConfig.super::durationUnits);
return obtain(GangliaProperties::getDurationUnits, GangliaConfig.super::durationUnits);
}
@Override
public GMetric.UDPAddressingMode addressingMode() {
return getRequired(GangliaProperties::getAddressingMode, GangliaConfig.super::addressingMode);
return obtain(GangliaProperties::getAddressingMode, GangliaConfig.super::addressingMode);
}
@Override
public int ttl() {
return getRequired(GangliaProperties::getTimeToLive, GangliaConfig.super::ttl);
return obtain(GangliaProperties::getTimeToLive, GangliaConfig.super::ttl);
}
@Override
public String host() {
return getRequired(GangliaProperties::getHost, GangliaConfig.super::host);
return obtain(GangliaProperties::getHost, GangliaConfig.super::host);
}
@Override
public int port() {
return getRequired(GangliaProperties::getPort, GangliaConfig.super::port);
return obtain(GangliaProperties::getPort, GangliaConfig.super::port);
}
}

18
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/graphite/GraphitePropertiesConfigAdapter.java

@ -49,47 +49,47 @@ class GraphitePropertiesConfigAdapter extends PropertiesConfigAdapter<GraphitePr @@ -49,47 +49,47 @@ class GraphitePropertiesConfigAdapter extends PropertiesConfigAdapter<GraphitePr
@Override
public boolean enabled() {
return getRequired(GraphiteProperties::isEnabled, GraphiteConfig.super::enabled);
return obtain(GraphiteProperties::isEnabled, GraphiteConfig.super::enabled);
}
@Override
public Duration step() {
return getRequired(GraphiteProperties::getStep, GraphiteConfig.super::step);
return obtain(GraphiteProperties::getStep, GraphiteConfig.super::step);
}
@Override
public TimeUnit rateUnits() {
return getRequired(GraphiteProperties::getRateUnits, GraphiteConfig.super::rateUnits);
return obtain(GraphiteProperties::getRateUnits, GraphiteConfig.super::rateUnits);
}
@Override
public TimeUnit durationUnits() {
return getRequired(GraphiteProperties::getDurationUnits, GraphiteConfig.super::durationUnits);
return obtain(GraphiteProperties::getDurationUnits, GraphiteConfig.super::durationUnits);
}
@Override
public String host() {
return getRequired(GraphiteProperties::getHost, GraphiteConfig.super::host);
return obtain(GraphiteProperties::getHost, GraphiteConfig.super::host);
}
@Override
public int port() {
return getRequired(GraphiteProperties::getPort, GraphiteConfig.super::port);
return obtain(GraphiteProperties::getPort, GraphiteConfig.super::port);
}
@Override
public GraphiteProtocol protocol() {
return getRequired(GraphiteProperties::getProtocol, GraphiteConfig.super::protocol);
return obtain(GraphiteProperties::getProtocol, GraphiteConfig.super::protocol);
}
@Override
public boolean graphiteTagsEnabled() {
return getRequired(GraphiteProperties::getGraphiteTagsEnabled, GraphiteConfig.super::graphiteTagsEnabled);
return obtain(GraphiteProperties::getGraphiteTagsEnabled, GraphiteConfig.super::graphiteTagsEnabled);
}
@Override
public String[] tagsAsPrefix() {
return getRequired(GraphiteProperties::getTagsAsPrefix, GraphiteConfig.super::tagsAsPrefix);
return obtain(GraphiteProperties::getTagsAsPrefix, GraphiteConfig.super::tagsAsPrefix);
}
}

4
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/humio/HumioPropertiesConfigAdapter.java

@ -46,17 +46,15 @@ class HumioPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<H @@ -46,17 +46,15 @@ class HumioPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<H
@Override
public String uri() {
return getRequired(HumioProperties::getUri, HumioConfig.super::uri);
return obtain(HumioProperties::getUri, HumioConfig.super::uri);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable Map<String, String> tags() {
return get(HumioProperties::getTags, HumioConfig.super::tags);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String apiToken() {
return get(HumioProperties::getApiToken, HumioConfig.super::apiToken);
}

22
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/influx/InfluxPropertiesConfigAdapter.java

@ -43,83 +43,75 @@ class InfluxPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter< @@ -43,83 +43,75 @@ class InfluxPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<
@Override
public String db() {
return getRequired(InfluxProperties::getDb, InfluxConfig.super::db);
return obtain(InfluxProperties::getDb, InfluxConfig.super::db);
}
@Override
public InfluxConsistency consistency() {
return getRequired(InfluxProperties::getConsistency, InfluxConfig.super::consistency);
return obtain(InfluxProperties::getConsistency, InfluxConfig.super::consistency);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String userName() {
return get(InfluxProperties::getUserName, InfluxConfig.super::userName);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String password() {
return get(InfluxProperties::getPassword, InfluxConfig.super::password);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String retentionPolicy() {
return get(InfluxProperties::getRetentionPolicy, InfluxConfig.super::retentionPolicy);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable Integer retentionReplicationFactor() {
return get(InfluxProperties::getRetentionReplicationFactor, InfluxConfig.super::retentionReplicationFactor);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String retentionDuration() {
return get(InfluxProperties::getRetentionDuration, InfluxConfig.super::retentionDuration);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String retentionShardDuration() {
return get(InfluxProperties::getRetentionShardDuration, InfluxConfig.super::retentionShardDuration);
}
@Override
public String uri() {
return getRequired(InfluxProperties::getUri, InfluxConfig.super::uri);
return obtain(InfluxProperties::getUri, InfluxConfig.super::uri);
}
@Override
public boolean compressed() {
return getRequired(InfluxProperties::isCompressed, InfluxConfig.super::compressed);
return obtain(InfluxProperties::isCompressed, InfluxConfig.super::compressed);
}
@Override
public boolean autoCreateDb() {
return getRequired(InfluxProperties::isAutoCreateDb, InfluxConfig.super::autoCreateDb);
return obtain(InfluxProperties::isAutoCreateDb, InfluxConfig.super::autoCreateDb);
}
@Override
public InfluxApiVersion apiVersion() {
return getRequired(InfluxProperties::getApiVersion, InfluxConfig.super::apiVersion);
return obtain(InfluxProperties::getApiVersion, InfluxConfig.super::apiVersion);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String org() {
return get(InfluxProperties::getOrg, InfluxConfig.super::org);
}
@Override
public String bucket() {
return getRequired(InfluxProperties::getBucket, InfluxConfig.super::bucket);
return obtain(InfluxProperties::getBucket, InfluxConfig.super::bucket);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String token() {
return get(InfluxProperties::getToken, InfluxConfig.super::token);
}

4
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/jmx/JmxPropertiesConfigAdapter.java

@ -47,12 +47,12 @@ class JmxPropertiesConfigAdapter extends PropertiesConfigAdapter<JmxProperties> @@ -47,12 +47,12 @@ class JmxPropertiesConfigAdapter extends PropertiesConfigAdapter<JmxProperties>
@Override
public String domain() {
return getRequired(JmxProperties::getDomain, JmxConfig.super::domain);
return obtain(JmxProperties::getDomain, JmxConfig.super::domain);
}
@Override
public Duration step() {
return getRequired(JmxProperties::getStep, JmxConfig.super::step);
return obtain(JmxProperties::getStep, JmxConfig.super::step);
}
}

4
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/kairos/KairosPropertiesConfigAdapter.java

@ -40,17 +40,15 @@ class KairosPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter< @@ -40,17 +40,15 @@ class KairosPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<
@Override
public String uri() {
return getRequired(KairosProperties::getUri, KairosConfig.super::uri);
return obtain(KairosProperties::getUri, KairosConfig.super::uri);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String userName() {
return get(KairosProperties::getUserName, KairosConfig.super::userName);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String password() {
return get(KairosProperties::getPassword, KairosConfig.super::password);
}

11
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/newrelic/NewRelicPropertiesConfigAdapter.java

@ -43,35 +43,32 @@ public class NewRelicPropertiesConfigAdapter extends StepRegistryPropertiesConfi @@ -43,35 +43,32 @@ public class NewRelicPropertiesConfigAdapter extends StepRegistryPropertiesConfi
@Override
public boolean meterNameEventTypeEnabled() {
return getRequired(NewRelicProperties::isMeterNameEventTypeEnabled,
NewRelicConfig.super::meterNameEventTypeEnabled);
return obtain(NewRelicProperties::isMeterNameEventTypeEnabled, NewRelicConfig.super::meterNameEventTypeEnabled);
}
@Override
public String eventType() {
return getRequired(NewRelicProperties::getEventType, NewRelicConfig.super::eventType);
return obtain(NewRelicProperties::getEventType, NewRelicConfig.super::eventType);
}
@Override
public ClientProviderType clientProviderType() {
return getRequired(NewRelicProperties::getClientProviderType, NewRelicConfig.super::clientProviderType);
return obtain(NewRelicProperties::getClientProviderType, NewRelicConfig.super::clientProviderType);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String apiKey() {
return get(NewRelicProperties::getApiKey, NewRelicConfig.super::apiKey);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable String accountId() {
return get(NewRelicProperties::getAccountId, NewRelicConfig.super::accountId);
}
@Override
public String uri() {
return getRequired(NewRelicProperties::getUri, NewRelicConfig.super::uri);
return obtain(NewRelicProperties::getUri, NewRelicConfig.super::uri);
}
}

18
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapter.java

@ -64,12 +64,12 @@ class OtlpMetricsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAda @@ -64,12 +64,12 @@ class OtlpMetricsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAda
@Override
public String url() {
return getRequired((properties) -> this.connectionDetails.getUrl(), OtlpConfig.super::url);
return obtain((properties) -> this.connectionDetails.getUrl(), OtlpConfig.super::url);
}
@Override
public AggregationTemporality aggregationTemporality() {
return getRequired(OtlpMetricsProperties::getAggregationTemporality, OtlpConfig.super::aggregationTemporality);
return obtain(OtlpMetricsProperties::getAggregationTemporality, OtlpConfig.super::aggregationTemporality);
}
@Override
@ -82,37 +82,37 @@ class OtlpMetricsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAda @@ -82,37 +82,37 @@ class OtlpMetricsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAda
@Override
public Map<String, String> headers() {
return getRequired(OtlpMetricsProperties::getHeaders, OtlpConfig.super::headers);
return obtain(OtlpMetricsProperties::getHeaders, OtlpConfig.super::headers);
}
@Override
public HistogramFlavor histogramFlavor() {
return getRequired(OtlpMetricsProperties::getHistogramFlavor, OtlpConfig.super::histogramFlavor);
return obtain(OtlpMetricsProperties::getHistogramFlavor, OtlpConfig.super::histogramFlavor);
}
@Override
public Map<String, HistogramFlavor> histogramFlavorPerMeter() {
return getRequired(perMeter(Meter::getHistogramFlavor), OtlpConfig.super::histogramFlavorPerMeter);
return obtain(perMeter(Meter::getHistogramFlavor), OtlpConfig.super::histogramFlavorPerMeter);
}
@Override
public Map<String, Integer> maxBucketsPerMeter() {
return getRequired(perMeter(Meter::getMaxBucketCount), OtlpConfig.super::maxBucketsPerMeter);
return obtain(perMeter(Meter::getMaxBucketCount), OtlpConfig.super::maxBucketsPerMeter);
}
@Override
public int maxScale() {
return getRequired(OtlpMetricsProperties::getMaxScale, OtlpConfig.super::maxScale);
return obtain(OtlpMetricsProperties::getMaxScale, OtlpConfig.super::maxScale);
}
@Override
public int maxBucketCount() {
return getRequired(OtlpMetricsProperties::getMaxBucketCount, OtlpConfig.super::maxBucketCount);
return obtain(OtlpMetricsProperties::getMaxBucketCount, OtlpConfig.super::maxBucketCount);
}
@Override
public TimeUnit baseTimeUnit() {
return getRequired(OtlpMetricsProperties::getBaseTimeUnit, OtlpConfig.super::baseTimeUnit);
return obtain(OtlpMetricsProperties::getBaseTimeUnit, OtlpConfig.super::baseTimeUnit);
}
private <V> Getter<OtlpMetricsProperties, Map<String, V>> perMeter(Getter<Meter, V> getter) {

5
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/prometheus/PrometheusPropertiesConfigAdapter.java

@ -50,16 +50,15 @@ class PrometheusPropertiesConfigAdapter extends PropertiesConfigAdapter<Promethe @@ -50,16 +50,15 @@ class PrometheusPropertiesConfigAdapter extends PropertiesConfigAdapter<Promethe
@Override
public boolean descriptions() {
return getRequired(PrometheusProperties::isDescriptions, PrometheusConfig.super::descriptions);
return obtain(PrometheusProperties::isDescriptions, PrometheusConfig.super::descriptions);
}
@Override
public Duration step() {
return getRequired(PrometheusProperties::getStep, PrometheusConfig.super::step);
return obtain(PrometheusProperties::getStep, PrometheusConfig.super::step);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public @Nullable Properties prometheusProperties() {
return get(this::fromPropertiesMap, PrometheusConfig.super::prometheusProperties);
}

51
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/properties/PropertiesConfigAdapter.java

@ -16,8 +16,6 @@ @@ -16,8 +16,6 @@
package org.springframework.boot.micrometer.metrics.autoconfigure.export.properties;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
@ -28,6 +26,7 @@ import org.springframework.util.Assert; @@ -28,6 +26,7 @@ import org.springframework.util.Assert;
* @param <T> the properties type
* @author Phillip Webb
* @author Nikolay Rybak
* @author Moritz Halbritter
* @since 4.0.0
*/
public class PropertiesConfigAdapter<T> {
@ -50,7 +49,7 @@ public class PropertiesConfigAdapter<T> { @@ -50,7 +49,7 @@ public class PropertiesConfigAdapter<T> {
* @param <V> the value type
* @return the property or fallback value
*/
protected final <V> @Nullable V get(Getter<T, V> getter, Supplier<@Nullable V> fallback) {
protected final <V> @Nullable V get(Getter<T, V> getter, Fallback<V> fallback) {
V value = getter.get(this.properties);
return (value != null) ? value : fallback.get();
}
@ -62,7 +61,7 @@ public class PropertiesConfigAdapter<T> { @@ -62,7 +61,7 @@ public class PropertiesConfigAdapter<T> {
* @param <V> the value type
* @return the property or fallback value
*/
protected final <V> V getRequired(Getter<T, V> getter, Supplier<V> fallback) {
protected final <V> V obtain(Getter<T, V> getter, RequiredFallback<V> fallback) {
V value = getter.get(this.properties);
if (value != null) {
return value;
@ -72,10 +71,54 @@ public class PropertiesConfigAdapter<T> { @@ -72,10 +71,54 @@ public class PropertiesConfigAdapter<T> {
return fallbackValue;
}
/**
* Gets a value from the given properties.
*
* @param <T> the type of the properties
* @param <V> the type of the value
*/
@FunctionalInterface
protected interface Getter<T, V> {
/**
* Gets a value from the given properties.
* @param properties the properties
* @return the value or {@code null}
*/
@Nullable V get(T properties);
}
/**
* Gets the fallback value, if any.
*
* @param <V> the type of the value
*/
@FunctionalInterface
protected interface Fallback<V> {
/**
* Gets the fallback value, if any.
* @return the value or {@code null}
*/
@Nullable V get();
}
/**
* Gets the fallback value.
*
* @param <V> the type of the value
*/
@FunctionalInterface
protected interface RequiredFallback<V> {
/**
* Gets the fallback value.
* @return the value
*/
V get();
}
}

6
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/properties/PushRegistryPropertiesConfigAdapter.java

@ -44,17 +44,17 @@ public abstract class PushRegistryPropertiesConfigAdapter<T extends PushRegistry @@ -44,17 +44,17 @@ public abstract class PushRegistryPropertiesConfigAdapter<T extends PushRegistry
@Override
public Duration step() {
return getRequired(T::getStep, PushRegistryConfig.super::step);
return obtain(T::getStep, PushRegistryConfig.super::step);
}
@Override
public boolean enabled() {
return getRequired(T::isEnabled, PushRegistryConfig.super::enabled);
return obtain(T::isEnabled, PushRegistryConfig.super::enabled);
}
@Override
public int batchSize() {
return getRequired(T::getBatchSize, PushRegistryConfig.super::batchSize);
return obtain(T::getBatchSize, PushRegistryConfig.super::batchSize);
}
}

4
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/simple/SimplePropertiesConfigAdapter.java

@ -48,12 +48,12 @@ public class SimplePropertiesConfigAdapter extends PropertiesConfigAdapter<Simpl @@ -48,12 +48,12 @@ public class SimplePropertiesConfigAdapter extends PropertiesConfigAdapter<Simpl
@Override
public Duration step() {
return getRequired(SimpleProperties::getStep, SimpleConfig.super::step);
return obtain(SimpleProperties::getStep, SimpleConfig.super::step);
}
@Override
public CountingMode mode() {
return getRequired(SimpleProperties::getMode, SimpleConfig.super::mode);
return obtain(SimpleProperties::getMode, SimpleConfig.super::mode);
}
}

13
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/stackdriver/StackdriverPropertiesConfigAdapter.java

@ -42,33 +42,32 @@ public class StackdriverPropertiesConfigAdapter extends StepRegistryPropertiesCo @@ -42,33 +42,32 @@ public class StackdriverPropertiesConfigAdapter extends StepRegistryPropertiesCo
@Override
public String projectId() {
return getRequired(StackdriverProperties::getProjectId, StackdriverConfig.super::projectId);
return obtain(StackdriverProperties::getProjectId, StackdriverConfig.super::projectId);
}
@Override
public String resourceType() {
return getRequired(StackdriverProperties::getResourceType, StackdriverConfig.super::resourceType);
return obtain(StackdriverProperties::getResourceType, StackdriverConfig.super::resourceType);
}
@Override
public Map<String, String> resourceLabels() {
return getRequired(StackdriverProperties::getResourceLabels, StackdriverConfig.super::resourceLabels);
return obtain(StackdriverProperties::getResourceLabels, StackdriverConfig.super::resourceLabels);
}
@Override
public boolean useSemanticMetricTypes() {
return getRequired(StackdriverProperties::isUseSemanticMetricTypes,
StackdriverConfig.super::useSemanticMetricTypes);
return obtain(StackdriverProperties::isUseSemanticMetricTypes, StackdriverConfig.super::useSemanticMetricTypes);
}
@Override
public String metricTypePrefix() {
return getRequired(StackdriverProperties::getMetricTypePrefix, StackdriverConfig.super::metricTypePrefix);
return obtain(StackdriverProperties::getMetricTypePrefix, StackdriverConfig.super::metricTypePrefix);
}
@Override
public boolean autoCreateMetricDescriptors() {
return getRequired(StackdriverProperties::isAutoCreateMetricDescriptors,
return obtain(StackdriverProperties::isAutoCreateMetricDescriptors,
StackdriverConfig.super::autoCreateMetricDescriptors);
}

20
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/statsd/StatsdPropertiesConfigAdapter.java

@ -49,52 +49,52 @@ public class StatsdPropertiesConfigAdapter extends PropertiesConfigAdapter<Stats @@ -49,52 +49,52 @@ public class StatsdPropertiesConfigAdapter extends PropertiesConfigAdapter<Stats
@Override
public StatsdFlavor flavor() {
return getRequired(StatsdProperties::getFlavor, StatsdConfig.super::flavor);
return obtain(StatsdProperties::getFlavor, StatsdConfig.super::flavor);
}
@Override
public boolean enabled() {
return getRequired(StatsdProperties::isEnabled, StatsdConfig.super::enabled);
return obtain(StatsdProperties::isEnabled, StatsdConfig.super::enabled);
}
@Override
public String host() {
return getRequired(StatsdProperties::getHost, StatsdConfig.super::host);
return obtain(StatsdProperties::getHost, StatsdConfig.super::host);
}
@Override
public int port() {
return getRequired(StatsdProperties::getPort, StatsdConfig.super::port);
return obtain(StatsdProperties::getPort, StatsdConfig.super::port);
}
@Override
public StatsdProtocol protocol() {
return getRequired(StatsdProperties::getProtocol, StatsdConfig.super::protocol);
return obtain(StatsdProperties::getProtocol, StatsdConfig.super::protocol);
}
@Override
public int maxPacketLength() {
return getRequired(StatsdProperties::getMaxPacketLength, StatsdConfig.super::maxPacketLength);
return obtain(StatsdProperties::getMaxPacketLength, StatsdConfig.super::maxPacketLength);
}
@Override
public Duration pollingFrequency() {
return getRequired(StatsdProperties::getPollingFrequency, StatsdConfig.super::pollingFrequency);
return obtain(StatsdProperties::getPollingFrequency, StatsdConfig.super::pollingFrequency);
}
@Override
public Duration step() {
return getRequired(StatsdProperties::getStep, StatsdConfig.super::step);
return obtain(StatsdProperties::getStep, StatsdConfig.super::step);
}
@Override
public boolean publishUnchangedMeters() {
return getRequired(StatsdProperties::isPublishUnchangedMeters, StatsdConfig.super::publishUnchangedMeters);
return obtain(StatsdProperties::isPublishUnchangedMeters, StatsdConfig.super::publishUnchangedMeters);
}
@Override
public boolean buffered() {
return getRequired(StatsdProperties::isBuffered, StatsdConfig.super::buffered);
return obtain(StatsdProperties::isBuffered, StatsdConfig.super::buffered);
}
}

Loading…
Cancel
Save