Skip to content

Commit e98235c

Browse files
committed
fix review comments
1 parent c44c339 commit e98235c

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public PrometheusScrapeEndpoint prometheusEndpoint(
105105
*/
106106
@Configuration
107107
@ConditionalOnClass(PushGateway.class)
108-
@ConditionalOnProperty(prefix = "management.metrics.export.prometheus.pushgateway", name = "enabled", havingValue = "true", matchIfMissing = false)
109-
public static class PrometheusPushGatewayConfiguration {
108+
@ConditionalOnProperty(prefix = "management.metrics.export.prometheus.pushgateway", name = "enabled")
109+
private static class PrometheusPushGatewayConfiguration {
110110

111111
@Bean
112112
public PushGatewayHandler pushGatewayHandler(CollectorRegistry collectorRegistry,
@@ -138,7 +138,7 @@ public PushGatewayHandler(CollectorRegistry collectorRegistry,
138138
this.pushgatewayProperties.getBaseUrl());
139139
this.environment = environment;
140140
this.executorService = Executors.newSingleThreadScheduledExecutor((r) -> {
141-
final Thread thread = new Thread(r);
141+
Thread thread = new Thread(r);
142142
thread.setDaemon(true);
143143
thread.setName("micrometer-pushgateway");
144144
return thread;
@@ -150,7 +150,7 @@ public PushGatewayHandler(CollectorRegistry collectorRegistry,
150150

151151
void push() {
152152
try {
153-
this.pushGateway.pushAdd(this.collectorRegistry, job(),
153+
this.pushGateway.pushAdd(this.collectorRegistry, getJobName(),
154154
this.pushgatewayProperties.getGroupingKeys());
155155
}
156156
catch (UnknownHostException ex) {
@@ -172,26 +172,30 @@ void shutdown() {
172172
push();
173173
}
174174
if (this.pushgatewayProperties.isDeleteOnShutdown()) {
175-
try {
176-
this.pushGateway.delete(job(),
177-
this.pushgatewayProperties.getGroupingKeys());
178-
}
179-
catch (Throwable throwable) {
180-
this.logger.error(
181-
"Unable to delete metrics from Prometheus Pushgateway",
182-
throwable);
183-
}
175+
delete();
184176
}
185177
}
186178

187-
private String job() {
179+
private void delete() {
180+
try {
181+
this.pushGateway.delete(getJobName(),
182+
this.pushgatewayProperties.getGroupingKeys());
183+
}
184+
catch (Throwable throwable) {
185+
this.logger.error(
186+
"Unable to delete metrics from Prometheus Pushgateway",
187+
throwable);
188+
}
189+
}
190+
191+
private String getJobName() {
188192
String job = this.pushgatewayProperties.getJob();
189193
if (job == null) {
190194
job = this.environment.getProperty("spring.application.name");
191195
}
192196
if (job == null) {
193197
// There's a history of Prometheus spring integration defaulting the
194-
// job name to "spring" from when
198+
// getJobName name to "spring" from when
195199
// Prometheus integration didn't exist in Spring itself.
196200
job = "spring";
197201
}

spring-boot-project/spring-boot-dependencies/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@
140140
<nio-multipart-parser.version>1.1.0</nio-multipart-parser.version>
141141
<pooled-jms-version>1.0.3</pooled-jms-version>
142142
<postgresql.version>42.2.5</postgresql.version>
143-
<!-- need to take care that this version harmonizes with micrometer ones -->
144143
<prometheus-pushgateway.version>0.5.0</prometheus-pushgateway.version>
145144
<quartz.version>2.3.0</quartz.version>
146145
<querydsl.version>4.2.1</querydsl.version>

0 commit comments

Comments
 (0)