Skip to content

Commit 5f2517f

Browse files
committed
Auto-configure AppOptics metrics
Closes gh-14819
1 parent 3dc74fe commit 5f2517f

File tree

12 files changed

+524
-0
lines changed

12 files changed

+524
-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
@@ -97,6 +97,11 @@
9797
<artifactId>micrometer-jersey2</artifactId>
9898
<optional>true</optional>
9999
</dependency>
100+
<dependency>
101+
<groupId>io.micrometer</groupId>
102+
<artifactId>micrometer-registry-appoptics</artifactId>
103+
<optional>true</optional>
104+
</dependency>
100105
<dependency>
101106
<groupId>io.micrometer</groupId>
102107
<artifactId>micrometer-registry-atlas</artifactId>
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.appoptics;
18+
19+
import io.micrometer.appoptics.AppOpticsConfig;
20+
import io.micrometer.appoptics.AppOpticsMeterRegistry;
21+
import io.micrometer.core.instrument.Clock;
22+
23+
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
24+
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
25+
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
26+
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
27+
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
28+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
29+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
30+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
31+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
32+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
33+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
34+
import org.springframework.context.annotation.Bean;
35+
import org.springframework.context.annotation.Configuration;
36+
37+
/**
38+
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to AppOptics.
39+
*
40+
* @author Stephane Nicoll
41+
* @since 2.1.0
42+
*/
43+
@Configuration
44+
@AutoConfigureBefore({ CompositeMeterRegistryAutoConfiguration.class,
45+
SimpleMetricsExportAutoConfiguration.class })
46+
@AutoConfigureAfter(MetricsAutoConfiguration.class)
47+
@ConditionalOnBean(Clock.class)
48+
@ConditionalOnClass(AppOpticsMeterRegistry.class)
49+
@ConditionalOnProperty(prefix = "management.metrics.export.appoptics", name = "enabled", havingValue = "true", matchIfMissing = true)
50+
@EnableConfigurationProperties(AppOpticsProperties.class)
51+
public class AppOpticsMetricsExportAutoConfiguration {
52+
53+
@Bean
54+
@ConditionalOnMissingBean
55+
public AppOpticsConfig appOpticsConfig(AppOpticsProperties appOpticsProperties) {
56+
return new AppOpticsPropertiesConfigAdapter(appOpticsProperties);
57+
}
58+
59+
@Bean
60+
@ConditionalOnMissingBean
61+
public AppOpticsMeterRegistry appOpticsMeterRegistry(AppOpticsConfig config,
62+
Clock clock) {
63+
return new AppOpticsMeterRegistry(config, clock);
64+
}
65+
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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.appoptics;
18+
19+
import java.time.Duration;
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 AppOptics metrics export.
26+
*
27+
* @author Stephane Nicoll
28+
* @since 2.1.0
29+
*/
30+
@ConfigurationProperties(prefix = "management.metrics.export.appoptics")
31+
public class AppOpticsProperties extends StepRegistryProperties {
32+
33+
/**
34+
* URI to ship metrics to.
35+
*/
36+
public String uri = "https://api.appoptics.com/v1/measurements";
37+
38+
/**
39+
* AppOptics API token.
40+
*/
41+
public String apiToken;
42+
43+
/**
44+
* Tag that will be mapped to "@host" when shipping metrics to AppOptics.
45+
*/
46+
public String hostTag = "instance";
47+
48+
/**
49+
* Number of measurements per request to use for this backend. If more measurements
50+
* are found, then multiple requests will be made.
51+
*/
52+
private Integer batchSize = 500;
53+
54+
/**
55+
* Connection timeout for requests to this backend.
56+
*/
57+
private Duration connectTimeout = Duration.ofSeconds(5);
58+
59+
public String getUri() {
60+
return this.uri;
61+
}
62+
63+
public void setUri(String uri) {
64+
this.uri = uri;
65+
}
66+
67+
public String getApiToken() {
68+
return this.apiToken;
69+
}
70+
71+
public void setApiToken(String apiToken) {
72+
this.apiToken = apiToken;
73+
}
74+
75+
public String getHostTag() {
76+
return this.hostTag;
77+
}
78+
79+
public void setHostTag(String hostTag) {
80+
this.hostTag = hostTag;
81+
}
82+
83+
@Override
84+
public Integer getBatchSize() {
85+
return this.batchSize;
86+
}
87+
88+
@Override
89+
public void setBatchSize(Integer batchSize) {
90+
this.batchSize = batchSize;
91+
}
92+
93+
@Override
94+
public Duration getConnectTimeout() {
95+
return this.connectTimeout;
96+
}
97+
98+
@Override
99+
public void setConnectTimeout(Duration connectTimeout) {
100+
this.connectTimeout = connectTimeout;
101+
}
102+
103+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.appoptics;
18+
19+
import io.micrometer.appoptics.AppOpticsConfig;
20+
21+
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapter;
22+
23+
/**
24+
* Adapter to convert {@link AppOpticsProperties} to an {@link AppOpticsConfig}.
25+
*
26+
* @author Stephane Nicoll
27+
*/
28+
class AppOpticsPropertiesConfigAdapter
29+
extends StepRegistryPropertiesConfigAdapter<AppOpticsProperties>
30+
implements AppOpticsConfig {
31+
32+
AppOpticsPropertiesConfigAdapter(AppOpticsProperties properties) {
33+
super(properties);
34+
}
35+
36+
public String uri() {
37+
return get(AppOpticsProperties::getUri, AppOpticsConfig.super::uri);
38+
}
39+
40+
public String token() {
41+
return get(AppOpticsProperties::getApiToken, AppOpticsConfig.super::token);
42+
}
43+
44+
public String hostTag() {
45+
return get(AppOpticsProperties::getHostTag, AppOpticsConfig.super::hostTag);
46+
}
47+
48+
}
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 AppOptics.
19+
*/
20+
package org.springframework.boot.actuate.autoconfigure.metrics.export.appoptics;

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
@@ -46,6 +46,7 @@ org.springframework.boot.actuate.autoconfigure.metrics.MetricsEndpointAutoConfig
4646
org.springframework.boot.actuate.autoconfigure.metrics.SystemMetricsAutoConfiguration,\
4747
org.springframework.boot.actuate.autoconfigure.metrics.amqp.RabbitMetricsAutoConfiguration,\
4848
org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsAutoConfiguration,\
49+
org.springframework.boot.actuate.autoconfigure.metrics.export.appoptics.AppOpticsMetricsExportAutoConfiguration,\
4950
org.springframework.boot.actuate.autoconfigure.metrics.export.atlas.AtlasMetricsExportAutoConfiguration,\
5051
org.springframework.boot.actuate.autoconfigure.metrics.export.datadog.DatadogMetricsExportAutoConfiguration,\
5152
org.springframework.boot.actuate.autoconfigure.metrics.export.dynatrace.DynatraceMetricsExportAutoConfiguration,\

0 commit comments

Comments
 (0)