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 )
48
+ after = { MetricsAutoConfiguration .class , WavefrontAutoConfiguration . class } )
49
+ @ ConditionalOnBean ({ Clock .class , WavefrontSender . class } )
54
50
@ ConditionalOnClass ({ WavefrontMeterRegistry .class , WavefrontSender .class })
55
51
@ ConditionalOnEnabledMetricsExport ("wavefront" )
56
52
@ EnableConfigurationProperties (WavefrontProperties .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
- @ Bean
66
- @ ConditionalOnMissingBean
67
- public WavefrontConfig wavefrontConfig () {
68
- return new WavefrontPropertiesConfigAdapter (this .properties );
69
- }
70
-
71
55
@ Bean
72
56
@ ConditionalOnMissingBean
73
- public WavefrontSender wavefrontSender ( WavefrontConfig wavefrontConfig ) {
74
- return createWavefrontSender ( wavefrontConfig );
57
+ public WavefrontConfig wavefrontConfig ( WavefrontProperties properties ) {
58
+ return new WavefrontPropertiesConfigAdapter ( properties );
75
59
}
76
60
77
61
@ Bean
@@ -81,14 +65,4 @@ public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig wavefrontCo
81
65
return WavefrontMeterRegistry .builder (wavefrontConfig ).clock (clock ).wavefrontSender (wavefrontSender ).build ();
82
66
}
83
67
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
68
}
0 commit comments