diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontAutoConfiguration.java index 6dc0c052b3..62a1186dd5 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontAutoConfiguration.java @@ -21,6 +21,7 @@ import java.util.function.Supplier; import com.wavefront.sdk.common.WavefrontSender; import com.wavefront.sdk.common.application.ApplicationTags; +import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties.Application; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -65,13 +66,14 @@ public class WavefrontAutoConfiguration { @Bean @ConditionalOnMissingBean public ApplicationTags wavefrontApplicationTags(Environment environment, WavefrontProperties properties) { - String wavefrontServiceName = getName(properties.getServiceName(), + Application application = properties.getApplication(); + String serviceName = getName(application.getServiceName(), () -> environment.getProperty("spring.application.name", DEFAULT_SERVICE_NAME)); - String wavefrontApplicationName = getName(properties.getApplicationName(), () -> DEFAULT_APPLICATION_NAME); + String applicationName = getName(application.getName(), () -> DEFAULT_APPLICATION_NAME); PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); - ApplicationTags.Builder builder = new ApplicationTags.Builder(wavefrontApplicationName, wavefrontServiceName); - map.from(properties::getClusterName).to(builder::cluster); - map.from(properties::getShardName).to(builder::shard); + ApplicationTags.Builder builder = new ApplicationTags.Builder(applicationName, serviceName); + map.from(application::getClusterName).to(builder::cluster); + map.from(application::getShardName).to(builder::shard); return builder.build(); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontProperties.java index dc2a407b2b..2008dd3bc3 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontProperties.java @@ -53,27 +53,7 @@ public class WavefrontProperties { */ private String apiToken; - /** - * Wavefront Application name used in ApplicationTags. Defaults to - * 'unnamed_application'. - */ - private String applicationName; - - /** - * 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 ApplicationTags. - */ - private String clusterName; - - /** - * Optional Wavefront Shard name used in ApplicationTags. - */ - private String shardName; + private final Application application = new Application(); /** * Sender configuration. @@ -85,6 +65,10 @@ public class WavefrontProperties { */ private final Metrics metrics = new Metrics(); + public Application getApplication() { + return this.application; + } + public Sender getSender() { return this.sender; } @@ -117,38 +101,6 @@ public class WavefrontProperties { this.apiToken = apiToken; } - public String getServiceName() { - return this.serviceName; - } - - public void setServiceName(String serviceName) { - this.serviceName = serviceName; - } - - public String getApplicationName() { - return this.applicationName; - } - - public void setApplicationName(String applicationName) { - this.applicationName = applicationName; - } - - public String getClusterName() { - return this.clusterName; - } - - public void setClusterName(String clusterName) { - this.clusterName = clusterName; - } - - public String getShardName() { - return this.shardName; - } - - public void setShardName(String shardName) { - this.shardName = shardName; - } - /** * Returns the effective URI of the wavefront instance. This will not be the same URI * given through {@link #setUri(URI)} when a proxy is used. @@ -195,6 +147,64 @@ public class WavefrontProperties { return "proxy".equals(this.uri.getScheme()); } + public static class Application { + + /** + * Wavefront Application name used in ApplicationTags. Defaults to + * 'unnamed_application'. + */ + private String name; + + /** + * 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 ApplicationTags. + */ + private String clusterName; + + /** + * Optional Wavefront Shard name used in ApplicationTags. + */ + private String shardName; + + public String getServiceName() { + return this.serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String getClusterName() { + return this.clusterName; + } + + public void setClusterName(String clusterName) { + this.clusterName = clusterName; + } + + public String getShardName() { + return this.shardName; + } + + public void setShardName(String shardName) { + this.shardName = shardName; + } + + } + public static class Sender { /** diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfigurationTests.java index 9487d4df9d..1b8b098477 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfigurationTests.java @@ -107,10 +107,10 @@ class WavefrontMetricsExportAutoConfigurationTests { @Test void exportsApplicationTagsInWavefrontRegistryWhenInProperties() { this.contextRunner.withConfiguration(AutoConfigurations.of(MetricsAutoConfiguration.class)) - .withPropertyValues("management.wavefront.service-name=super-service", - "management.wavefront.application-name=super-application", - "management.wavefront.cluster-name=super-cluster", - "management.wavefront.shard-name=super-shard") + .withPropertyValues("management.wavefront.application.service-name=super-service", + "management.wavefront.application.name=super-application", + "management.wavefront.application.cluster-name=super-cluster", + "management.wavefront.application.shard-name=super-shard") .withUserConfiguration(BaseConfiguration.class).run((context) -> { WavefrontMeterRegistry registry = context.getBean(WavefrontMeterRegistry.class); registry.counter("my.counter", "env", "qa"); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/wavefront/WavefrontTracingAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/wavefront/WavefrontTracingAutoConfigurationTests.java index 07b6d987fa..95ed8646fd 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/wavefront/WavefrontTracingAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/wavefront/WavefrontTracingAutoConfigurationTests.java @@ -137,10 +137,13 @@ class WavefrontTracingAutoConfigurationTests { @Test void shouldHonorConfigProperties() { - this.contextRunner.withUserConfiguration(WavefrontSenderConfiguration.class).withPropertyValues( - "spring.application.name=ignored", "management.wavefront.application-name=super-application", - "management.wavefront.service-name=super-service", "management.wavefront.cluster-name=super-cluster", - "management.wavefront.shard-name=super-shard").run((context) -> { + this.contextRunner.withUserConfiguration(WavefrontSenderConfiguration.class) + .withPropertyValues("spring.application.name=ignored", + "management.wavefront.application.name=super-application", + "management.wavefront.application.service-name=super-service", + "management.wavefront.application.cluster-name=super-cluster", + "management.wavefront.application.shard-name=super-shard") + .run((context) -> { ApplicationTags applicationTags = context.getBean(ApplicationTags.class); assertThat(applicationTags.getApplication()).isEqualTo("super-application"); assertThat(applicationTags.getService()).isEqualTo("super-service"); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontAutoConfigurationTests.java index 378925c401..702f675241 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontAutoConfigurationTests.java @@ -51,10 +51,10 @@ class WavefrontAutoConfigurationTests { @Test void wavefrontApplicationTagsMapsProperties() { List properties = new ArrayList<>(); - properties.add("management.wavefront.application-name=test-application"); - properties.add("management.wavefront.service-name=test-service"); - properties.add("management.wavefront.cluster-name=test-cluster"); - properties.add("management.wavefront.shard-name=test-shard"); + properties.add("management.wavefront.application.name=test-application"); + properties.add("management.wavefront.application.service-name=test-service"); + properties.add("management.wavefront.application.cluster-name=test-cluster"); + properties.add("management.wavefront.application.shard-name=test-shard"); this.contextRunner.withPropertyValues(properties.toArray(String[]::new)).run((context) -> { ApplicationTags tags = context.getBean(ApplicationTags.class); assertThat(tags.getApplication()).isEqualTo("test-application");