|
16 | 16 |
|
17 | 17 | package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
|
18 | 18 |
|
19 |
| -import java.time.Duration; |
20 |
| - |
21 | 19 | import com.wavefront.sdk.common.WavefrontSender;
|
22 |
| -import com.wavefront.sdk.common.clients.WavefrontClient.Builder; |
23 | 20 | import io.micrometer.core.instrument.Clock;
|
24 | 21 | import io.micrometer.wavefront.WavefrontConfig;
|
25 | 22 | import io.micrometer.wavefront.WavefrontMeterRegistry;
|
|
28 | 25 | import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
29 | 26 | import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
|
30 | 27 | import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
31 |
| -import org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront.WavefrontProperties.Sender; |
| 28 | +import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontAutoConfiguration; |
| 29 | +import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties; |
32 | 30 | import org.springframework.boot.autoconfigure.AutoConfiguration;
|
33 | 31 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
34 | 32 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
35 | 33 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
36 | 34 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
37 | 35 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
38 |
| -import org.springframework.boot.context.properties.PropertyMapper; |
39 | 36 | import org.springframework.context.annotation.Bean;
|
40 |
| -import org.springframework.util.unit.DataSize; |
41 | 37 |
|
42 | 38 | /**
|
43 | 39 | * {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Wavefront.
|
|
49 | 45 | */
|
50 | 46 | @AutoConfiguration(
|
51 | 47 | before = { CompositeMeterRegistryAutoConfiguration.class, SimpleMetricsExportAutoConfiguration.class },
|
52 |
| - after = MetricsAutoConfiguration.class) |
53 |
| -@ConditionalOnBean(Clock.class) |
54 |
| -@ConditionalOnClass({ WavefrontMeterRegistry.class, WavefrontSender.class }) |
| 48 | + after = { MetricsAutoConfiguration.class, WavefrontAutoConfiguration.class }) |
| 49 | +@ConditionalOnBean({ Clock.class, WavefrontSender.class }) |
| 50 | +@ConditionalOnClass(WavefrontMeterRegistry.class) |
55 | 51 | @ConditionalOnEnabledMetricsExport("wavefront")
|
56 |
| -@EnableConfigurationProperties(WavefrontProperties.class) |
| 52 | +@EnableConfigurationProperties({ WavefrontProperties.class, WavefrontMetricsProperties.class }) |
57 | 53 | public class WavefrontMetricsExportAutoConfiguration {
|
58 | 54 |
|
59 |
| - private final WavefrontProperties properties; |
60 |
| - |
61 |
| - public WavefrontMetricsExportAutoConfiguration(WavefrontProperties properties) { |
62 |
| - this.properties = properties; |
63 |
| - } |
64 |
| - |
65 | 55 | @Bean
|
66 |
| - @ConditionalOnMissingBean |
67 |
| - public WavefrontConfig wavefrontConfig() { |
68 |
| - return new WavefrontPropertiesConfigAdapter(this.properties); |
| 56 | + WavefrontConfig wavefrontConfig(WavefrontMetricsProperties metricsProperties, WavefrontProperties properties) { |
| 57 | + return new WavefrontMetricsPropertiesConfigAdapter(properties, metricsProperties); |
69 | 58 | }
|
70 | 59 |
|
71 | 60 | @Bean
|
72 | 61 | @ConditionalOnMissingBean
|
73 |
| - public WavefrontSender wavefrontSender(WavefrontConfig wavefrontConfig) { |
74 |
| - return createWavefrontSender(wavefrontConfig); |
75 |
| - } |
76 |
| - |
77 |
| - @Bean |
78 |
| - @ConditionalOnMissingBean |
79 |
| - public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig wavefrontConfig, Clock clock, |
| 62 | + WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig wavefrontConfig, Clock clock, |
80 | 63 | WavefrontSender wavefrontSender) {
|
81 | 64 | return WavefrontMeterRegistry.builder(wavefrontConfig).clock(clock).wavefrontSender(wavefrontSender).build();
|
82 | 65 | }
|
83 | 66 |
|
84 |
| - private WavefrontSender createWavefrontSender(WavefrontConfig wavefrontConfig) { |
85 |
| - Builder builder = WavefrontMeterRegistry.getDefaultSenderBuilder(wavefrontConfig); |
86 |
| - PropertyMapper mapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); |
87 |
| - Sender sender = this.properties.getSender(); |
88 |
| - mapper.from(sender.getMaxQueueSize()).to(builder::maxQueueSize); |
89 |
| - mapper.from(sender.getFlushInterval()).asInt(Duration::getSeconds).to(builder::flushIntervalSeconds); |
90 |
| - mapper.from(sender.getMessageSize()).asInt(DataSize::toBytes).to(builder::messageSizeBytes); |
91 |
| - return builder.build(); |
92 |
| - } |
93 |
| - |
94 | 67 | }
|
0 commit comments