You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by mi...@apache.org on 2024/10/10 17:29:18 UTC

(kafka) branch 3.8 updated: MINOR: Fix Throttler compilation issue (#17459)

This is an automated email from the ASF dual-hosted git repository.

mimaison pushed a commit to branch 3.8
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/3.8 by this push:
     new 42656cf28d3 MINOR: Fix Throttler compilation issue (#17459)
42656cf28d3 is described below

commit 42656cf28d33b1ab1de997d9a39509960b4aa6e0
Author: Mickael Maison <mi...@users.noreply.github.com>
AuthorDate: Thu Oct 10 19:29:12 2024 +0200

    MINOR: Fix Throttler compilation issue (#17459)
    
    
    Reviewers: Josep Prat <jo...@aiven.io>
---
 .../kafka/server/metrics/KafkaMetricsGroup.java      | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/server-common/src/main/java/org/apache/kafka/server/metrics/KafkaMetricsGroup.java b/server-common/src/main/java/org/apache/kafka/server/metrics/KafkaMetricsGroup.java
index af2840f9960..026648f02df 100644
--- a/server-common/src/main/java/org/apache/kafka/server/metrics/KafkaMetricsGroup.java
+++ b/server-common/src/main/java/org/apache/kafka/server/metrics/KafkaMetricsGroup.java
@@ -31,10 +31,22 @@ import com.yammer.metrics.core.Timer;
 import org.apache.kafka.common.utils.Sanitizer;
 
 public class KafkaMetricsGroup {
-    private final Class<?> klass;
+
+    private final String pkg;
+    private final String simpleName;
 
     public KafkaMetricsGroup(Class<?> klass) {
-        this.klass = klass;
+        this(klass.getPackage() == null ? "" : klass.getPackage().getName(), klass.getSimpleName().replaceAll("\\$$", ""));
+    }
+
+    /**
+     * This constructor allows caller to build metrics name with custom package and class name. This is useful to keep metrics
+     * compatibility in migrating scala code, since the difference of either package or class name will impact the mbean name and
+     * that will break the backward compatibility.
+     */
+    public KafkaMetricsGroup(String packageName, String simpleName) {
+        this.pkg = packageName;
+        this.simpleName = simpleName;
     }
 
     /**
@@ -45,9 +57,7 @@ public class KafkaMetricsGroup {
      * @return Sanitized metric name object.
      */
     public MetricName metricName(String name, Map<String, String> tags) {
-        String pkg = klass.getPackage() == null ? "" : klass.getPackage().getName();
-        String simpleName = klass.getSimpleName().replaceAll("\\$$", "");
-        return explicitMetricName(pkg, simpleName, name, tags);
+        return explicitMetricName(this.pkg, this.simpleName, name, tags);
     }
 
     public static MetricName explicitMetricName(String group, String typeName,