Skip to content

Commit 63a3d2a

Browse files
committed
Upgrade client to 1.2.1, prometheusProperties, merge config props
1 parent 70089c1 commit 63a3d2a

File tree

10 files changed

+250
-311
lines changed

10 files changed

+250
-311
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusProperties.java

+156
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
package org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus;
1818

1919
import java.time.Duration;
20+
import java.util.HashMap;
21+
import java.util.Map;
2022

23+
import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusPushGatewayManager.ShutdownOperation;
2124
import org.springframework.boot.context.properties.ConfigurationProperties;
2225

2326
/**
@@ -42,6 +45,23 @@ public class PrometheusProperties {
4245
*/
4346
private boolean descriptions = true;
4447

48+
/**
49+
* Configuration options for using Prometheus Pushgateway, allowing metrics to be
50+
* pushed when they cannot be scraped.
51+
*/
52+
private final Pushgateway pushgateway = new Pushgateway();
53+
54+
/**
55+
* Histogram type for backing DistributionSummary and Timer.
56+
*/
57+
@Deprecated(since = "3.3.0")
58+
private HistogramFlavor histogramFlavor = HistogramFlavor.Prometheus;
59+
60+
/**
61+
* Additional properties to pass to the Prometheus client.
62+
*/
63+
private final Map<String, String> prometheusProperties = new HashMap<>();
64+
4565
/**
4666
* Step size (i.e. reporting frequency) to use.
4767
*/
@@ -55,6 +75,14 @@ public void setDescriptions(boolean descriptions) {
5575
this.descriptions = descriptions;
5676
}
5777

78+
public HistogramFlavor getHistogramFlavor() {
79+
return this.histogramFlavor;
80+
}
81+
82+
public void setHistogramFlavor(HistogramFlavor histogramFlavor) {
83+
this.histogramFlavor = histogramFlavor;
84+
}
85+
5886
public Duration getStep() {
5987
return this.step;
6088
}
@@ -71,4 +99,132 @@ public void setEnabled(boolean enabled) {
7199
this.enabled = enabled;
72100
}
73101

102+
public Pushgateway getPushgateway() {
103+
return this.pushgateway;
104+
}
105+
106+
public Map<String, String> getPrometheusProperties() {
107+
return this.prometheusProperties;
108+
}
109+
110+
/**
111+
* Configuration options for push-based interaction with Prometheus.
112+
*/
113+
public static class Pushgateway {
114+
115+
/**
116+
* Enable publishing over a Prometheus Pushgateway.
117+
*/
118+
private Boolean enabled = false;
119+
120+
/**
121+
* Base URL for the Pushgateway.
122+
*/
123+
private String baseUrl = "http://localhost:9091";
124+
125+
/**
126+
* Login user of the Prometheus Pushgateway.
127+
*/
128+
private String username;
129+
130+
/**
131+
* Login password of the Prometheus Pushgateway.
132+
*/
133+
private String password;
134+
135+
/**
136+
* Frequency with which to push metrics.
137+
*/
138+
private Duration pushRate = Duration.ofMinutes(1);
139+
140+
/**
141+
* Job identifier for this application instance.
142+
*/
143+
private String job;
144+
145+
/**
146+
* Grouping key for the pushed metrics.
147+
*/
148+
private Map<String, String> groupingKey = new HashMap<>();
149+
150+
/**
151+
* Operation that should be performed on shutdown.
152+
*/
153+
private ShutdownOperation shutdownOperation = ShutdownOperation.NONE;
154+
155+
public Boolean getEnabled() {
156+
return this.enabled;
157+
}
158+
159+
public void setEnabled(Boolean enabled) {
160+
this.enabled = enabled;
161+
}
162+
163+
public String getBaseUrl() {
164+
return this.baseUrl;
165+
}
166+
167+
public void setBaseUrl(String baseUrl) {
168+
this.baseUrl = baseUrl;
169+
}
170+
171+
public String getUsername() {
172+
return this.username;
173+
}
174+
175+
public void setUsername(String username) {
176+
this.username = username;
177+
}
178+
179+
public String getPassword() {
180+
return this.password;
181+
}
182+
183+
public void setPassword(String password) {
184+
this.password = password;
185+
}
186+
187+
public Duration getPushRate() {
188+
return this.pushRate;
189+
}
190+
191+
public void setPushRate(Duration pushRate) {
192+
this.pushRate = pushRate;
193+
}
194+
195+
public String getJob() {
196+
return this.job;
197+
}
198+
199+
public void setJob(String job) {
200+
this.job = job;
201+
}
202+
203+
public Map<String, String> getGroupingKey() {
204+
return this.groupingKey;
205+
}
206+
207+
public void setGroupingKey(Map<String, String> groupingKey) {
208+
this.groupingKey = groupingKey;
209+
}
210+
211+
public ShutdownOperation getShutdownOperation() {
212+
return this.shutdownOperation;
213+
}
214+
215+
public void setShutdownOperation(ShutdownOperation shutdownOperation) {
216+
this.shutdownOperation = shutdownOperation;
217+
}
218+
219+
}
220+
221+
public enum HistogramFlavor {
222+
223+
Prometheus, VictoriaMetrics;
224+
225+
HistogramFlavor() {
226+
}
227+
228+
}
229+
74230
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapter.java

+18
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus;
1818

1919
import java.time.Duration;
20+
import java.util.Map;
21+
import java.util.Properties;
2022

2123
import io.micrometer.prometheusmetrics.PrometheusConfig;
2224

@@ -55,4 +57,20 @@ public Duration step() {
5557
return get(PrometheusProperties::getStep, PrometheusConfig.super::step);
5658
}
5759

60+
@Override
61+
public Properties prometheusProperties() {
62+
return get(this::fromPropertiesMap, PrometheusConfig.super::prometheusProperties);
63+
}
64+
65+
private Properties fromPropertiesMap(PrometheusProperties prometheusProperties) {
66+
Map<String, String> map = prometheusProperties.getPrometheusProperties();
67+
if (map.isEmpty()) {
68+
return null;
69+
}
70+
Properties properties = PrometheusConfig.super.prometheusProperties();
71+
properties = (properties != null) ? properties : new Properties();
72+
properties.putAll(map);
73+
return properties;
74+
}
75+
5876
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusSimpleclientMetricsExportAutoConfiguration.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@
7171
@ConditionalOnBean(Clock.class)
7272
@ConditionalOnClass(PrometheusMeterRegistry.class)
7373
@ConditionalOnEnabledMetricsExport("prometheus")
74-
@EnableConfigurationProperties(PrometheusSimpleclientProperties.class)
74+
@EnableConfigurationProperties(PrometheusProperties.class)
7575
public class PrometheusSimpleclientMetricsExportAutoConfiguration {
7676

7777
@Bean
7878
@ConditionalOnMissingBean
79-
public PrometheusConfig simpleclientPrometheusConfig(PrometheusSimpleclientProperties prometheusProperties) {
79+
public PrometheusConfig simpleclientPrometheusConfig(PrometheusProperties prometheusProperties) {
8080
return new PrometheusSimpleclientPropertiesConfigAdapter(prometheusProperties);
8181
}
8282

@@ -134,9 +134,8 @@ public static class PrometheusPushGatewayConfiguration {
134134
@Bean
135135
@ConditionalOnMissingBean
136136
public PrometheusPushGatewayManager prometheusPushGatewayManager(CollectorRegistry collectorRegistry,
137-
PrometheusSimpleclientProperties prometheusProperties, Environment environment)
138-
throws MalformedURLException {
139-
PrometheusSimpleclientProperties.Pushgateway properties = prometheusProperties.getPushgateway();
137+
PrometheusProperties prometheusProperties, Environment environment) throws MalformedURLException {
138+
PrometheusProperties.Pushgateway properties = prometheusProperties.getPushgateway();
140139
Duration pushRate = properties.getPushRate();
141140
String job = getJob(properties, environment);
142141
Map<String, String> groupingKey = properties.getGroupingKey();
@@ -154,7 +153,7 @@ private PushGateway initializePushGateway(String url) throws MalformedURLExcepti
154153
return new PushGateway(new URL(url));
155154
}
156155

157-
private String getJob(PrometheusSimpleclientProperties.Pushgateway properties, Environment environment) {
156+
private String getJob(PrometheusProperties.Pushgateway properties, Environment environment) {
158157
String job = properties.getJob();
159158
job = (job != null) ? job : environment.getProperty("spring.application.name");
160159
return (job != null) ? job : FALLBACK_JOB;

0 commit comments

Comments
 (0)