1616
1717package org .springframework .boot .actuate .autoconfigure .metrics .export .wavefront ;
1818
19- import java .time .Duration ;
20-
2119import com .wavefront .sdk .common .WavefrontSender ;
22- import com .wavefront .sdk .common .clients .WavefrontClient .Builder ;
2320import io .micrometer .core .instrument .Clock ;
2421import io .micrometer .wavefront .WavefrontConfig ;
2522import io .micrometer .wavefront .WavefrontMeterRegistry ;
2825import org .springframework .boot .actuate .autoconfigure .metrics .MetricsAutoConfiguration ;
2926import org .springframework .boot .actuate .autoconfigure .metrics .export .ConditionalOnEnabledMetricsExport ;
3027import 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 ;
3230import org .springframework .boot .autoconfigure .AutoConfiguration ;
3331import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
3432import org .springframework .boot .autoconfigure .condition .ConditionalOnBean ;
3533import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
3634import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
3735import org .springframework .boot .context .properties .EnableConfigurationProperties ;
38- import org .springframework .boot .context .properties .PropertyMapper ;
3936import org .springframework .context .annotation .Bean ;
40- import org .springframework .util .unit .DataSize ;
4137
4238/**
4339 * {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Wavefront.
4945 */
5046@ AutoConfiguration (
5147 before = { CompositeMeterRegistryAutoConfiguration .class , SimpleMetricsExportAutoConfiguration .class },
52- after = MetricsAutoConfiguration .class )
53- @ ConditionalOnBean (Clock .class )
48+ after = { MetricsAutoConfiguration .class , WavefrontAutoConfiguration . class } )
49+ @ ConditionalOnBean ({ Clock .class , WavefrontSender . class } )
5450@ ConditionalOnClass ({ WavefrontMeterRegistry .class , WavefrontSender .class })
5551@ ConditionalOnEnabledMetricsExport ("wavefront" )
5652@ EnableConfigurationProperties (WavefrontProperties .class )
5753public class WavefrontMetricsExportAutoConfiguration {
5854
59- private final WavefrontProperties properties ;
60-
61- public WavefrontMetricsExportAutoConfiguration (WavefrontProperties properties ) {
62- this .properties = properties ;
63- }
64-
65- @ Bean
66- @ ConditionalOnMissingBean
67- public WavefrontConfig wavefrontConfig () {
68- return new WavefrontPropertiesConfigAdapter (this .properties );
69- }
70-
7155 @ Bean
7256 @ ConditionalOnMissingBean
73- public WavefrontSender wavefrontSender ( WavefrontConfig wavefrontConfig ) {
74- return createWavefrontSender ( wavefrontConfig );
57+ public WavefrontConfig wavefrontConfig ( WavefrontProperties properties ) {
58+ return new WavefrontPropertiesConfigAdapter ( properties );
7559 }
7660
7761 @ Bean
@@ -81,14 +65,4 @@ public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig wavefrontCo
8165 return WavefrontMeterRegistry .builder (wavefrontConfig ).clock (clock ).wavefrontSender (wavefrontSender ).build ();
8266 }
8367
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-
9468}
0 commit comments