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 ...@@ -33,7 +33,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
/** /**
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Wavefront. * {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Wavefront.
* *
...@@ -57,7 +56,9 @@ public class WavefrontMetricsExportAutoConfiguration { ...@@ -57,7 +56,9 @@ public class WavefrontMetricsExportAutoConfiguration {
@Bean(destroyMethod = "stop") @Bean(destroyMethod = "stop")
@ConditionalOnMissingBean @ConditionalOnMissingBean
public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig config, Clock clock) { public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig config,
Clock clock) {
return new WavefrontMeterRegistry(config, clock); return new WavefrontMeterRegistry(config, clock);
} }
} }
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront; 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.actuate.autoconfigure.metrics.export.properties.StepRegistryProperties;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
...@@ -27,36 +29,41 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -27,36 +29,41 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*/ */
@ConfigurationProperties("management.metrics.export.wavefront") @ConfigurationProperties("management.metrics.export.wavefront")
public class WavefrontProperties extends StepRegistryProperties { public class WavefrontProperties extends StepRegistryProperties {
/** /**
* The URI to publish metrics to. The URI could represent a Wavefront sidecar or the * 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 * Wavefront API host. This host could also represent an internal proxy set up in your
* that forwards metrics data to the Wavefront API host. * 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), * If publishing metrics to a Wavefront proxy (as described in
* the host must be in the proxy://HOST:PORT format. * 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; 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; 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; private String globalPrefix;
public String getUri() { public URI getUri() {
return this.uri; return this.uri;
} }
public void setUri(String uri) { public void setUri(URI uri) {
this.uri = uri; this.uri = uri;
} }
...@@ -83,4 +90,5 @@ public class WavefrontProperties extends StepRegistryProperties { ...@@ -83,4 +90,5 @@ public class WavefrontProperties extends StepRegistryProperties {
public void setGlobalPrefix(String globalPrefix) { public void setGlobalPrefix(String globalPrefix) {
this.globalPrefix = globalPrefix; this.globalPrefix = globalPrefix;
} }
} }
...@@ -26,7 +26,8 @@ import org.springframework.boot.actuate.autoconfigure.metrics.export.properties. ...@@ -26,7 +26,8 @@ import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.
* @author Jon Schneider * @author Jon Schneider
* @since 2.0.0 * @since 2.0.0
*/ */
public class WavefrontPropertiesConfigAdapter extends PropertiesConfigAdapter<WavefrontProperties> implements WavefrontConfig { public class WavefrontPropertiesConfigAdapter
extends PropertiesConfigAdapter<WavefrontProperties> implements WavefrontConfig {
public WavefrontPropertiesConfigAdapter(WavefrontProperties properties) { public WavefrontPropertiesConfigAdapter(WavefrontProperties properties) {
super(properties); super(properties);
...@@ -39,7 +40,7 @@ public class WavefrontPropertiesConfigAdapter extends PropertiesConfigAdapter<Wa ...@@ -39,7 +40,7 @@ public class WavefrontPropertiesConfigAdapter extends PropertiesConfigAdapter<Wa
@Override @Override
public String uri() { public String uri() {
return get(WavefrontProperties::getUri, WavefrontConfig.DEFAULT_DIRECT::uri); return get(this::getUriAsString, WavefrontConfig.DEFAULT_DIRECT::uri);
} }
@Override @Override
...@@ -54,6 +55,12 @@ public class WavefrontPropertiesConfigAdapter extends PropertiesConfigAdapter<Wa ...@@ -54,6 +55,12 @@ public class WavefrontPropertiesConfigAdapter extends PropertiesConfigAdapter<Wa
@Override @Override
public String globalPrefix() { 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -15,6 +15,6 @@ ...@@ -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; package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
...@@ -52,11 +52,16 @@ public class WavefrontMetricsExportAutoConfigurationTests { ...@@ -52,11 +52,16 @@ public class WavefrontMetricsExportAutoConfigurationTests {
.doesNotHaveBean(WavefrontMeterRegistry.class)); .doesNotHaveBean(WavefrontMeterRegistry.class));
} }
@Test
public void failsWithoutAnApiTokenWhenPublishingDirectly() {
this.runner.withUserConfiguration(BaseConfiguration.class)
.run((context) -> assertThat(context).hasFailed());
}
@Test @Test
public void autoConfigurationCanBeDisabled() { public void autoConfigurationCanBeDisabled() {
this.runner.withUserConfiguration(BaseConfiguration.class) this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues( .withPropertyValues("management.metrics.export.wavefront.enabled=false")
"management.metrics.export.wavefront.enabled=false")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(WavefrontMeterRegistry.class) .doesNotHaveBean(WavefrontMeterRegistry.class)
.doesNotHaveBean(WavefrontConfig.class)); .doesNotHaveBean(WavefrontConfig.class));
...@@ -64,8 +69,7 @@ public class WavefrontMetricsExportAutoConfigurationTests { ...@@ -64,8 +69,7 @@ public class WavefrontMetricsExportAutoConfigurationTests {
@Test @Test
public void allowsConfigToBeCustomized() { public void allowsConfigToBeCustomized() {
this.runner this.runner.withUserConfiguration(CustomConfigConfiguration.class)
.withUserConfiguration(CustomConfigConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(Clock.class) .run((context) -> assertThat(context).hasSingleBean(Clock.class)
.hasSingleBean(WavefrontMeterRegistry.class) .hasSingleBean(WavefrontMeterRegistry.class)
.hasSingleBean(WavefrontConfig.class).hasBean("customConfig")); .hasSingleBean(WavefrontConfig.class).hasBean("customConfig"));
...@@ -73,10 +77,8 @@ public class WavefrontMetricsExportAutoConfigurationTests { ...@@ -73,10 +77,8 @@ public class WavefrontMetricsExportAutoConfigurationTests {
@Test @Test
public void allowsRegistryToBeCustomized() { public void allowsRegistryToBeCustomized() {
this.runner this.runner.withUserConfiguration(CustomRegistryConfiguration.class)
.withUserConfiguration(CustomRegistryConfiguration.class) .withPropertyValues("management.metrics.export.wavefront.api-token=abcde")
.withPropertyValues(
"management.metrics.export.wavefront.api-token=abcde")
.run((context) -> assertThat(context).hasSingleBean(Clock.class) .run((context) -> assertThat(context).hasSingleBean(Clock.class)
.hasSingleBean(WavefrontConfig.class) .hasSingleBean(WavefrontConfig.class)
.hasSingleBean(WavefrontMeterRegistry.class) .hasSingleBean(WavefrontMeterRegistry.class)
...@@ -85,10 +87,8 @@ public class WavefrontMetricsExportAutoConfigurationTests { ...@@ -85,10 +87,8 @@ public class WavefrontMetricsExportAutoConfigurationTests {
@Test @Test
public void stopsMeterRegistryWhenContextIsClosed() { public void stopsMeterRegistryWhenContextIsClosed() {
this.runner this.runner.withUserConfiguration(BaseConfiguration.class)
.withUserConfiguration(BaseConfiguration.class) .withPropertyValues("management.metrics.export.wavefront.api-token=abcde")
.withPropertyValues(
"management.metrics.export.wavefront.api-token=abcde")
.run((context) -> { .run((context) -> {
WavefrontMeterRegistry registry = spyOnDisposableBean( WavefrontMeterRegistry registry = spyOnDisposableBean(
WavefrontMeterRegistry.class, context); WavefrontMeterRegistry.class, context);
...@@ -115,7 +115,7 @@ public class WavefrontMetricsExportAutoConfigurationTests { ...@@ -115,7 +115,7 @@ public class WavefrontMetricsExportAutoConfigurationTests {
static class BaseConfiguration { static class BaseConfiguration {
@Bean @Bean
public Clock customClock() { public Clock clock() {
return Clock.SYSTEM; return Clock.SYSTEM;
} }
...@@ -147,7 +147,8 @@ public class WavefrontMetricsExportAutoConfigurationTests { ...@@ -147,7 +147,8 @@ public class WavefrontMetricsExportAutoConfigurationTests {
static class CustomRegistryConfiguration { static class CustomRegistryConfiguration {
@Bean(destroyMethod = "stop") @Bean(destroyMethod = "stop")
public WavefrontMeterRegistry customRegistry(WavefrontConfig config, Clock clock) { public WavefrontMeterRegistry customRegistry(WavefrontConfig config,
Clock clock) {
return new WavefrontMeterRegistry(config, clock); return new WavefrontMeterRegistry(config, clock);
} }
......
...@@ -1391,10 +1391,11 @@ content into your application. Rather, pick only the properties that you need. ...@@ -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.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.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.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.api-token= # API token used when publishing metrics directly to the Wavefront API host.
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.enabled= # Whether exporting of metrics to this backend is enabled.
management.metrics.export.wavefront.api-token= # Required when publishing directly to the Wavefront API host, otherwise does nothing. 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.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.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.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.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. 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