From 9049dd3bd402d8668c1b6a41ebc50bba59aa2340 Mon Sep 17 00:00:00 2001 From: Michael Bell Date: Fri, 14 Oct 2022 17:29:46 -0700 Subject: [PATCH] Allow override of scheduler https://github.com/dropwizard/metrics/issues/1524 introduced a fix to queuing issues and ends up doing atFixedDelay rather than atFixedRate. Issues with binning exist in Graphite (and probably others). See https://github.com/dropwizard/metrics/issues/2664 --- .../com/codahale/metrics/ScheduledReporter.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 304cfb3a26..5821df1c8b 100644 --- a/metrics-core/src/main/java/com/codahale/metrics/ScheduledReporter.java +++ b/metrics-core/src/main/java/com/codahale/metrics/ScheduledReporter.java @@ -166,7 +166,19 @@ synchronized void start(long initialDelay, long period, TimeUnit unit, Runnable throw new IllegalArgumentException("Reporter already started"); } - this.scheduledFuture = executor.scheduleWithFixedDelay(runnable, initialDelay, period, unit); + this.scheduledFuture = getScheduledFuture(initialDelay, period, unit, runnable); + } + + + /** + * Schedule the task, and return a future. + * The current implementation uses scheduleWithFixedDelay, replacing scheduleWithFixedRate. This avoids queueing issues, but may + * cause some reporters to skip metrics, as scheduleWithFixedDelay introduces a growing delta from the original start point. + * + * Overriding this in a subclass to revert to the old behavior is permitted. + */ + protected ScheduledFuture getScheduledFuture(long initialDelay, long period, TimeUnit unit, Runnable runnable) { + return executor.scheduleWithFixedDelay(runnable, initialDelay, period, unit); } /**