See gh-14780 and gh-14467
pull/14497/merge
Andy Wilkinson 6 years ago
parent 5f0d7dd6c7
commit 5e3b5ae14f

@ -16,8 +16,8 @@
package org.springframework.boot.actuate.autoconfigure.metrics; package org.springframework.boot.actuate.autoconfigure.metrics;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.MeterBinder; import io.micrometer.core.instrument.binder.MeterBinder;
@ -37,19 +37,19 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
*/ */
class MeterRegistryPostProcessor implements BeanPostProcessor { class MeterRegistryPostProcessor implements BeanPostProcessor {
private final ObjectProvider<List<MeterBinder>> meterBinders; private final ObjectProvider<MeterBinder> meterBinders;
private final ObjectProvider<List<MeterFilter>> meterFilters; private final ObjectProvider<MeterFilter> meterFilters;
private final ObjectProvider<List<MeterRegistryCustomizer<?>>> meterRegistryCustomizers; private final ObjectProvider<MeterRegistryCustomizer<?>> meterRegistryCustomizers;
private final ObjectProvider<MetricsProperties> metricsProperties; private final ObjectProvider<MetricsProperties> metricsProperties;
private volatile MeterRegistryConfigurer configurer; private volatile MeterRegistryConfigurer configurer;
MeterRegistryPostProcessor(ObjectProvider<List<MeterBinder>> meterBinders, MeterRegistryPostProcessor(ObjectProvider<MeterBinder> meterBinders,
ObjectProvider<List<MeterFilter>> meterFilters, ObjectProvider<MeterFilter> meterFilters,
ObjectProvider<List<MeterRegistryCustomizer<?>>> meterRegistryCustomizers, ObjectProvider<MeterRegistryCustomizer<?>> meterRegistryCustomizers,
ObjectProvider<MetricsProperties> metricsProperties) { ObjectProvider<MetricsProperties> metricsProperties) {
this.meterBinders = meterBinders; this.meterBinders = meterBinders;
this.meterFilters = meterFilters; this.meterFilters = meterFilters;
@ -69,12 +69,15 @@ class MeterRegistryPostProcessor implements BeanPostProcessor {
private MeterRegistryConfigurer getConfigurer() { private MeterRegistryConfigurer getConfigurer() {
if (this.configurer == null) { if (this.configurer == null) {
this.configurer = new MeterRegistryConfigurer( this.configurer = new MeterRegistryConfigurer(
this.meterBinders.getIfAvailable(Collections::emptyList), asOrderedList(this.meterBinders), asOrderedList(this.meterFilters),
this.meterFilters.getIfAvailable(Collections::emptyList), asOrderedList(this.meterRegistryCustomizers),
this.meterRegistryCustomizers.getIfAvailable(Collections::emptyList),
this.metricsProperties.getObject().isUseGlobalRegistry()); this.metricsProperties.getObject().isUseGlobalRegistry());
} }
return this.configurer; return this.configurer;
} }
private <T> List<T> asOrderedList(ObjectProvider<T> provider) {
return provider.orderedStream().collect(Collectors.toList());
}
} }

@ -16,8 +16,6 @@
package org.springframework.boot.actuate.autoconfigure.metrics; package org.springframework.boot.actuate.autoconfigure.metrics;
import java.util.List;
import io.micrometer.core.annotation.Timed; import io.micrometer.core.annotation.Timed;
import io.micrometer.core.instrument.Clock; import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.binder.MeterBinder; import io.micrometer.core.instrument.binder.MeterBinder;
@ -54,9 +52,9 @@ public class MetricsAutoConfiguration {
@Bean @Bean
public static MeterRegistryPostProcessor meterRegistryPostProcessor( public static MeterRegistryPostProcessor meterRegistryPostProcessor(
ObjectProvider<List<MeterBinder>> meterBinders, ObjectProvider<MeterBinder> meterBinders,
ObjectProvider<List<MeterFilter>> meterFilters, ObjectProvider<MeterFilter> meterFilters,
ObjectProvider<List<MeterRegistryCustomizer<?>>> meterRegistryCustomizers, ObjectProvider<MeterRegistryCustomizer<?>> meterRegistryCustomizers,
ObjectProvider<MetricsProperties> metricsProperties) { ObjectProvider<MetricsProperties> metricsProperties) {
return new MeterRegistryPostProcessor(meterBinders, meterFilters, return new MeterRegistryPostProcessor(meterBinders, meterFilters,
meterRegistryCustomizers, metricsProperties); meterRegistryCustomizers, metricsProperties);

Loading…
Cancel
Save