Skip to content

Commit e450332

Browse files
committed
Merge pull request #12068 from Jon Schneider
* gh-12068: Polish "Add auto-configuraton for exporting metrics to Wavefront" Add auto-configuration for exporting metrics to Wavefront
2 parents 46eb88c + c1c162a commit e450332

File tree

9 files changed

+417
-0
lines changed

9 files changed

+417
-0
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,64 @@
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+
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to Wavefront.
38+
*
39+
* @author Jon Schneider
40+
* @since 2.0.0
41+
*/
42+
@Configuration
43+
@AutoConfigureBefore(SimpleMetricsExportAutoConfiguration.class)
44+
@AutoConfigureAfter(MetricsAutoConfiguration.class)
45+
@ConditionalOnBean(Clock.class)
46+
@ConditionalOnClass(WavefrontMeterRegistry.class)
47+
@ConditionalOnProperty(prefix = "management.metrics.export.wavefront", name = "enabled", havingValue = "true", matchIfMissing = true)
48+
@EnableConfigurationProperties(WavefrontProperties.class)
49+
public class WavefrontMetricsExportAutoConfiguration {
50+
51+
@Bean
52+
@ConditionalOnMissingBean(WavefrontConfig.class)
53+
public WavefrontConfig wavefrontConfig(WavefrontProperties props) {
54+
return new WavefrontPropertiesConfigAdapter(props);
55+
}
56+
57+
@Bean(destroyMethod = "stop")
58+
@ConditionalOnMissingBean
59+
public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig config,
60+
Clock clock) {
61+
return new WavefrontMeterRegistry(config, clock);
62+
}
63+
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
/**
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.
37+
*
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.
41+
*/
42+
private URI uri;
43+
44+
/**
45+
* Unique identifier for the app instance that is the source of metrics being
46+
* published to Wavefront. Defaults to the local host name.
47+
*/
48+
private String source;
49+
50+
/**
51+
* API token used when publishing metrics directly to the Wavefront API host.
52+
*/
53+
private String apiToken;
54+
55+
/**
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.
59+
*/
60+
private String globalPrefix;
61+
62+
public URI getUri() {
63+
return this.uri;
64+
}
65+
66+
public void setUri(URI uri) {
67+
this.uri = uri;
68+
}
69+
70+
public String getSource() {
71+
return this.source;
72+
}
73+
74+
public void setSource(String source) {
75+
this.source = source;
76+
}
77+
78+
public String getApiToken() {
79+
return this.apiToken;
80+
}
81+
82+
public void setApiToken(String apiToken) {
83+
this.apiToken = apiToken;
84+
}
85+
86+
public String getGlobalPrefix() {
87+
return this.globalPrefix;
88+
}
89+
90+
public void setGlobalPrefix(String globalPrefix) {
91+
this.globalPrefix = globalPrefix;
92+
}
93+
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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
30+
extends PropertiesConfigAdapter<WavefrontProperties> implements WavefrontConfig {
31+
32+
public WavefrontPropertiesConfigAdapter(WavefrontProperties properties) {
33+
super(properties);
34+
}
35+
36+
@Override
37+
public String get(String k) {
38+
return null;
39+
}
40+
41+
@Override
42+
public String uri() {
43+
return get(this::getUriAsString, WavefrontConfig.DEFAULT_DIRECT::uri);
44+
}
45+
46+
@Override
47+
public String source() {
48+
return get(WavefrontProperties::getSource, WavefrontConfig.super::source);
49+
}
50+
51+
@Override
52+
public String apiToken() {
53+
return get(WavefrontProperties::getApiToken, WavefrontConfig.super::apiToken);
54+
}
55+
56+
@Override
57+
public String globalPrefix() {
58+
return get(WavefrontProperties::getGlobalPrefix,
59+
WavefrontConfig.super::globalPrefix);
60+
}
61+
62+
private String getUriAsString(WavefrontProperties properties) {
63+
return properties.getUri() == null ? null : properties.getUri().toString();
64+
}
65+
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
/**
18+
* Support for exporting actuator metrics to Wavefront.
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,\

0 commit comments

Comments
 (0)