Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkarlsen committed Sep 10, 2018
1 parent c44c339 commit e98235c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public PrometheusScrapeEndpoint prometheusEndpoint(
*/
@Configuration
@ConditionalOnClass(PushGateway.class)
@ConditionalOnProperty(prefix = "management.metrics.export.prometheus.pushgateway", name = "enabled", havingValue = "true", matchIfMissing = false)
public static class PrometheusPushGatewayConfiguration {
@ConditionalOnProperty(prefix = "management.metrics.export.prometheus.pushgateway", name = "enabled")
private static class PrometheusPushGatewayConfiguration {

@Bean
public PushGatewayHandler pushGatewayHandler(CollectorRegistry collectorRegistry,
Expand Down Expand Up @@ -138,7 +138,7 @@ public PushGatewayHandler(CollectorRegistry collectorRegistry,
this.pushgatewayProperties.getBaseUrl());
this.environment = environment;
this.executorService = Executors.newSingleThreadScheduledExecutor((r) -> {
final Thread thread = new Thread(r);
Thread thread = new Thread(r);
thread.setDaemon(true);
thread.setName("micrometer-pushgateway");
return thread;
Expand All @@ -150,7 +150,7 @@ public PushGatewayHandler(CollectorRegistry collectorRegistry,

void push() {
try {
this.pushGateway.pushAdd(this.collectorRegistry, job(),
this.pushGateway.pushAdd(this.collectorRegistry, getJobName(),
this.pushgatewayProperties.getGroupingKeys());
}
catch (UnknownHostException ex) {
Expand All @@ -172,26 +172,30 @@ void shutdown() {
push();
}
if (this.pushgatewayProperties.isDeleteOnShutdown()) {
try {
this.pushGateway.delete(job(),
this.pushgatewayProperties.getGroupingKeys());
}
catch (Throwable throwable) {
this.logger.error(
"Unable to delete metrics from Prometheus Pushgateway",
throwable);
}
delete();
}
}

private String job() {
private void delete() {
try {
this.pushGateway.delete(getJobName(),
this.pushgatewayProperties.getGroupingKeys());
}
catch (Throwable throwable) {
this.logger.error(
"Unable to delete metrics from Prometheus Pushgateway",
throwable);
}
}

private String getJobName() {
String job = this.pushgatewayProperties.getJob();
if (job == null) {
job = this.environment.getProperty("spring.application.name");
}
if (job == null) {
// There's a history of Prometheus spring integration defaulting the
// job name to "spring" from when
// getJobName name to "spring" from when
// Prometheus integration didn't exist in Spring itself.
job = "spring";
}
Expand Down
1 change: 0 additions & 1 deletion spring-boot-project/spring-boot-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@
<nio-multipart-parser.version>1.1.0</nio-multipart-parser.version>
<pooled-jms-version>1.0.3</pooled-jms-version>
<postgresql.version>42.2.5</postgresql.version>
<!-- need to take care that this version harmonizes with micrometer ones -->
<prometheus-pushgateway.version>0.5.0</prometheus-pushgateway.version>
<quartz.version>2.3.0</quartz.version>
<querydsl.version>4.2.1</querydsl.version>
Expand Down

0 comments on commit e98235c

Please sign in to comment.