From ba6736eab2b5a229c2ba7263591c4e6c7c2db0b1 Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Mon, 18 Dec 2017 13:21:10 +0100 Subject: use clock utilities to align metric reporting ticks --- kamon-core/src/main/scala/kamon/ReporterRegistry.scala | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/kamon-core/src/main/scala/kamon/ReporterRegistry.scala b/kamon-core/src/main/scala/kamon/ReporterRegistry.scala index 55733294..67cfbe4e 100644 --- a/kamon-core/src/main/scala/kamon/ReporterRegistry.scala +++ b/kamon-core/src/main/scala/kamon/ReporterRegistry.scala @@ -234,15 +234,9 @@ object ReporterRegistry { metricReporterTickerSchedule.set { val initialDelay = if(registryConfiguration.optimisticMetricTickAlignment) { - val minimumInitialDelay = 2.seconds.toMillis - val currentTimestamp = System.currentTimeMillis() - val roundCurrentTick = Math.floor(currentTimestamp.toDouble / tickIntervalMillis.toDouble).toLong - val roundCurrentTimestamp = roundCurrentTick * tickIntervalMillis - - if(roundCurrentTimestamp - currentTimestamp >= minimumInitialDelay) - roundCurrentTimestamp - currentTimestamp - else - (roundCurrentTimestamp + tickIntervalMillis) - currentTimestamp + val now = clock.instant() + val nextTick = Clock.nextTick(now, registryConfiguration.metricTickInterval) + Duration.between(now, nextTick).toMillis } else tickIntervalMillis -- cgit v1.2.3