From 04eef90adebf3c0977c7d0c1a6aa815d97c0c0f4 Mon Sep 17 00:00:00 2001 From: Jonatan Ivanov Date: Tue, 28 Jan 2025 15:46:02 -0800 Subject: [PATCH] Fix LongTaskTimer output for LoggingMeterRegistryTest Closes gh-5834 --- .../core/instrument/logging/LoggingMeterRegistry.java | 3 ++- .../core/instrument/logging/LoggingMeterRegistryTest.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/logging/LoggingMeterRegistry.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/logging/LoggingMeterRegistry.java index d2d408e14..2a6dae114 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/logging/LoggingMeterRegistry.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/logging/LoggingMeterRegistry.java @@ -42,6 +42,7 @@ import java.util.stream.StreamSupport; import static io.micrometer.core.instrument.util.DoubleFormat.decimalOrNan; +import static io.micrometer.core.instrument.util.DoubleFormat.wholeOrDecimal; import static java.util.stream.Collectors.joining; /** @@ -146,7 +147,7 @@ protected void publish() { int activeTasks = longTaskTimer.activeTasks(); if (!config.logInactive() && activeTasks == 0) return; - loggingSink.accept(print.id() + " active=" + print.value(activeTasks) + " duration=" + loggingSink.accept(print.id() + " active=" + wholeOrDecimal(activeTasks) + " duration=" + print.time(longTaskTimer.duration(getBaseTimeUnit()))); }, timeGauge -> { double value = timeGauge.value(getBaseTimeUnit()); diff --git a/micrometer-core/src/test/java/io/micrometer/core/instrument/logging/LoggingMeterRegistryTest.java b/micrometer-core/src/test/java/io/micrometer/core/instrument/logging/LoggingMeterRegistryTest.java index 7dc34b02b..54219122a 100644 --- a/micrometer-core/src/test/java/io/micrometer/core/instrument/logging/LoggingMeterRegistryTest.java +++ b/micrometer-core/src/test/java/io/micrometer/core/instrument/logging/LoggingMeterRegistryTest.java @@ -228,7 +228,7 @@ void publishShouldPrintActiveCountAndDurationWhenMeterIsLongTaskTimer() { IntStream.rangeClosed(1, 30).forEach(t -> timer.start()); clock.add(config.step()); recordingRegistry.publish(); - assertThat(recordingRegistry.getLogs()).containsExactly("my.ltt{} active=30 milliseconds duration=30m"); + assertThat(recordingRegistry.getLogs()).containsExactly("my.ltt{} active=30 duration=30m"); } @Test