Skip to content

Commit

Permalink
Align publication time with StepValue rollover (micrometer-metrics#1218)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-karp committed Dec 31, 2020
1 parent 3b6c88a commit 13389a1
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 13389a1

Please sign in to comment.