Skip to content

Commit 16e48c7

Browse files
author
Jon Schneider
committed
Add Wavefront support
1 parent a1ba2de commit 16e48c7

File tree

10 files changed

+402
-2
lines changed

10 files changed

+402
-2
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@
137137
<artifactId>micrometer-registry-statsd</artifactId>
138138
<optional>true</optional>
139139
</dependency>
140+
<dependency>
141+
<groupId>io.micrometer</groupId>
142+
<artifactId>micrometer-registry-wavefront</artifactId>
143+
<optional>true</optional>
144+
</dependency>
140145
<dependency>
141146
<groupId>io.projectreactor.ipc</groupId>
142147
<artifactId>reactor-netty</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2012-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
18+
19+
import io.micrometer.core.instrument.Clock;
20+
import io.micrometer.wavefront.WavefrontConfig;
21+
import io.micrometer.wavefront.WavefrontMeterRegistry;
22+
23+
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
24+
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
25+
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
26+
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
27+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
28+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
29+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
30+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
31+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
32+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
33+
import org.springframework.context.annotation.Bean;
34+
import org.springframework.context.annotation.Configuration;
35+
36+
37+
/**
38+
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Wavefront.
39+
*
40+
* @author Jon Schneider
41+
* @since 2.0.0
42+
*/
43+
@Configuration
44+
@AutoConfigureBefore(SimpleMetricsExportAutoConfiguration.class)
45+
@AutoConfigureAfter(MetricsAutoConfiguration.class)
46+
@ConditionalOnBean(Clock.class)
47+
@ConditionalOnClass(WavefrontMeterRegistry.class)
48+
@ConditionalOnProperty(prefix = "management.metrics.export.wavefront", name = "enabled", havingValue = "true", matchIfMissing = true)
49+
@EnableConfigurationProperties(WavefrontProperties.class)
50+
public class WavefrontMetricsExportAutoConfiguration {
51+
52+
@Bean
53+
@ConditionalOnMissingBean(WavefrontConfig.class)
54+
public WavefrontConfig wavefrontConfig(WavefrontProperties props) {
55+
return new WavefrontPropertiesConfigAdapter(props);
56+
}
57+
58+
@Bean(destroyMethod = "stop")
59+
@ConditionalOnMissingBean
60+
public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig config, Clock clock) {
61+
return new WavefrontMeterRegistry(config, clock);
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright 2012-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
18+
19+
import java.net.URI;
20+
21+
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryProperties;
22+
import org.springframework.boot.context.properties.ConfigurationProperties;
23+
24+
/**
25+
* {@link ConfigurationProperties} for configuring Wavefront metrics export.
26+
*
27+
* @author Jon Schneider
28+
* @since 2.0.0
29+
*/
30+
@ConfigurationProperties("management.metrics.export.wavefront")
31+
public class WavefrontProperties extends StepRegistryProperties {
32+
/**
33+
* The URI to publish metrics to. The URI could represent a Wavefront sidecar or the
34+
* Wavefront API host. This host could also represent an internal proxy set up in your environment
35+
* that forwards metrics data to the Wavefront API host.
36+
*
37+
* If publishing metrics to a Wavefront proxy (as described in https://docs.wavefront.com/proxies_installing.html),
38+
* the host must be in the proxy://HOST:PORT format.
39+
*/
40+
private URI uri;
41+
42+
/**
43+
* Uniquely identifies the app instance that is publishing metrics to Wavefront. Defaults to the local host name.
44+
*/
45+
private String source;
46+
47+
/**
48+
* Required when publishing directly to the Wavefront API host, otherwise does nothing.
49+
*/
50+
private String apiToken;
51+
52+
/**
53+
* 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.
54+
*/
55+
private String globalPrefix;
56+
57+
public URI getUri() {
58+
return this.uri;
59+
}
60+
61+
public void setUri(URI uri) {
62+
this.uri = uri;
63+
}
64+
65+
public String getSource() {
66+
return this.source;
67+
}
68+
69+
public void setSource(String source) {
70+
this.source = source;
71+
}
72+
73+
public String getApiToken() {
74+
return this.apiToken;
75+
}
76+
77+
public void setApiToken(String apiToken) {
78+
this.apiToken = apiToken;
79+
}
80+
81+
public String getGlobalPrefix() {
82+
return this.globalPrefix;
83+
}
84+
85+
public void setGlobalPrefix(String globalPrefix) {
86+
this.globalPrefix = globalPrefix;
87+
}
88+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2012-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
18+
19+
import io.micrometer.wavefront.WavefrontConfig;
20+
21+
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PropertiesConfigAdapter;
22+
23+
/**
24+
* Adapter to convert {@link WavefrontProperties} to a {@link WavefrontConfig}.
25+
*
26+
* @author Jon Schneider
27+
* @since 2.0.0
28+
*/
29+
public class WavefrontPropertiesConfigAdapter extends PropertiesConfigAdapter<WavefrontProperties> implements WavefrontConfig {
30+
31+
public WavefrontPropertiesConfigAdapter(WavefrontProperties properties) {
32+
super(properties);
33+
}
34+
35+
@Override
36+
public String get(String k) {
37+
return null;
38+
}
39+
40+
@Override
41+
public String uri() {
42+
return get(props -> props.getUri().toString(), WavefrontConfig.DEFAULT_DIRECT::uri);
43+
}
44+
45+
@Override
46+
public String source() {
47+
return get(WavefrontProperties::getSource, WavefrontConfig.super::source);
48+
}
49+
50+
@Override
51+
public String apiToken() {
52+
return get(WavefrontProperties::getApiToken, WavefrontConfig.super::apiToken);
53+
}
54+
55+
@Override
56+
public String globalPrefix() {
57+
return get(WavefrontProperties::getGlobalPrefix, WavefrontConfig.super::globalPrefix);
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Support for exporting actuator metrics to StatsD.
19+
*/
20+
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.Prometh
4747
org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration,\
4848
org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxMetricsExportAutoConfiguration,\
4949
org.springframework.boot.actuate.autoconfigure.metrics.export.statsd.StatsdMetricsExportAutoConfiguration,\
50+
org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront.WavefrontMetricsExportAutoConfiguration,\
5051
org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration,\
5152
org.springframework.boot.actuate.autoconfigure.metrics.integration.MetricsIntegrationAutoConfiguration,\
5253
org.springframework.boot.actuate.autoconfigure.metrics.web.client.RestTemplateMetricsAutoConfiguration,\

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.Map;
2020

2121
import io.micrometer.core.instrument.Clock;
22-
import io.micrometer.influx.InfluxMeterRegistry;
2322
import io.micrometer.signalfx.SignalFxConfig;
2423
import io.micrometer.signalfx.SignalFxMeterRegistry;
2524
import org.junit.Test;
@@ -50,7 +49,7 @@ public class SignalFxMetricsExportAutoConfigurationTests {
5049
@Test
5150
public void backsOffWithoutAClock() {
5251
this.runner.run((context) -> assertThat(context)
53-
.doesNotHaveBean(InfluxMeterRegistry.class));
52+
.doesNotHaveBean(SignalFxMeterRegistry.class));
5453
}
5554

5655
@Test

0 commit comments

Comments
 (0)