Skip to content

Commit

Permalink
Refine WavefrontProperties
Browse files Browse the repository at this point in the history
Remove naming properties under `management.wavefront.application`.

Closes gh-33244
  • Loading branch information
philwebb committed Nov 19, 2022
1 parent 9250fd6 commit c93e248
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 70 deletions.
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -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();
}

Expand Down
Expand Up @@ -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.
Expand All @@ -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;
}
Expand Down Expand Up @@ -117,38 +101,6 @@ public void setApiToken(String apiToken) {
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.
Expand Down Expand Up @@ -195,6 +147,64 @@ private boolean usesProxy() {
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 {

/**
Expand Down
Expand Up @@ -107,10 +107,10 @@ void exportsApplicationTagsInWavefrontRegistryWhenApplicationTagsBean() {
@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");
Expand Down
Expand Up @@ -137,10 +137,13 @@ void shouldUseSpringApplicationNameForServiceName() {

@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");
Expand Down
Expand Up @@ -51,10 +51,10 @@ void wavefrontApplicationTagsWhenHasUserBeanBacksOff() {
@Test
void wavefrontApplicationTagsMapsProperties() {
List<String> 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");
Expand Down

0 comments on commit c93e248

Please sign in to comment.