diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusPushGatewayManager.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusPushGatewayManager.java index b0e2540f888..504f066f621 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusPushGatewayManager.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusPushGatewayManager.java @@ -98,15 +98,15 @@ public class PrometheusPushGatewayManager { this.groupingKey = groupingKey; this.shutdownOperation = (shutdownOperation != null) ? shutdownOperation : ShutdownOperation.NONE; this.scheduler = scheduler; - this.scheduled = this.scheduler.scheduleAtFixedRate(this::push, pushRate); + this.scheduled = this.scheduler.scheduleAtFixedRate(this::post, pushRate); } - private void push() { + private void post() { try { this.pushGateway.pushAdd(this.registry, this.job, this.groupingKey); } catch (Throwable ex) { - logger.warn("Unexpected exception thrown while pushing metrics to Prometheus Pushgateway", ex); + logger.warn("Unexpected exception thrown by POST of metrics to Prometheus Pushgateway", ex); } } @@ -115,7 +115,7 @@ public class PrometheusPushGatewayManager { this.pushGateway.push(this.registry, this.job, this.groupingKey); } catch (Throwable ex) { - logger.warn("Unexpected exception thrown while pushing metrics to Prometheus Pushgateway", ex); + logger.warn("Unexpected exception thrown by PUT of metrics to Prometheus Pushgateway", ex); } } @@ -124,7 +124,7 @@ public class PrometheusPushGatewayManager { this.pushGateway.delete(this.job, this.groupingKey); } catch (Throwable ex) { - logger.warn("Unexpected exception thrown while deleting metrics from Prometheus Pushgateway", ex); + logger.warn("Unexpected exception thrown by DELETE of metrics from Prometheus Pushgateway", ex); } } @@ -142,7 +142,8 @@ public class PrometheusPushGatewayManager { this.scheduled.cancel(false); switch (shutdownOperation) { case PUSH: - push(); + case POST: + post(); break; case PUT: put(); @@ -164,17 +165,24 @@ public class PrometheusPushGatewayManager { NONE, /** - * Perform a 'push' with POST method before shutdown. + * Perform a POST before shutdown. */ + POST, + + /** + * Perform a POST before shutdown. + * @deprecated since 3.0.0 for removal in 3.2.0 in favor of {@link #POST}. + */ + @Deprecated PUSH, /** - * Perform a 'push' with PUT method before shutdown. + * Perform a PUT before shutdown. */ PUT, /** - * Perform a 'delete' before shutdown. + * Perform a DELETE before shutdown. */ DELETE diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusPushGatewayManagerTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusPushGatewayManagerTests.java index f06d633fabd..b35cfecb2a3 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusPushGatewayManagerTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusPushGatewayManagerTests.java @@ -135,7 +135,8 @@ class PrometheusPushGatewayManagerTests { } @Test - void shutdownWhenShutdownOperationIsPushPerformsPushOnShutdown() throws Exception { + @SuppressWarnings("deprecation") + void shutdownWhenShutdownOperationIsPushPerformsPushAddOnShutdown() throws Exception { givenScheduleAtFixedRateWithReturnFuture(); PrometheusPushGatewayManager manager = new PrometheusPushGatewayManager(this.pushGateway, this.registry, this.scheduler, this.pushRate, "job", this.groupingKey, ShutdownOperation.PUSH); @@ -144,6 +145,16 @@ class PrometheusPushGatewayManagerTests { then(this.pushGateway).should().pushAdd(this.registry, "job", this.groupingKey); } + @Test + void shutdownWhenShutdownOperationIsPostPerformsPushAddOnShutdown() throws Exception { + givenScheduleAtFixedRateWithReturnFuture(); + PrometheusPushGatewayManager manager = new PrometheusPushGatewayManager(this.pushGateway, this.registry, + this.scheduler, this.pushRate, "job", this.groupingKey, ShutdownOperation.POST); + manager.shutdown(); + then(this.future).should().cancel(false); + then(this.pushGateway).should().pushAdd(this.registry, "job", this.groupingKey); + } + @Test void shutdownWhenShutdownOperationIsPutPerformsPushOnShutdown() throws Exception { givenScheduleAtFixedRateWithReturnFuture();