Skip to content

Commit 117fc0d

Browse files
committed
WIP: Add support for OpenTSDBMeterRegistry
1 parent ac06a54 commit 117fc0d

File tree

12 files changed

+639
-0
lines changed

12 files changed

+639
-0
lines changed

documentation/spring-boot-docs/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ dependencies {
274274
javadocMacros("com.redis:testcontainers-redis")
275275
javadocMacros("io.lettuce:lettuce-core")
276276
javadocMacros("io.micrometer:micrometer-registry-new-relic")
277+
javadocMacros("io.micrometer:micrometer-registry-opentsdb")
277278
javadocMacros("io.micrometer:micrometer-registry-otlp")
278279
javadocMacros("io.opentelemetry:opentelemetry-sdk-logs")
279280
javadocMacros("io.opentelemetry:opentelemetry-sdk-metrics")

module/spring-boot-micrometer-metrics/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ dependencies {
5252
optional("io.micrometer:micrometer-registry-jmx")
5353
optional("io.micrometer:micrometer-registry-kairos")
5454
optional("io.micrometer:micrometer-registry-new-relic")
55+
optional("io.micrometer:micrometer-registry-opentsdb")
5556
optional("io.micrometer:micrometer-registry-otlp")
5657
optional("io.micrometer:micrometer-registry-prometheus")
5758
optional("io.micrometer:micrometer-registry-stackdriver") {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2012-present 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+
* https://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.micrometer.metrics.autoconfigure.export.opentsdb;
18+
19+
import org.jspecify.annotations.Nullable;
20+
21+
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
22+
23+
/**
24+
* Details required to establish a connection to OpenTSDB.
25+
*
26+
* @author Moritz Halbritter
27+
* @since 4.1.0
28+
*/
29+
public interface OpenTSDBMetricsConnectionDetails extends ConnectionDetails {
30+
31+
/**
32+
* Address to where metrics will be published.
33+
* @return the address to where metrics will be published
34+
*/
35+
@Nullable String getUri();
36+
37+
/**
38+
* Username for the OpenTSDB server.
39+
* @return the username for the OpenTSDB server
40+
*/
41+
default @Nullable String getUsername() {
42+
return null;
43+
}
44+
45+
/**
46+
* Password for the OpenTSDB server.
47+
* @return the password for the OpenTSDB server
48+
*/
49+
default @Nullable String getPassword() {
50+
return null;
51+
}
52+
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright 2012-present 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+
* https://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.micrometer.metrics.autoconfigure.export.opentsdb;
18+
19+
import io.micrometer.core.instrument.Clock;
20+
import io.micrometer.opentsdb.OpenTSDBConfig;
21+
import io.micrometer.opentsdb.OpenTSDBMeterRegistry;
22+
import org.jspecify.annotations.Nullable;
23+
24+
import org.springframework.boot.autoconfigure.AutoConfiguration;
25+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
26+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
27+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
28+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
29+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
30+
import org.springframework.boot.micrometer.metrics.autoconfigure.CompositeMeterRegistryAutoConfiguration;
31+
import org.springframework.boot.micrometer.metrics.autoconfigure.MetricsAutoConfiguration;
32+
import org.springframework.boot.micrometer.metrics.autoconfigure.export.ConditionalOnEnabledMetricsExport;
33+
import org.springframework.boot.micrometer.metrics.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration;
34+
import org.springframework.context.annotation.Bean;
35+
36+
/**
37+
* {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to OpenTSDB.
38+
*
39+
* @author Moritz Halbritter
40+
* @since 4.1.0
41+
*/
42+
@AutoConfiguration(
43+
before = { CompositeMeterRegistryAutoConfiguration.class, SimpleMetricsExportAutoConfiguration.class },
44+
after = MetricsAutoConfiguration.class)
45+
@ConditionalOnBean(Clock.class)
46+
@ConditionalOnClass({ OpenTSDBMeterRegistry.class })
47+
@ConditionalOnEnabledMetricsExport("opentsdb")
48+
@EnableConfigurationProperties({ OpenTSDBMetricsProperties.class })
49+
public final class OpenTSDBMetricsExportAutoConfiguration {
50+
51+
private final OpenTSDBMetricsProperties properties;
52+
53+
OpenTSDBMetricsExportAutoConfiguration(OpenTSDBMetricsProperties properties) {
54+
this.properties = properties;
55+
}
56+
57+
@Bean
58+
@ConditionalOnMissingBean
59+
OpenTSDBMetricsConnectionDetails openTSDBMetricsConnectionDetails() {
60+
return new PropertiesOpenTSDBMetricsConnectionDetails(this.properties);
61+
}
62+
63+
@Bean
64+
@ConditionalOnMissingBean
65+
OpenTSDBConfig openTSDBConfig(OpenTSDBMetricsConnectionDetails connectionDetails) {
66+
return new OpenTSDBMetricsPropertiesConfigAdapter(this.properties, connectionDetails);
67+
}
68+
69+
@Bean
70+
@ConditionalOnMissingBean
71+
OpenTSDBMeterRegistry openTSDBMeterRegistry(OpenTSDBConfig openTSDBConfig, Clock clock) {
72+
return OpenTSDBMeterRegistry.builder(openTSDBConfig).clock(clock).build();
73+
}
74+
75+
/**
76+
* Adapts {@link OpenTSDBMetricsProperties} to
77+
* {@link OpenTSDBMetricsConnectionDetails}.
78+
*/
79+
static class PropertiesOpenTSDBMetricsConnectionDetails implements OpenTSDBMetricsConnectionDetails {
80+
81+
private final OpenTSDBMetricsProperties properties;
82+
83+
PropertiesOpenTSDBMetricsConnectionDetails(OpenTSDBMetricsProperties properties) {
84+
this.properties = properties;
85+
}
86+
87+
@Override
88+
public @Nullable String getUri() {
89+
return this.properties.getUri();
90+
}
91+
92+
@Override
93+
public @Nullable String getUsername() {
94+
return this.properties.getUsername();
95+
}
96+
97+
@Override
98+
public @Nullable String getPassword() {
99+
return this.properties.getPassword();
100+
}
101+
102+
}
103+
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2012-present 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+
* https://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.micrometer.metrics.autoconfigure.export.opentsdb;
18+
19+
import org.jspecify.annotations.Nullable;
20+
21+
import org.springframework.boot.context.properties.ConfigurationProperties;
22+
import org.springframework.boot.micrometer.metrics.autoconfigure.export.properties.StepRegistryProperties;
23+
24+
/**
25+
* {@link ConfigurationProperties @ConfigurationProperties} for configuring OpenTSDB
26+
* metrics export.
27+
*
28+
* @author Moritz Halbritter
29+
* @since 4.1.0
30+
*/
31+
@ConfigurationProperties("management.opentsdb.metrics.export")
32+
public class OpenTSDBMetricsProperties extends StepRegistryProperties {
33+
34+
/**
35+
* URI of the OpenTSDB server.
36+
*/
37+
private @Nullable String uri;
38+
39+
/**
40+
* Username to connect to the OpenTSDB server.
41+
*/
42+
private @Nullable String username;
43+
44+
/**
45+
* Password to connect to the OpenTSDB server.
46+
*/
47+
private @Nullable String password;
48+
49+
private @Nullable Flavor flavor;
50+
51+
public @Nullable String getUri() {
52+
return this.uri;
53+
}
54+
55+
public void setUri(@Nullable String uri) {
56+
this.uri = uri;
57+
}
58+
59+
public @Nullable String getUsername() {
60+
return this.username;
61+
}
62+
63+
public void setUsername(@Nullable String username) {
64+
this.username = username;
65+
}
66+
67+
public @Nullable String getPassword() {
68+
return this.password;
69+
}
70+
71+
public void setPassword(@Nullable String password) {
72+
this.password = password;
73+
}
74+
75+
public @Nullable Flavor getFlavor() {
76+
return this.flavor;
77+
}
78+
79+
public void setFlavor(@Nullable Flavor flavor) {
80+
this.flavor = flavor;
81+
}
82+
83+
/**
84+
* Flavor of the metrics.
85+
*/
86+
public enum Flavor {
87+
88+
/**
89+
* VictoriaMetrics.
90+
*/
91+
VICTORIA_METRICS
92+
93+
}
94+
95+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2012-present 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+
* https://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.micrometer.metrics.autoconfigure.export.opentsdb;
18+
19+
import io.micrometer.opentsdb.OpenTSDBConfig;
20+
import io.micrometer.opentsdb.OpenTSDBFlavor;
21+
import org.jspecify.annotations.Nullable;
22+
23+
import org.springframework.boot.micrometer.metrics.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapter;
24+
25+
/**
26+
* Adapter to convert {@link OpenTSDBMetricsProperties} to an {@link OpenTSDBConfig}.
27+
*
28+
* @author Moritz Halbritter
29+
*/
30+
class OpenTSDBMetricsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<OpenTSDBMetricsProperties>
31+
implements OpenTSDBConfig {
32+
33+
private final OpenTSDBMetricsConnectionDetails connectionDetails;
34+
35+
OpenTSDBMetricsPropertiesConfigAdapter(OpenTSDBMetricsProperties properties,
36+
OpenTSDBMetricsConnectionDetails connectionDetails) {
37+
super(properties);
38+
this.connectionDetails = connectionDetails;
39+
}
40+
41+
@Override
42+
public String prefix() {
43+
return "management.opentsdb.metrics.export";
44+
}
45+
46+
@Override
47+
public String uri() {
48+
return obtain((properties) -> this.connectionDetails.getUri(), OpenTSDBConfig.super::uri);
49+
}
50+
51+
@Override
52+
public @Nullable String userName() {
53+
return get((properties) -> this.connectionDetails.getUsername(), OpenTSDBConfig.super::userName);
54+
}
55+
56+
@Override
57+
public @Nullable String password() {
58+
return get((properties) -> this.connectionDetails.getPassword(), OpenTSDBConfig.super::password);
59+
}
60+
61+
@Override
62+
public @Nullable OpenTSDBFlavor flavor() {
63+
return get((properties) -> mapFlavor(properties.getFlavor()), OpenTSDBConfig.super::flavor);
64+
}
65+
66+
private @Nullable OpenTSDBFlavor mapFlavor(OpenTSDBMetricsProperties.@Nullable Flavor flavor) {
67+
if (flavor == null) {
68+
return null;
69+
}
70+
return switch (flavor) {
71+
case VICTORIA_METRICS -> OpenTSDBFlavor.VictoriaMetrics;
72+
};
73+
}
74+
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2012-present 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+
* https://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 OpenTSDB.
19+
*/
20+
@NullMarked
21+
package org.springframework.boot.micrometer.metrics.autoconfigure.export.opentsdb;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-micrometer-metrics/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ org.springframework.boot.micrometer.metrics.autoconfigure.export.influx.InfluxMe
1414
org.springframework.boot.micrometer.metrics.autoconfigure.export.jmx.JmxMetricsExportAutoConfiguration
1515
org.springframework.boot.micrometer.metrics.autoconfigure.export.kairos.KairosMetricsExportAutoConfiguration
1616
org.springframework.boot.micrometer.metrics.autoconfigure.export.newrelic.NewRelicMetricsExportAutoConfiguration
17+
org.springframework.boot.micrometer.metrics.autoconfigure.export.opentsdb.OpenTSDBMetricsExportAutoConfiguration
1718
org.springframework.boot.micrometer.metrics.autoconfigure.export.otlp.OtlpMetricsExportAutoConfiguration
1819
org.springframework.boot.micrometer.metrics.autoconfigure.export.prometheus.PrometheusMetricsExportAutoConfiguration
1920
org.springframework.boot.micrometer.metrics.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration

0 commit comments

Comments
 (0)