Skip to content

Commit c1c162a

Browse files
committed
Polish "Add auto-configuraton for exporting metrics to Wavefront"
Closes gh-12068
1 parent 142dbb2 commit c1c162a

File tree

6 files changed

+54
-36
lines changed

6 files changed

+54
-36
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.springframework.context.annotation.Bean;
3434
import org.springframework.context.annotation.Configuration;
3535

36-
3736
/**
3837
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Wavefront.
3938
*
@@ -57,7 +56,9 @@ public WavefrontConfig wavefrontConfig(WavefrontProperties props) {
5756

5857
@Bean(destroyMethod = "stop")
5958
@ConditionalOnMissingBean
60-
public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig config, Clock clock) {
59+
public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig config,
60+
Clock clock) {
6161
return new WavefrontMeterRegistry(config, clock);
6262
}
63+
6364
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontProperties.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
1818

19+
import java.net.URI;
20+
1921
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryProperties;
2022
import org.springframework.boot.context.properties.ConfigurationProperties;
2123

@@ -27,36 +29,41 @@
2729
*/
2830
@ConfigurationProperties("management.metrics.export.wavefront")
2931
public class WavefrontProperties extends StepRegistryProperties {
32+
3033
/**
31-
* The URI to publish metrics to. The URI could represent a Wavefront sidecar or the
32-
* Wavefront API host. This host could also represent an internal proxy set up in your environment
33-
* that forwards metrics data to the Wavefront API host.
34+
* URI to which metrics are published. May represent a Wavefront sidecar or the
35+
* Wavefront API host. This host could also represent an internal proxy set up in your
36+
* environment that forwards metrics data to the Wavefront API host.
3437
*
35-
* If publishing metrics to a Wavefront proxy (as described in https://docs.wavefront.com/proxies_installing.html),
36-
* the host must be in the proxy://HOST:PORT format.
38+
* If publishing metrics to a Wavefront proxy (as described in
39+
* https://docs.wavefront.com/proxies_installing.html), the host must be in the
40+
* proxy://HOST:PORT format.
3741
*/
38-
private String uri;
42+
private URI uri;
3943

4044
/**
41-
* Uniquely identifies the app instance that is publishing metrics to Wavefront. Defaults to the local host name.
45+
* Unique identifier for the app instance that is the source of metrics being
46+
* published to Wavefront. Defaults to the local host name.
4247
*/
4348
private String source;
4449

4550
/**
46-
* Required when publishing directly to the Wavefront API host, otherwise does nothing.
51+
* API token used when publishing metrics directly to the Wavefront API host.
4752
*/
4853
private String apiToken;
4954

5055
/**
51-
* 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.
56+
* Global prefix to separate metrics originating from this app's white box
57+
* instrumentation from those originating from other Wavefront integrations when
58+
* viewed in the Wavefront UI.
5259
*/
5360
private String globalPrefix;
5461

55-
public String getUri() {
62+
public URI getUri() {
5663
return this.uri;
5764
}
5865

59-
public void setUri(String uri) {
66+
public void setUri(URI uri) {
6067
this.uri = uri;
6168
}
6269

@@ -83,4 +90,5 @@ public String getGlobalPrefix() {
8390
public void setGlobalPrefix(String globalPrefix) {
8491
this.globalPrefix = globalPrefix;
8592
}
93+
8694
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapter.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
* @author Jon Schneider
2727
* @since 2.0.0
2828
*/
29-
public class WavefrontPropertiesConfigAdapter extends PropertiesConfigAdapter<WavefrontProperties> implements WavefrontConfig {
29+
public class WavefrontPropertiesConfigAdapter
30+
extends PropertiesConfigAdapter<WavefrontProperties> implements WavefrontConfig {
3031

3132
public WavefrontPropertiesConfigAdapter(WavefrontProperties properties) {
3233
super(properties);
@@ -39,7 +40,7 @@ public String get(String k) {
3940

4041
@Override
4142
public String uri() {
42-
return get(WavefrontProperties::getUri, WavefrontConfig.DEFAULT_DIRECT::uri);
43+
return get(this::getUriAsString, WavefrontConfig.DEFAULT_DIRECT::uri);
4344
}
4445

4546
@Override
@@ -54,6 +55,12 @@ public String apiToken() {
5455

5556
@Override
5657
public String globalPrefix() {
57-
return get(WavefrontProperties::getGlobalPrefix, WavefrontConfig.super::globalPrefix);
58+
return get(WavefrontProperties::getGlobalPrefix,
59+
WavefrontConfig.super::globalPrefix);
5860
}
61+
62+
private String getUriAsString(WavefrontProperties properties) {
63+
return properties.getUri() == null ? null : properties.getUri().toString();
64+
}
65+
5966
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/package-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,6 @@
1515
*/
1616

1717
/**
18-
* Support for exporting actuator metrics to StatsD.
18+
* Support for exporting actuator metrics to Wavefront.
1919
*/
2020
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfigurationTests.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,33 @@ public void backsOffWithoutAClock() {
5252
.doesNotHaveBean(WavefrontMeterRegistry.class));
5353
}
5454

55+
@Test
56+
public void failsWithoutAnApiTokenWhenPublishingDirectly() {
57+
this.runner.withUserConfiguration(BaseConfiguration.class)
58+
.run((context) -> assertThat(context).hasFailed());
59+
}
60+
5561
@Test
5662
public void autoConfigurationCanBeDisabled() {
5763
this.runner.withUserConfiguration(BaseConfiguration.class)
58-
.withPropertyValues(
59-
"management.metrics.export.wavefront.enabled=false")
64+
.withPropertyValues("management.metrics.export.wavefront.enabled=false")
6065
.run((context) -> assertThat(context)
6166
.doesNotHaveBean(WavefrontMeterRegistry.class)
6267
.doesNotHaveBean(WavefrontConfig.class));
6368
}
6469

6570
@Test
6671
public void allowsConfigToBeCustomized() {
67-
this.runner
68-
.withUserConfiguration(CustomConfigConfiguration.class)
72+
this.runner.withUserConfiguration(CustomConfigConfiguration.class)
6973
.run((context) -> assertThat(context).hasSingleBean(Clock.class)
7074
.hasSingleBean(WavefrontMeterRegistry.class)
7175
.hasSingleBean(WavefrontConfig.class).hasBean("customConfig"));
7276
}
7377

7478
@Test
7579
public void allowsRegistryToBeCustomized() {
76-
this.runner
77-
.withUserConfiguration(CustomRegistryConfiguration.class)
78-
.withPropertyValues(
79-
"management.metrics.export.wavefront.api-token=abcde")
80+
this.runner.withUserConfiguration(CustomRegistryConfiguration.class)
81+
.withPropertyValues("management.metrics.export.wavefront.api-token=abcde")
8082
.run((context) -> assertThat(context).hasSingleBean(Clock.class)
8183
.hasSingleBean(WavefrontConfig.class)
8284
.hasSingleBean(WavefrontMeterRegistry.class)
@@ -85,10 +87,8 @@ public void allowsRegistryToBeCustomized() {
8587

8688
@Test
8789
public void stopsMeterRegistryWhenContextIsClosed() {
88-
this.runner
89-
.withUserConfiguration(BaseConfiguration.class)
90-
.withPropertyValues(
91-
"management.metrics.export.wavefront.api-token=abcde")
90+
this.runner.withUserConfiguration(BaseConfiguration.class)
91+
.withPropertyValues("management.metrics.export.wavefront.api-token=abcde")
9292
.run((context) -> {
9393
WavefrontMeterRegistry registry = spyOnDisposableBean(
9494
WavefrontMeterRegistry.class, context);
@@ -115,7 +115,7 @@ private <T> T spyOnDisposableBean(Class<T> type,
115115
static class BaseConfiguration {
116116

117117
@Bean
118-
public Clock customClock() {
118+
public Clock clock() {
119119
return Clock.SYSTEM;
120120
}
121121

@@ -147,7 +147,8 @@ public String uri() {
147147
static class CustomRegistryConfiguration {
148148

149149
@Bean(destroyMethod = "stop")
150-
public WavefrontMeterRegistry customRegistry(WavefrontConfig config, Clock clock) {
150+
public WavefrontMeterRegistry customRegistry(WavefrontConfig config,
151+
Clock clock) {
151152
return new WavefrontMeterRegistry(config, clock);
152153
}
153154

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,10 +1391,11 @@ content into your application. Rather, pick only the properties that you need.
13911391
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.
13921392
management.metrics.export.statsd.port=8125 # Port of the StatsD server to receive exported metrics.
13931393
management.metrics.export.statsd.queue-size=2147483647 # Maximum size of the queue of items waiting to be sent to the StatsD server.
1394-
management.metrics.export.wavefront.uri= # Optional custom URI for the Wavefront API or proxy.
1395-
management.metrics.export.wavefront.source= # Uniquely identifies the app instance that is publishing metrics to Wavefront. Defaults to the local host name.
1396-
management.metrics.export.wavefront.api-token= # Required when publishing directly to the Wavefront API host, otherwise does nothing.
1397-
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.
1394+
management.metrics.export.wavefront.api-token= # API token used when publishing metrics directly to the Wavefront API host.
1395+
management.metrics.export.wavefront.enabled= # Whether exporting of metrics to this backend is enabled.
1396+
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.
1397+
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.
1398+
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.
13981399
management.metrics.use-global-registry=true # Whether auto-configured MeterRegistry implementations should be bound to the global static registry on Metrics.
13991400
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.
14001401
management.metrics.web.client.record-request-percentiles=false # Whether instrumented requests record percentiles histogram buckets by default.

0 commit comments

Comments
 (0)