From 5543b258d73de1dd2a14dc391683eb5dc33da1e0 Mon Sep 17 00:00:00 2001 From: Jonatan Ivanov Date: Tue, 28 Jan 2025 16:34:55 -0800 Subject: [PATCH] Make Timer and LongTaskTimer output similar in LoggingMeterRegistry In case of the LoggingMeterRegistry, the output of a LongTaskTimer looks like this: "my.ltt{} active=30 duration=30m" while the output of a Timer is something like this: "my.timer{} delta_count=30 throughput=0.5/s mean=1s max=1s" We can add the missing fields to the LongTaskTimer output: "my.ltt{} active=30 duration=30m throughput=0.5/s mean=1m max=1m" --- .../core/instrument/logging/LoggingMeterRegistry.java | 5 ++++- .../core/instrument/logging/LoggingMeterRegistryTest.java | 3 ++- 2 files changed, 6 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 750efdb43..677a67c79 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 @@ -150,8 +150,11 @@ protected void publish() { int activeTasks = longTaskTimer.activeTasks(); if (!config.logInactive() && activeTasks == 0) return; + HistogramSnapshot snapshot = longTaskTimer.takeSnapshot(); loggingSink.accept(print.id() + " active=" + wholeOrDecimal(activeTasks) + " duration=" - + print.time(longTaskTimer.duration(getBaseTimeUnit()))); + + print.time(longTaskTimer.duration(getBaseTimeUnit())) + " throughput=" + + print.unitlessRate(activeTasks) + " mean=" + print.time(snapshot.mean(getBaseTimeUnit())) + + " max=" + print.time(snapshot.max(getBaseTimeUnit()))); }, timeGauge -> { double value = timeGauge.value(getBaseTimeUnit()); if (!config.logInactive() && value == 0) 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 283cd5043..6b36af997 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 @@ -231,7 +231,8 @@ void publishShouldPrintActiveCountAndDurationWhenMeterIsLongTaskTimer() { IntStream.rangeClosed(1, 30).forEach(t -> timer.start()); clock.add(config.step()); recordingRegistry.publish(); - assertThat(recordingRegistry.getLogs()).containsExactly("my.ltt{} active=30 duration=30m"); + assertThat(recordingRegistry.getLogs()) + .containsExactly("my.ltt{} active=30 duration=30m throughput=0.5/s mean=1m max=1m"); } @Test