Skip to content

Commit

Permalink
Make Timer and LongTaskTimer output similar in LoggingMeterRegistry
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
jonatan-ivanov committed Jan 29, 2025
1 parent 1f43511 commit 5543b25
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5543b25

Please sign in to comment.