Skip to content

Commit 276c09e

Browse files
committed
Move wavefront properties to management.wavefront
- Settings moved from management.metrics.export.wavefront to management.wavefront.metrics and management.wavefront - WavefrontSender is created by WavefrontAutoConfiguration and is used by the tracing and metrics auto-configurations - Users can no longer supply a WavefrontConfig bean. WavefrontConfig comes from micrometer-core and was used to build the WavefrontSender. The WavefrontSender is used by tracing, which doesn't rely on micrometer-core. The sender can be configured as usual through properties See spring-projectsgh-30156
1 parent 24ee49b commit 276c09e

15 files changed

+403
-273
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfiguration.java

+9-36
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
1818

19-
import java.time.Duration;
20-
2119
import com.wavefront.sdk.common.WavefrontSender;
22-
import com.wavefront.sdk.common.clients.WavefrontClient.Builder;
2320
import io.micrometer.core.instrument.Clock;
2421
import io.micrometer.wavefront.WavefrontConfig;
2522
import io.micrometer.wavefront.WavefrontMeterRegistry;
@@ -28,16 +25,15 @@
2825
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
2926
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
3027
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;
3230
import org.springframework.boot.autoconfigure.AutoConfiguration;
3331
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
3432
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
3533
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
3634
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3735
import org.springframework.boot.context.properties.EnableConfigurationProperties;
38-
import org.springframework.boot.context.properties.PropertyMapper;
3936
import org.springframework.context.annotation.Bean;
40-
import org.springframework.util.unit.DataSize;
4137

4238
/**
4339
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Wavefront.
@@ -49,46 +45,23 @@
4945
*/
5046
@AutoConfiguration(
5147
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)
5551
@ConditionalOnEnabledMetricsExport("wavefront")
56-
@EnableConfigurationProperties(WavefrontProperties.class)
52+
@EnableConfigurationProperties({ WavefrontProperties.class, WavefrontMetricsProperties.class })
5753
public class WavefrontMetricsExportAutoConfiguration {
5854

59-
private final WavefrontProperties properties;
60-
61-
public WavefrontMetricsExportAutoConfiguration(WavefrontProperties properties) {
62-
this.properties = properties;
63-
}
64-
6555
@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);
6958
}
7059

7160
@Bean
7261
@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,
8063
WavefrontSender wavefrontSender) {
8164
return WavefrontMeterRegistry.builder(wavefrontConfig).clock(clock).wavefrontSender(wavefrontSender).build();
8265
}
8366

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-
9467
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
18+
19+
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PushRegistryProperties;
20+
import org.springframework.boot.context.properties.ConfigurationProperties;
21+
22+
/**
23+
* {@link ConfigurationProperties @ConfigurationProperties} for configuring Wavefront
24+
* metrics export.
25+
*
26+
* @author Jon Schneider
27+
* @author Stephane Nicoll
28+
* @author Moritz Halbritter
29+
* @since 2.0.0
30+
*/
31+
@ConfigurationProperties("management.wavefront.metrics")
32+
public class WavefrontMetricsProperties extends PushRegistryProperties {
33+
34+
/**
35+
* Global prefix to separate metrics originating from this app's white box
36+
* instrumentation from those originating from other Wavefront integrations when
37+
* viewed in the Wavefront UI.
38+
*/
39+
private String globalPrefix;
40+
41+
public String getGlobalPrefix() {
42+
return this.globalPrefix;
43+
}
44+
45+
public void setGlobalPrefix(String globalPrefix) {
46+
this.globalPrefix = globalPrefix;
47+
}
48+
49+
}
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,24 @@
1919
import io.micrometer.wavefront.WavefrontConfig;
2020

2121
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PushRegistryPropertiesConfigAdapter;
22+
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties;
2223

2324
/**
24-
* Adapter to convert {@link WavefrontProperties} to a {@link WavefrontConfig}.
25+
* Adapter to convert {@link WavefrontMetricsProperties} to a {@link WavefrontConfig}.
2526
*
2627
* @author Jon Schneider
28+
* @author Moritz Halbritter
2729
* @since 2.0.0
2830
*/
29-
public class WavefrontPropertiesConfigAdapter extends PushRegistryPropertiesConfigAdapter<WavefrontProperties>
30-
implements WavefrontConfig {
31+
public class WavefrontMetricsPropertiesConfigAdapter
32+
extends PushRegistryPropertiesConfigAdapter<WavefrontMetricsProperties> implements WavefrontConfig {
3133

32-
public WavefrontPropertiesConfigAdapter(WavefrontProperties properties) {
33-
super(properties);
34+
private final WavefrontProperties properties;
35+
36+
public WavefrontMetricsPropertiesConfigAdapter(WavefrontProperties properties,
37+
WavefrontMetricsProperties metricsProperties) {
38+
super(metricsProperties);
39+
this.properties = properties;
3440
}
3541

3642
@Override
@@ -45,26 +51,27 @@ public String get(String k) {
4551

4652
@Override
4753
public String uri() {
48-
return get(this::getUriAsString, WavefrontConfig.DEFAULT_DIRECT::uri);
54+
return this.properties.getUri().toString();
4955
}
5056

5157
@Override
5258
public String source() {
53-
return get(WavefrontProperties::getSource, WavefrontConfig.super::source);
59+
return this.properties.getSourceOrDefault();
5460
}
5561

5662
@Override
57-
public String apiToken() {
58-
return get(WavefrontProperties::getApiToken, WavefrontConfig.super::apiToken);
63+
public int batchSize() {
64+
return this.properties.getSender().getBatchSize();
5965
}
6066

6167
@Override
62-
public String globalPrefix() {
63-
return get(WavefrontProperties::getGlobalPrefix, WavefrontConfig.super::globalPrefix);
68+
public String apiToken() {
69+
return this.properties.getApiTokenOrThrow();
6470
}
6571

66-
private String getUriAsString(WavefrontProperties properties) {
67-
return (properties.getUri() != null) ? properties.getUri().toString() : null;
72+
@Override
73+
public String globalPrefix() {
74+
return get(WavefrontMetricsProperties::getGlobalPrefix, WavefrontConfig.super::globalPrefix);
6875
}
6976

7077
}
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
package org.springframework.boot.actuate.autoconfigure.tracing.wavefront;
1818

1919
import java.util.Set;
20-
import java.util.concurrent.TimeUnit;
2120

2221
import brave.handler.SpanHandler;
2322
import com.wavefront.sdk.common.WavefrontSender;
2423
import com.wavefront.sdk.common.application.ApplicationTags;
25-
import com.wavefront.sdk.common.clients.WavefrontClient;
2624
import io.micrometer.core.instrument.MeterRegistry;
2725
import io.micrometer.tracing.reporter.wavefront.SpanMetrics;
2826
import io.micrometer.tracing.reporter.wavefront.WavefrontBraveSpanHandler;
@@ -32,6 +30,8 @@
3230

3331
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
3432
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
33+
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontAutoConfiguration;
34+
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties;
3535
import org.springframework.boot.autoconfigure.AutoConfiguration;
3636
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
3737
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -48,30 +48,21 @@
4848
*
4949
* @author Moritz Halbritter
5050
*/
51-
@AutoConfiguration(after = { MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class })
52-
@EnableConfigurationProperties(WavefrontTracingProperties.class)
53-
@ConditionalOnClass(WavefrontSender.class)
54-
class WavefrontAutoConfiguration {
51+
@AutoConfiguration(after = { MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class,
52+
WavefrontAutoConfiguration.class })
53+
@EnableConfigurationProperties({ WavefrontTracingProperties.class, WavefrontProperties.class })
54+
@ConditionalOnBean(WavefrontSender.class)
55+
public class WavefrontTracingAutoConfiguration {
5556

5657
/**
5758
* Default value for application name if {@code spring.application.name} is not set.
5859
*/
5960
private static final String DEFAULT_APPLICATION_NAME = "application";
6061

61-
@Bean
62-
@ConditionalOnMissingBean
63-
WavefrontSender wavefrontSender(WavefrontTracingProperties properties) {
64-
return new WavefrontClient.Builder(properties.getUri().toString(), properties.getApiToken())
65-
.flushInterval((int) properties.getSender().getFlushInterval().getSeconds(), TimeUnit.SECONDS)
66-
.maxQueueSize(properties.getSender().getMaxQueueSize())
67-
.messageSizeBytes((int) properties.getSender().getMessageSize().toBytes()).build();
68-
}
69-
7062
@Bean
7163
@ConditionalOnMissingBean
7264
ApplicationTags applicationTags(Environment environment, WavefrontTracingProperties properties) {
7365
String applicationName = environment.getProperty("spring.application.name");
74-
7566
return new ApplicationTags.Builder(
7667
StringUtils.hasLength(applicationName) ? applicationName : DEFAULT_APPLICATION_NAME,
7768
properties.getServiceName()).build();
@@ -109,10 +100,10 @@ static class WavefrontMicrometer {
109100

110101
@Bean(destroyMethod = "")
111102
@ConditionalOnMissingBean
112-
WavefrontSpanHandler wavefrontSpanHandler(WavefrontTracingProperties properties,
113-
WavefrontSender wavefrontSender, SpanMetrics spanMetrics, ApplicationTags applicationTags) {
103+
WavefrontSpanHandler wavefrontSpanHandler(WavefrontProperties properties, WavefrontSender wavefrontSender,
104+
SpanMetrics spanMetrics, ApplicationTags applicationTags) {
114105
return new WavefrontSpanHandler(properties.getSender().getMaxQueueSize(), wavefrontSender, spanMetrics,
115-
properties.getSource(), applicationTags, Set.of());
106+
properties.getSourceOrDefault(), applicationTags, Set.of());
116107
}
117108

118109
@Configuration(proxyBeanMethods = false)
@@ -140,4 +131,5 @@ WavefrontOtelSpanHandler wavefrontOtelSpanHandler(WavefrontSpanHandler wavefront
140131
}
141132

142133
}
134+
143135
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/wavefront/WavefrontTracingProperties.java

+1-86
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,19 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.tracing.wavefront;
1818

19-
import java.net.URI;
20-
import java.time.Duration;
21-
2219
import org.springframework.boot.context.properties.ConfigurationProperties;
23-
import org.springframework.util.unit.DataSize;
2420

2521
/**
2622
* @author Moritz Halbritter
2723
*/
28-
@ConfigurationProperties("management.tracing.wavefront")
29-
// TODO MH: Consolidate with WavefrontProperties
24+
@ConfigurationProperties("management.wavefront.tracing")
3025
public class WavefrontTracingProperties {
3126

32-
/**
33-
* URI to ship metrics to.
34-
*/
35-
private URI uri = URI.create("https://longboard.wavefront.com");
36-
37-
/**
38-
* Unique identifier for the app instance that is the source of metrics being
39-
* published to Wavefront. Defaults to the local host name.
40-
*/
41-
private String source;
42-
43-
/**
44-
* API token used when publishing metrics directly to the Wavefront API host.
45-
*/
46-
private String apiToken;
47-
4827
/**
4928
* Service name.
5029
*/
5130
private String serviceName;
5231

53-
private final Sender sender = new Sender();
54-
5532
public String getServiceName() {
5633
return this.serviceName;
5734
}
@@ -60,66 +37,4 @@ public void setServiceName(String serviceName) {
6037
this.serviceName = serviceName;
6138
}
6239

63-
public URI getUri() {
64-
return this.uri;
65-
}
66-
67-
public void setUri(URI uri) {
68-
this.uri = uri;
69-
}
70-
71-
public String getSource() {
72-
return this.source;
73-
}
74-
75-
public void setSource(String source) {
76-
this.source = source;
77-
}
78-
79-
public String getApiToken() {
80-
return this.apiToken;
81-
}
82-
83-
public void setApiToken(String apiToken) {
84-
this.apiToken = apiToken;
85-
}
86-
87-
public Sender getSender() {
88-
return this.sender;
89-
}
90-
91-
public static class Sender {
92-
93-
private int maxQueueSize = 50000;
94-
95-
private Duration flushInterval = Duration.ofSeconds(1);
96-
97-
private DataSize messageSize = DataSize.ofBytes(Integer.MAX_VALUE);
98-
99-
public int getMaxQueueSize() {
100-
return this.maxQueueSize;
101-
}
102-
103-
public void setMaxQueueSize(int maxQueueSize) {
104-
this.maxQueueSize = maxQueueSize;
105-
}
106-
107-
public Duration getFlushInterval() {
108-
return this.flushInterval;
109-
}
110-
111-
public void setFlushInterval(Duration flushInterval) {
112-
this.flushInterval = flushInterval;
113-
}
114-
115-
public DataSize getMessageSize() {
116-
return this.messageSize;
117-
}
118-
119-
public void setMessageSize(DataSize messageSize) {
120-
this.messageSize = messageSize;
121-
}
122-
123-
}
124-
12540
}

0 commit comments

Comments
 (0)