From cd6d65f18c52b81a83bce9744a5a2f70ab8b8a5d Mon Sep 17 00:00:00 2001 From: Michael Ummels Date: Sun, 16 Jun 2024 11:41:50 +0200 Subject: [PATCH 1/2] Check whether ScheduledReporter ist started before reporting metrics one last time --- .../java/com/codahale/metrics/ScheduledReporter.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/metrics-core/src/main/java/com/codahale/metrics/ScheduledReporter.java b/metrics-core/src/main/java/com/codahale/metrics/ScheduledReporter.java index 4723cdfc8c..bb7ad86c15 100644 --- a/metrics-core/src/main/java/com/codahale/metrics/ScheduledReporter.java +++ b/metrics-core/src/main/java/com/codahale/metrics/ScheduledReporter.java @@ -220,10 +220,13 @@ public void stop() { executor.shutdown(); // Disable new tasks from being submitted } - try { - report(); // Report metrics one last time - } catch (Exception e) { - LOG.warn("Final reporting of metrics failed.", e); + if (this.scheduledFuture != null) { + // Reporter started, try to report metrics one last time + try { + report(); + } catch (Exception e) { + LOG.warn("Final reporting of metrics failed.", e); + } } if (shutdownExecutorOnStop) { From 1a7e87aef0f4526bd1827b230ba1326089ade247 Mon Sep 17 00:00:00 2001 From: Jochen Schalanda Date: Thu, 3 Oct 2024 18:42:10 +0200 Subject: [PATCH 2/2] Fix GraphiteReporterTest --- .../java/com/codahale/metrics/graphite/GraphiteReporterTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/metrics-graphite/src/test/java/com/codahale/metrics/graphite/GraphiteReporterTest.java b/metrics-graphite/src/test/java/com/codahale/metrics/graphite/GraphiteReporterTest.java index 3498b2ce64..240c0d26ff 100644 --- a/metrics-graphite/src/test/java/com/codahale/metrics/graphite/GraphiteReporterTest.java +++ b/metrics-graphite/src/test/java/com/codahale/metrics/graphite/GraphiteReporterTest.java @@ -445,6 +445,7 @@ public void closesConnectionIfGraphiteIsUnavailable() throws Exception { @Test public void closesConnectionOnReporterStop() throws Exception { + reporter.start(1, TimeUnit.SECONDS); reporter.stop(); final InOrder inOrder = inOrder(graphite);