Browse Source

Polish 'Align Wavefront application tags support with Spring Boot 2.x'

See gh-32844
pull/33240/head
Phillip Webb 3 years ago
parent
commit
a0f39d66fe
  1. 8
      spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfiguration.java
  2. 31
      spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/wavefront/WavefrontTracingAutoConfiguration.java
  3. 25
      spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontProperties.java
  4. 11
      spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfigurationTests.java

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

@ -77,13 +77,13 @@ public class WavefrontMetricsExportAutoConfiguration { @@ -77,13 +77,13 @@ public class WavefrontMetricsExportAutoConfiguration {
@Bean
@ConditionalOnBean(ApplicationTags.class)
MeterRegistryCustomizer<WavefrontMeterRegistry> applicationTagsCustomizer(ApplicationTags applicationTags) {
Tags commonTags = Tags.of(applicationTags.toPointTags().entrySet().stream()
.map(WavefrontMetricsExportAutoConfiguration::asTag).toList());
MeterRegistryCustomizer<WavefrontMeterRegistry> wavefrontApplicationTagsCustomizer(
ApplicationTags wavefrontApplicationTags) {
Tags commonTags = Tags.of(wavefrontApplicationTags.toPointTags().entrySet().stream().map(this::asTag).toList());
return (registry) -> registry.config().commonTags(commonTags);
}
private static Tag asTag(Map.Entry<String, String> entry) {
private Tag asTag(Map.Entry<String, String> entry) {
return Tag.of(entry.getKey(), entry.getValue());
}

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

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.tracing.wavefront;
import java.util.Collections;
import java.util.function.Supplier;
import brave.handler.SpanHandler;
import com.wavefront.sdk.common.WavefrontSender;
@ -40,10 +41,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -40,10 +41,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Wavefront tracing.
@ -65,7 +68,7 @@ public class WavefrontTracingAutoConfiguration { @@ -65,7 +68,7 @@ public class WavefrontTracingAutoConfiguration {
* "https://docs.wavefront.com/trace_data_details.html#application-tags">Wavefront
* Application Tags</a>
*/
private static final String DEFAULT_WAVEFRONT_APPLICATION_NAME = "unnamed_application";
private static final String DEFAULT_APPLICATION_NAME = "unnamed_application";
/**
* Default value for the Wavefront Service name if {@code spring.application.name} is
@ -74,28 +77,26 @@ public class WavefrontTracingAutoConfiguration { @@ -74,28 +77,26 @@ public class WavefrontTracingAutoConfiguration {
* "https://docs.wavefront.com/trace_data_details.html#application-tags">Wavefront
* Application Tags</a>
*/
private static final String DEFAULT_WAVEFRONT_SERVICE_NAME = "unnamed_service";
private static final String DEFAULT_SERVICE_NAME = "unnamed_service";
@Bean
@ConditionalOnMissingBean
public ApplicationTags applicationTags(Environment environment, WavefrontProperties properties) {
String fallbackWavefrontServiceName = environment.getProperty("spring.application.name",
DEFAULT_WAVEFRONT_SERVICE_NAME);
public ApplicationTags wavefrontApplicationTags(Environment environment, WavefrontProperties properties) {
Tracing tracing = properties.getTracing();
String wavefrontServiceName = (tracing.getServiceName() != null) ? tracing.getServiceName()
: fallbackWavefrontServiceName;
String wavefrontApplicationName = (tracing.getApplicationName() != null) ? tracing.getApplicationName()
: DEFAULT_WAVEFRONT_APPLICATION_NAME;
String wavefrontServiceName = getName(tracing.getServiceName(),
() -> environment.getProperty("spring.application.name", DEFAULT_SERVICE_NAME));
String wavefrontApplicationName = getName(tracing.getApplicationName(), () -> DEFAULT_APPLICATION_NAME);
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
ApplicationTags.Builder builder = new ApplicationTags.Builder(wavefrontApplicationName, wavefrontServiceName);
if (tracing.getClusterName() != null) {
builder.cluster(tracing.getClusterName());
}
if (tracing.getShardName() != null) {
builder.shard(tracing.getShardName());
}
map.from(tracing::getClusterName).to(builder::cluster);
map.from(tracing::getShardName).to(builder::shard);
return builder.build();
}
private String getName(String value, Supplier<String> fallback) {
return (StringUtils.hasText(value)) ? value : fallback.get();
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(WavefrontSpanHandler.class)
static class WavefrontMicrometer {

25
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontProperties.java

@ -21,8 +21,6 @@ import java.net.URI; @@ -21,8 +21,6 @@ import java.net.URI;
import java.net.UnknownHostException;
import java.time.Duration;
import com.wavefront.sdk.common.application.ApplicationTags;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PushRegistryProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException;
@ -264,37 +262,24 @@ public class WavefrontProperties { @@ -264,37 +262,24 @@ public class WavefrontProperties {
public static class Tracing {
/**
* Wavefront Application name used in {@link ApplicationTags}. Defaults to
* Wavefront Application name used in ApplicationTags. Defaults to
* 'unnamed_application'.
* @see <a href=
* "https://docs.wavefront.com/trace_data_details.html#application-tags">Wavefront
* Application Tags</a>
*/
private String applicationName;
/**
* Wavefront Service name used in {@link ApplicationTags}, falling back to
* {@code spring.application.name}. If both are unset it defaults to
* 'unnamed_service'.
* @see <a href=
* "https://docs.wavefront.com/trace_data_details.html#application-tags">Wavefront
* Application Tags</a>
* Wavefront Service name used in ApplicationTags, falling back to
* 'spring.application.name'. If both are unset it defaults to 'unnamed_service'.
*/
private String serviceName;
/**
* Optional Wavefront Cluster name used in {@link ApplicationTags}.
* @see <a href=
* "https://docs.wavefront.com/trace_data_details.html#application-tags">Wavefront
* Application Tags</a>
* Optional Wavefront Cluster name used in ApplicationTags.
*/
private String clusterName;
/**
* Optional Wavefront Shard name used in {@link ApplicationTags}.
* @see <a href=
* "https://docs.wavefront.com/trace_data_details.html#application-tags">Wavefront
* Application Tags</a>
* Optional Wavefront Shard name used in ApplicationTags.
*/
private String shardName;

11
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfigurationTests.java

@ -88,13 +88,12 @@ class WavefrontMetricsExportAutoConfigurationTests { @@ -88,13 +88,12 @@ class WavefrontMetricsExportAutoConfigurationTests {
@Test
void exportsApplicationTagsInWavefrontRegistry() {
ApplicationTags.Builder appTagsBuilder = new ApplicationTags.Builder("super-application", "super-service");
appTagsBuilder.cluster("super-cluster");
appTagsBuilder.shard("super-shard");
appTagsBuilder.customTags(Map.of("custom-key", "custom-val"));
ApplicationTags.Builder builder = new ApplicationTags.Builder("super-application", "super-service");
builder.cluster("super-cluster");
builder.shard("super-shard");
builder.customTags(Map.of("custom-key", "custom-val"));
this.contextRunner.withConfiguration(AutoConfigurations.of(MetricsAutoConfiguration.class))
.withUserConfiguration(BaseConfiguration.class).withBean(ApplicationTags.class, appTagsBuilder::build)
.withUserConfiguration(BaseConfiguration.class).withBean(ApplicationTags.class, builder::build)
.run((context) -> {
WavefrontMeterRegistry registry = context.getBean(WavefrontMeterRegistry.class);
registry.counter("my.counter", "env", "qa");

Loading…
Cancel
Save