Skip to content

Commit 1e2d5a1

Browse files
committed
Auto-configure Micrometer's HumioMeterRegistry
Closes gh-14804
1 parent 9a80e88 commit 1e2d5a1

File tree

13 files changed

+572
-0
lines changed

13 files changed

+572
-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
@@ -127,6 +127,11 @@
127127
<artifactId>micrometer-registry-graphite</artifactId>
128128
<optional>true</optional>
129129
</dependency>
130+
<dependency>
131+
<groupId>io.micrometer</groupId>
132+
<artifactId>micrometer-registry-humio</artifactId>
133+
<optional>true</optional>
134+
</dependency>
130135
<dependency>
131136
<groupId>io.micrometer</groupId>
132137
<artifactId>micrometer-registry-influx</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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.humio;
18+
19+
import io.micrometer.core.instrument.Clock;
20+
import io.micrometer.humio.HumioConfig;
21+
import io.micrometer.humio.HumioMeterRegistry;
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 Humio.
39+
*
40+
* @author Andy Wilkinson
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(HumioMeterRegistry.class)
49+
@ConditionalOnProperty(prefix = "management.metrics.export.humio", name = "enabled", havingValue = "true", matchIfMissing = true)
50+
@EnableConfigurationProperties(HumioProperties.class)
51+
public class HumioMetricsExportAutoConfiguration {
52+
53+
@Bean
54+
@ConditionalOnMissingBean
55+
public HumioConfig humioConfig(HumioProperties humioProperties) {
56+
return new HumioPropertiesConfigAdapter(humioProperties);
57+
}
58+
59+
@Bean
60+
@ConditionalOnMissingBean
61+
public HumioMeterRegistry humioMeterRegistry(HumioConfig humioConfig, Clock clock) {
62+
return new HumioMeterRegistry(humioConfig, clock);
63+
}
64+
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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.humio;
18+
19+
import java.time.Duration;
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
23+
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryProperties;
24+
import org.springframework.boot.context.properties.ConfigurationProperties;
25+
26+
/**
27+
* {@link ConfigurationProperties} for configuring Humio metrics export.
28+
*
29+
* @author Andy Wilkinson
30+
* @since 2.1.0
31+
*/
32+
@ConfigurationProperties(prefix = "management.metrics.export.humio")
33+
public class HumioProperties extends StepRegistryProperties {
34+
35+
/**
36+
* Humio API token.
37+
*/
38+
private String apiToken;
39+
40+
/**
41+
* Connection timeout for requests to Humio.
42+
*/
43+
private Duration connectTimeout = Duration.ofSeconds(5);
44+
45+
/**
46+
* Name of the repository to publish metrics to.
47+
*/
48+
private String repository = "sandbox";
49+
50+
/**
51+
* Humio tags describing the data source in which metrics will be stored. Humio tags
52+
* are a distinct concept from Micrometer's tags. Micrometer's tags are used to divide
53+
* metrics along dimensional boundaries.
54+
*/
55+
private Map<String, String> tags = new HashMap<>();
56+
57+
/**
58+
* URI to ship metrics to. If you need to publish metrics to an internal proxy
59+
* en-route to Humio, you can define the location of the proxy with this.
60+
*/
61+
private String uri = "https://cloud.humio.com";
62+
63+
public String getApiToken() {
64+
return this.apiToken;
65+
}
66+
67+
public void setApiToken(String apiToken) {
68+
this.apiToken = apiToken;
69+
}
70+
71+
@Override
72+
public Duration getConnectTimeout() {
73+
return this.connectTimeout;
74+
}
75+
76+
@Override
77+
public void setConnectTimeout(Duration connectTimeout) {
78+
this.connectTimeout = connectTimeout;
79+
}
80+
81+
public String getRepository() {
82+
return this.repository;
83+
}
84+
85+
public void setRepository(String repository) {
86+
this.repository = repository;
87+
}
88+
89+
public Map<String, String> getTags() {
90+
return this.tags;
91+
}
92+
93+
public void setTags(Map<String, String> tags) {
94+
this.tags = tags;
95+
}
96+
97+
public String getUri() {
98+
return this.uri;
99+
}
100+
101+
public void setUri(String uri) {
102+
this.uri = uri;
103+
}
104+
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.humio;
18+
19+
import java.util.Map;
20+
21+
import io.micrometer.humio.HumioConfig;
22+
23+
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapter;
24+
25+
/**
26+
* Adapter to convert {@link HumioProperties} to a {@link HumioConfig}.
27+
*
28+
* @author Andy Wilkinson
29+
*/
30+
class HumioPropertiesConfigAdapter extends
31+
StepRegistryPropertiesConfigAdapter<HumioProperties> implements HumioConfig {
32+
33+
HumioPropertiesConfigAdapter(HumioProperties properties) {
34+
super(properties);
35+
}
36+
37+
@Override
38+
public String get(String k) {
39+
return null;
40+
}
41+
42+
@Override
43+
public String uri() {
44+
return get(HumioProperties::getUri, HumioConfig.super::uri);
45+
}
46+
47+
@Override
48+
public String repository() {
49+
return get(HumioProperties::getRepository, HumioConfig.super::repository);
50+
}
51+
52+
@Override
53+
public Map<String, String> tags() {
54+
return get(HumioProperties::getTags, HumioConfig.super::tags);
55+
}
56+
57+
@Override
58+
public String apiToken() {
59+
return get(HumioProperties::getApiToken, HumioConfig.super::apiToken);
60+
}
61+
62+
}
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 Humio.
19+
*/
20+
package org.springframework.boot.actuate.autoconfigure.metrics.export.humio;

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
@@ -52,6 +52,7 @@ org.springframework.boot.actuate.autoconfigure.metrics.export.dynatrace.Dynatrac
5252
org.springframework.boot.actuate.autoconfigure.metrics.export.elastic.ElasticMetricsExportAutoConfiguration,\
5353
org.springframework.boot.actuate.autoconfigure.metrics.export.ganglia.GangliaMetricsExportAutoConfiguration,\
5454
org.springframework.boot.actuate.autoconfigure.metrics.export.graphite.GraphiteMetricsExportAutoConfiguration,\
55+
org.springframework.boot.actuate.autoconfigure.metrics.export.humio.HumioMetricsExportAutoConfiguration,\
5556
org.springframework.boot.actuate.autoconfigure.metrics.export.influx.InfluxMetricsExportAutoConfiguration,\
5657
org.springframework.boot.actuate.autoconfigure.metrics.export.jmx.JmxMetricsExportAutoConfiguration,\
5758
org.springframework.boot.actuate.autoconfigure.metrics.export.kairos.KairosMetricsExportAutoConfiguration,\

0 commit comments

Comments
 (0)