From 1c0cc36714b1fbd8f7922e2556547f97a4385608 Mon Sep 17 00:00:00 2001 From: Corey O'Connor Date: Fri, 15 Nov 2024 10:09:24 -0800 Subject: [PATCH] statsd + abstract timer: Consistently use baseTimeUnit --- .../java/io/micrometer/statsd/StatsdTimer.java | 16 ++++++++-------- .../core/instrument/AbstractTimer.java | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/implementations/micrometer-registry-statsd/src/main/java/io/micrometer/statsd/StatsdTimer.java b/implementations/micrometer-registry-statsd/src/main/java/io/micrometer/statsd/StatsdTimer.java index befbffda49..2ab1ddfab2 100644 --- a/implementations/micrometer-registry-statsd/src/main/java/io/micrometer/statsd/StatsdTimer.java +++ b/implementations/micrometer-registry-statsd/src/main/java/io/micrometer/statsd/StatsdTimer.java @@ -43,9 +43,9 @@ public class StatsdTimer extends AbstractTimer { StatsdTimer(Id id, StatsdLineBuilder lineBuilder, FluxSink sink, Clock clock, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector, TimeUnit baseTimeUnit, - long stepMillis) { + long stepBaseUnits) { super(id, clock, distributionStatisticConfig, pauseDetector, baseTimeUnit, false); - this.max = new StepDouble(clock, stepMillis); + this.max = new StepDouble(clock, stepBaseUnits); this.lineBuilder = lineBuilder; this.sink = sink; } @@ -55,13 +55,13 @@ protected void recordNonNegative(long amount, TimeUnit unit) { if (!shutdown && amount >= 0) { count.increment(); - double msAmount = TimeUtils.convert(amount, unit, TimeUnit.MILLISECONDS); - totalTime.add(msAmount); + double baseUnitAmount = TimeUtils.convert(amount, unit, baseTimeUnit()); + totalTime.add(baseUnitAmount); // not necessary to ship max, as most StatsD agents calculate this themselves - max.getCurrent().add(Math.max(msAmount - max.getCurrent().doubleValue(), 0)); + max.getCurrent().add(Math.max(baseUnitAmount - max.getCurrent().doubleValue(), 0)); - sink.next(lineBuilder.timing(msAmount)); + sink.next(lineBuilder.timing(baseUnitAmount)); } } @@ -72,7 +72,7 @@ public long count() { @Override public double totalTime(TimeUnit unit) { - return TimeUtils.convert(totalTime.doubleValue(), TimeUnit.MILLISECONDS, unit); + return TimeUtils.convert(totalTime.doubleValue(), baseTimeUnit(), unit); } /** @@ -82,7 +82,7 @@ public double totalTime(TimeUnit unit) { */ @Override public double max(TimeUnit unit) { - return TimeUtils.convert(max.poll(), TimeUnit.MILLISECONDS, unit); + return TimeUtils.convert(max.poll(), baseTimeUnit(), unit); } void shutdown() { diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/AbstractTimer.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/AbstractTimer.java index 6cf9d369cd..8ef18625e1 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/AbstractTimer.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/AbstractTimer.java @@ -258,7 +258,7 @@ public void record(Runnable f) { @Override public final void record(long amount, TimeUnit unit) { if (amount >= 0) { - histogram.recordLong(TimeUnit.NANOSECONDS.convert(amount, unit)); + histogram.recordLong(baseTimeUnit().convert(amount, unit)); recordNonNegative(amount, unit); if (intervalEstimator != null) {