Skip to content

Commit

Permalink
KAFKA-18597: Fix max-buffer-utilization-percent is always 0
Browse files Browse the repository at this point in the history
  • Loading branch information
LoganZhuZzz committed Jan 19, 2025
1 parent 516d524 commit 3b3700d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions core/src/main/scala/kafka/log/LogCleaner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ class LogCleaner(initialConfig: CleanerConfig,
* @param f to compute the result
* @return the max value (int value) or 0 if there is no cleaner
*/
private def maxOverCleanerThreads(f: CleanerThread => Double): Int =
cleaners.foldLeft(0.0d)((max: Double, thread: CleanerThread) => math.max(max, f(thread))).toInt
private def maxOverCleanerThreads(f: CleanerThread => Double): Double =
cleaners.foldLeft(0.0d)((max: Double, thread: CleanerThread) => math.max(max, f(thread)))

/* a metric to track the maximum utilization of any thread's buffer in the last cleaning */
metricsGroup.newGauge(MaxBufferUtilizationPercentMetricName,
() => maxOverCleanerThreads(_.lastStats.bufferUtilization) * 100)
() => (maxOverCleanerThreads(_.lastStats.bufferUtilization) * 100).toInt)

/* a metric to track the recopy rate of each thread's last cleaning */
metricsGroup.newGauge(CleanerRecopyPercentMetricName, () => {
Expand All @@ -134,12 +134,12 @@ class LogCleaner(initialConfig: CleanerConfig,
})

/* a metric to track the maximum cleaning time for the last cleaning from each thread */
metricsGroup.newGauge(MaxCleanTimeMetricName, () => maxOverCleanerThreads(_.lastStats.elapsedSecs))
metricsGroup.newGauge(MaxCleanTimeMetricName, () => maxOverCleanerThreads(_.lastStats.elapsedSecs).toInt)

// a metric to track delay between the time when a log is required to be compacted
// as determined by max compaction lag and the time of last cleaner run.
metricsGroup.newGauge(MaxCompactionDelayMetricsName,
() => maxOverCleanerThreads(_.lastPreCleanStats.maxCompactionDelayMs.toDouble) / 1000)
() => (maxOverCleanerThreads(_.lastPreCleanStats.maxCompactionDelayMs.toDouble) / 1000).toInt)

metricsGroup.newGauge(DeadThreadCountMetricName, () => deadThreadCount)

Expand Down

0 comments on commit 3b3700d

Please sign in to comment.