Commit c1c162ab authored by Andy Wilkinson's avatar Andy Wilkinson

Polish "Add auto-configuraton for exporting metrics to Wavefront"

Closes gh-12068
parent 142dbb22
......@@ -33,7 +33,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Wavefront.
*
......@@ -57,7 +56,9 @@ public class WavefrontMetricsExportAutoConfiguration {
@Bean(destroyMethod = "stop")
@ConditionalOnMissingBean
public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig config, Clock clock) {
public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig config,
Clock clock) {
return new WavefrontMeterRegistry(config, clock);
}
}
......@@ -16,6 +16,8 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
import java.net.URI;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
......@@ -27,36 +29,41 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*/
@ConfigurationProperties("management.metrics.export.wavefront")
public class WavefrontProperties extends StepRegistryProperties {
/**
* The URI to publish metrics to. The URI could represent a Wavefront sidecar or the
* Wavefront API host. This host could also represent an internal proxy set up in your environment
* that forwards metrics data to the Wavefront API host.
* URI to which metrics are published. May represent a Wavefront sidecar or the
* Wavefront API host. This host could also represent an internal proxy set up in your
* environment that forwards metrics data to the Wavefront API host.
*
* If publishing metrics to a Wavefront proxy (as described in https://docs.wavefront.com/proxies_installing.html),
* the host must be in the proxy://HOST:PORT format.
* If publishing metrics to a Wavefront proxy (as described in
* https://docs.wavefront.com/proxies_installing.html), the host must be in the
* proxy://HOST:PORT format.
*/
private String uri;
private URI uri;
/**
* Uniquely identifies the app instance that is publishing metrics to Wavefront. Defaults to the local host name.
* Unique identifier for the app instance that is the source of metrics being
* published to Wavefront. Defaults to the local host name.
*/
private String source;
/**
* Required when publishing directly to the Wavefront API host, otherwise does nothing.
* API token used when publishing metrics directly to the Wavefront API host.
*/
private String apiToken;
/**
* Global prefix to separate metrics originating from this app's white box instrumentation from those originating from other Wavefront integrations when viewed in the Wavefront UI.
* Global prefix to separate metrics originating from this app's white box
* instrumentation from those originating from other Wavefront integrations when
* viewed in the Wavefront UI.
*/
private String globalPrefix;
public String getUri() {
public URI getUri() {
return this.uri;
}
public void setUri(String uri) {
public void setUri(URI uri) {
this.uri = uri;
}
......@@ -83,4 +90,5 @@ public class WavefrontProperties extends StepRegistryProperties {
public void setGlobalPrefix(String globalPrefix) {
this.globalPrefix = globalPrefix;
}
}
......@@ -26,7 +26,8 @@ import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.
* @author Jon Schneider
* @since 2.0.0
*/
public class WavefrontPropertiesConfigAdapter extends PropertiesConfigAdapter<WavefrontProperties> implements WavefrontConfig {
public class WavefrontPropertiesConfigAdapter
extends PropertiesConfigAdapter<WavefrontProperties> implements WavefrontConfig {
public WavefrontPropertiesConfigAdapter(WavefrontProperties properties) {
super(properties);
......@@ -39,7 +40,7 @@ public class WavefrontPropertiesConfigAdapter extends PropertiesConfigAdapter<Wa
@Override
public String uri() {
return get(WavefrontProperties::getUri, WavefrontConfig.DEFAULT_DIRECT::uri);
return get(this::getUriAsString, WavefrontConfig.DEFAULT_DIRECT::uri);
}
@Override
......@@ -54,6 +55,12 @@ public class WavefrontPropertiesConfigAdapter extends PropertiesConfigAdapter<Wa
@Override
public String globalPrefix() {
return get(WavefrontProperties::getGlobalPrefix, WavefrontConfig.super::globalPrefix);
return get(WavefrontProperties::getGlobalPrefix,
WavefrontConfig.super::globalPrefix);
}
private String getUriAsString(WavefrontProperties properties) {
return properties.getUri() == null ? null : properties.getUri().toString();
}
}
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -15,6 +15,6 @@
*/
/**
* Support for exporting actuator metrics to StatsD.
* Support for exporting actuator metrics to Wavefront.
*/
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
......@@ -52,11 +52,16 @@ public class WavefrontMetricsExportAutoConfigurationTests {
.doesNotHaveBean(WavefrontMeterRegistry.class));
}
@Test
public void failsWithoutAnApiTokenWhenPublishingDirectly() {
this.runner.withUserConfiguration(BaseConfiguration.class)
.run((context) -> assertThat(context).hasFailed());
}
@Test
public void autoConfigurationCanBeDisabled() {
this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues(
"management.metrics.export.wavefront.enabled=false")
.withPropertyValues("management.metrics.export.wavefront.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(WavefrontMeterRegistry.class)
.doesNotHaveBean(WavefrontConfig.class));
......@@ -64,8 +69,7 @@ public class WavefrontMetricsExportAutoConfigurationTests {
@Test
public void allowsConfigToBeCustomized() {
this.runner
.withUserConfiguration(CustomConfigConfiguration.class)
this.runner.withUserConfiguration(CustomConfigConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(Clock.class)
.hasSingleBean(WavefrontMeterRegistry.class)
.hasSingleBean(WavefrontConfig.class).hasBean("customConfig"));
......@@ -73,10 +77,8 @@ public class WavefrontMetricsExportAutoConfigurationTests {
@Test
public void allowsRegistryToBeCustomized() {
this.runner
.withUserConfiguration(CustomRegistryConfiguration.class)
.withPropertyValues(
"management.metrics.export.wavefront.api-token=abcde")
this.runner.withUserConfiguration(CustomRegistryConfiguration.class)
.withPropertyValues("management.metrics.export.wavefront.api-token=abcde")
.run((context) -> assertThat(context).hasSingleBean(Clock.class)
.hasSingleBean(WavefrontConfig.class)
.hasSingleBean(WavefrontMeterRegistry.class)
......@@ -85,10 +87,8 @@ public class WavefrontMetricsExportAutoConfigurationTests {
@Test
public void stopsMeterRegistryWhenContextIsClosed() {
this.runner
.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues(
"management.metrics.export.wavefront.api-token=abcde")
this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.wavefront.api-token=abcde")
.run((context) -> {
WavefrontMeterRegistry registry = spyOnDisposableBean(
WavefrontMeterRegistry.class, context);
......@@ -115,7 +115,7 @@ public class WavefrontMetricsExportAutoConfigurationTests {
static class BaseConfiguration {
@Bean
public Clock customClock() {
public Clock clock() {
return Clock.SYSTEM;
}
......@@ -147,7 +147,8 @@ public class WavefrontMetricsExportAutoConfigurationTests {
static class CustomRegistryConfiguration {
@Bean(destroyMethod = "stop")
public WavefrontMeterRegistry customRegistry(WavefrontConfig config, Clock clock) {
public WavefrontMeterRegistry customRegistry(WavefrontConfig config,
Clock clock) {
return new WavefrontMeterRegistry(config, clock);
}
......
......@@ -1391,10 +1391,11 @@ content into your application. Rather, pick only the properties that you need.
management.metrics.export.statsd.polling-frequency=10s # How often gauges will be polled. When a gauge is polled, its value is recalculated and if the value has changed, it is sent to the StatsD server.
management.metrics.export.statsd.port=8125 # Port of the StatsD server to receive exported metrics.
management.metrics.export.statsd.queue-size=2147483647 # Maximum size of the queue of items waiting to be sent to the StatsD server.
management.metrics.export.wavefront.uri= # Optional custom URI for the Wavefront API or proxy.
management.metrics.export.wavefront.source= # Uniquely identifies the app instance that is publishing metrics to Wavefront. Defaults to the local host name.
management.metrics.export.wavefront.api-token= # Required when publishing directly to the Wavefront API host, otherwise does nothing.
management.metrics.export.wavefront.global-prefix= # Setting a global prefix separates metrics originating from this app's whitebox instrumentation from those originating from other Wavefront integrations.
management.metrics.export.wavefront.api-token= # API token used when publishing metrics directly to the Wavefront API host.
management.metrics.export.wavefront.enabled= # Whether exporting of metrics to this backend is enabled.
management.metrics.export.wavefront.global-prefix= # Global prefix to separate metrics originating from this app's white box instrumentation from those originating from other Wavefront integrations when viewed in the Wavefront UI.
management.metrics.export.wavefront.source= # Unique identifier for the app instance that is the source of metrics being published to Wavefront. Defaults to the local host name.
management.metrics.export.wavefront.uri= # URI to which metrics are published. May represent a Wavefront sidecar or the Wavefront API host. This host could also represent an internal proxy set up in your environment that forwards metrics data to the Wavefront API host.
management.metrics.use-global-registry=true # Whether auto-configured MeterRegistry implementations should be bound to the global static registry on Metrics.
management.metrics.web.client.max-uri-tags=100 # Maximum number of unique URI tag values allowed. After the max number of tag values is reached, metrics with additional tag values are denied by filter.
management.metrics.web.client.record-request-percentiles=false # Whether instrumented requests record percentiles histogram buckets by default.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment