Skip to content

Commit

Permalink
Further refine WavefrontProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Nov 21, 2022
1 parent 2d4ef90 commit 12b4578
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 34 deletions.
Expand Up @@ -16,8 +16,6 @@

package org.springframework.boot.actuate.autoconfigure.wavefront;

import java.util.function.Supplier;

import com.wavefront.sdk.common.WavefrontSender;
import com.wavefront.sdk.common.application.ApplicationTags;

Expand Down Expand Up @@ -46,39 +44,18 @@
@EnableConfigurationProperties(WavefrontProperties.class)
public class WavefrontAutoConfiguration {

/**
* Default value for the Wavefront Service name if {@code spring.application.name} is
* not set.
* @see <a href=
* "https://docs.wavefront.com/trace_data_details.html#application-tags">Wavefront
* Application Tags</a>
*/
private static final String DEFAULT_SERVICE_NAME = "unnamed_service";

/**
* Default value for the Wavefront Application name.
* @see <a href=
* "https://docs.wavefront.com/trace_data_details.html#application-tags">Wavefront
* Application Tags</a>
*/
private static final String DEFAULT_APPLICATION_NAME = "unnamed_application";

@Bean
@ConditionalOnMissingBean
public ApplicationTags wavefrontApplicationTags(Environment environment, WavefrontProperties properties) {
Application application = properties.getApplication();
String serviceName = getName(application.getServiceName(),
() -> environment.getProperty("spring.application.name", DEFAULT_SERVICE_NAME));
String applicationName = getName(application.getName(), () -> DEFAULT_APPLICATION_NAME);
String serviceName = application.getServiceName();
serviceName = (StringUtils.hasText(serviceName)) ? serviceName
: environment.getProperty("spring.application.name", "unnamed_service");
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
ApplicationTags.Builder builder = new ApplicationTags.Builder(applicationName, serviceName);
ApplicationTags.Builder builder = new ApplicationTags.Builder(application.getName(), serviceName);
map.from(application::getClusterName).to(builder::cluster);
map.from(application::getShardName).to(builder::shard);
return builder.build();
}

private String getName(String value, Supplier<String> fallback) {
return (StringUtils.hasText(value)) ? value : fallback.get();
}

}
Expand Up @@ -53,6 +53,9 @@ public class WavefrontProperties {
*/
private String apiToken;

/**
* Application configuration.
*/
private final Application application = new Application();

/**
Expand Down Expand Up @@ -150,24 +153,23 @@ private boolean usesProxy() {
public static class Application {

/**
* Wavefront Application name used in ApplicationTags. Defaults to
* 'unnamed_application'.
* Wavefront 'Application' name used in ApplicationTags.
*/
private String name;
private String name = "unnamed_application";

/**
* Wavefront Service name used in ApplicationTags, falling back to
* 'spring.application.name'. If both are unset it defaults to 'unnamed_service'.
* Wavefront 'Service' name used in t, 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.
* Wavefront Cluster name used in ApplicationTags.
*/
private String clusterName;

/**
* Optional Wavefront Shard name used in ApplicationTags.
* Wavefront Shard name used in ApplicationTags.
*/
private String shardName;

Expand Down

0 comments on commit 12b4578

Please sign in to comment.