From 13389a1ec83449d5acd1bd3541d960c60ee6602c Mon Sep 17 00:00:00 2001 From: John Karp Date: Thu, 31 Dec 2020 12:57:54 -0600 Subject: [PATCH] Align publication time with StepValue rollover (#1218) --- .../micrometer/core/instrument/push/PushMeterRegistry.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/push/PushMeterRegistry.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/push/PushMeterRegistry.java index 08cb544f8d..cfd73a55a1 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/push/PushMeterRegistry.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/push/PushMeterRegistry.java @@ -71,8 +71,11 @@ public void start(ThreadFactory threadFactory) { logger.info("publishing metrics for " + this.getClass().getSimpleName() + " every " + TimeUtils.format(config.step())); scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(threadFactory); - scheduledExecutorService.scheduleAtFixedRate(this::publishSafely, config.step() - .toMillis(), config.step().toMillis(), TimeUnit.MILLISECONDS); + // time publication to happen just after StepValue finishes the step + long stepMillis = config.step().toMillis(); + long initialDelayMillis = stepMillis - (clock.wallTime() % stepMillis) + 1; + scheduledExecutorService.scheduleAtFixedRate(this::publishSafely, + initialDelayMillis, stepMillis, TimeUnit.MILLISECONDS); } }