|
16 | 16 |
|
17 | 17 | package org.springframework.boot.actuate.autoconfigure.metrics;
|
18 | 18 |
|
19 |
| -import java.util.ArrayList; |
20 | 19 | import java.util.List;
|
21 | 20 |
|
22 | 21 | import io.micrometer.core.instrument.MeterRegistry;
|
23 |
| -import io.micrometer.core.instrument.observation.MeterObservationHandler; |
24 | 22 | import io.micrometer.core.instrument.observation.Observation.GlobalTagsProvider;
|
25 | 23 | import io.micrometer.core.instrument.observation.ObservationHandler;
|
26 |
| -import io.micrometer.core.instrument.observation.ObservationHandler.FirstMatchingCompositeObservationHandler; |
27 | 24 | import io.micrometer.core.instrument.observation.ObservationPredicate;
|
28 |
| -import io.micrometer.core.instrument.observation.TimerObservationHandler; |
29 | 25 |
|
30 | 26 | import org.springframework.boot.autoconfigure.AutoConfiguration;
|
31 | 27 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
32 | 28 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
| 29 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
33 | 30 | import org.springframework.context.annotation.Bean;
|
34 | 31 |
|
35 | 32 | /**
|
|
42 | 39 | @ConditionalOnBean(MeterRegistry.class)
|
43 | 40 | public class ObservationAutoConfiguration {
|
44 | 41 |
|
45 |
| - /** |
46 |
| - * Enables {@link TimerObservationHandler} on the {@link MeterRegistry}. |
47 |
| - * @return meter registry customizer |
48 |
| - */ |
49 | 42 | @Bean
|
50 |
| - public MeterRegistryCustomizer<MeterRegistry> enableTimerObservationHandler() { |
51 |
| - return MeterRegistry::withTimerObservationHandler; |
52 |
| - } |
53 |
| - |
54 |
| - /** |
55 |
| - * Registers {@link ObservationPredicate ObservationPredicates} into the |
56 |
| - * {@link MeterRegistry}. |
57 |
| - * @param predicates list of predicates |
58 |
| - * @return meter registry customizer |
59 |
| - */ |
60 |
| - @Bean |
61 |
| - public MeterRegistryCustomizer<MeterRegistry> registerObservationPredicates(List<ObservationPredicate> predicates) { |
62 |
| - return (registry) -> predicates |
63 |
| - .forEach((predicate) -> registry.observationConfig().observationPredicate(predicate)); |
64 |
| - } |
65 |
| - |
66 |
| - /** |
67 |
| - * Registers {@link GlobalTagsProvider GlobalTagsProviders} into the |
68 |
| - * {@link MeterRegistry}. |
69 |
| - * @param tagProviders list of tags providers |
70 |
| - * @return meter registry customizer |
71 |
| - */ |
72 |
| - @Bean |
73 |
| - public MeterRegistryCustomizer<MeterRegistry> registerGlobalTagsProvider(List<GlobalTagsProvider<?>> tagProviders) { |
74 |
| - return (registry) -> tagProviders |
75 |
| - .forEach((tagProvider) -> registry.observationConfig().tagsProvider(tagProvider)); |
76 |
| - } |
77 |
| - |
78 |
| - /** |
79 |
| - * Registers {@link ObservationHandler ObservationHandlers} into the |
80 |
| - * {@link MeterRegistry}. |
81 |
| - * @param handlers list of handlers |
82 |
| - * @return meter registry customizer |
83 |
| - */ |
84 |
| - @Bean |
85 |
| - public MeterRegistryCustomizer<MeterRegistry> registerObservationHandler(List<ObservationHandler<?>> handlers) { |
86 |
| - return (registry) -> registerObservationHandler(registry, handlers); |
87 |
| - } |
88 |
| - |
89 |
| - @SuppressWarnings("rawtypes") |
90 |
| - private void registerObservationHandler(MeterRegistry registry, List<ObservationHandler<?>> handlers) { |
91 |
| - List<ObservationHandler> meterHandlers = new ArrayList<>(); |
92 |
| - for (ObservationHandler<?> observationHandler : handlers) { |
93 |
| - if (observationHandler instanceof MeterObservationHandler) { |
94 |
| - meterHandlers.add(observationHandler); |
95 |
| - } |
96 |
| - else { |
97 |
| - registry.observationConfig().observationHandler(observationHandler); |
98 |
| - } |
99 |
| - } |
100 |
| - if (!meterHandlers.isEmpty()) { |
101 |
| - registry.observationConfig() |
102 |
| - .observationHandler(new FirstMatchingCompositeObservationHandler(meterHandlers)); |
103 |
| - } |
| 43 | + @ConditionalOnMissingBean |
| 44 | + public ObservationMeterRegistryCustomizer enableTimerObservationHandler( |
| 45 | + List<ObservationPredicate> observationPredicates, List<GlobalTagsProvider<?>> tagProviders, |
| 46 | + List<ObservationHandler<?>> observationHandlers) { |
| 47 | + return new ObservationMeterRegistryCustomizer(observationPredicates, tagProviders, observationHandlers); |
104 | 48 | }
|
105 | 49 |
|
106 | 50 | }
|
0 commit comments