parent
2d4ef90954
commit
12b4578e98
|
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure.wavefront;
|
package org.springframework.boot.actuate.autoconfigure.wavefront;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import com.wavefront.sdk.common.WavefrontSender;
|
import com.wavefront.sdk.common.WavefrontSender;
|
||||||
import com.wavefront.sdk.common.application.ApplicationTags;
|
import com.wavefront.sdk.common.application.ApplicationTags;
|
||||||
|
|
||||||
|
|
@ -46,39 +44,18 @@ import org.springframework.util.StringUtils;
|
||||||
@EnableConfigurationProperties(WavefrontProperties.class)
|
@EnableConfigurationProperties(WavefrontProperties.class)
|
||||||
public class WavefrontAutoConfiguration {
|
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
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public ApplicationTags wavefrontApplicationTags(Environment environment, WavefrontProperties properties) {
|
public ApplicationTags wavefrontApplicationTags(Environment environment, WavefrontProperties properties) {
|
||||||
Application application = properties.getApplication();
|
Application application = properties.getApplication();
|
||||||
String serviceName = getName(application.getServiceName(),
|
String serviceName = application.getServiceName();
|
||||||
() -> environment.getProperty("spring.application.name", DEFAULT_SERVICE_NAME));
|
serviceName = (StringUtils.hasText(serviceName)) ? serviceName
|
||||||
String applicationName = getName(application.getName(), () -> DEFAULT_APPLICATION_NAME);
|
: environment.getProperty("spring.application.name", "unnamed_service");
|
||||||
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
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::getClusterName).to(builder::cluster);
|
||||||
map.from(application::getShardName).to(builder::shard);
|
map.from(application::getShardName).to(builder::shard);
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getName(String value, Supplier<String> fallback) {
|
|
||||||
return (StringUtils.hasText(value)) ? value : fallback.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,9 @@ public class WavefrontProperties {
|
||||||
*/
|
*/
|
||||||
private String apiToken;
|
private String apiToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application configuration.
|
||||||
|
*/
|
||||||
private final Application application = new Application();
|
private final Application application = new Application();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -150,24 +153,23 @@ public class WavefrontProperties {
|
||||||
public static class Application {
|
public static class Application {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wavefront Application name used in ApplicationTags. Defaults to
|
* Wavefront 'Application' name used in ApplicationTags.
|
||||||
* 'unnamed_application'.
|
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name = "unnamed_application";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wavefront Service name used in ApplicationTags, falling back to
|
* Wavefront 'Service' name used in t, falling back to 'spring.application.name'.
|
||||||
* 'spring.application.name'. If both are unset it defaults to 'unnamed_service'.
|
* If both are unset it defaults to 'unnamed_service'.
|
||||||
*/
|
*/
|
||||||
private String serviceName;
|
private String serviceName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional Wavefront Cluster name used in ApplicationTags.
|
* Wavefront Cluster name used in ApplicationTags.
|
||||||
*/
|
*/
|
||||||
private String clusterName;
|
private String clusterName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional Wavefront Shard name used in ApplicationTags.
|
* Wavefront Shard name used in ApplicationTags.
|
||||||
*/
|
*/
|
||||||
private String shardName;
|
private String shardName;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue