chia7712 commented on code in PR #20493:
URL: https://github.com/apache/kafka/pull/20493#discussion_r2327931574


##########
clients/src/main/java/org/apache/kafka/common/utils/AppInfoParser.java:
##########
@@ -67,8 +68,11 @@ public static synchronized void registerAppInfo(String 
prefix, String id, Metric
             }
             AppInfo mBean = new AppInfo(nowMs);
             server.registerMBean(mBean, name);
-
-            registerMetrics(metrics, mBean); // prefix will be added later by 
JmxReporter
+            
+            registerMetrics(metrics, mBean, null); // prefix will be added 
later by JmxReporter
+            if (!metrics.config().tags().containsKey("client-id")) {

Review Comment:
   Could you please move this condition into `registerMetrics`? for example:
   ```java
       public static synchronized void unregisterAppInfo(String prefix, String 
id, Metrics metrics) {
           MBeanServer server = ManagementFactory.getPlatformMBeanServer();
           try {
               ObjectName name = new ObjectName(prefix + ":type=app-info,id=" + 
Sanitizer.jmxSanitize(id));
               if (server.isRegistered(name))
                   server.unregisterMBean(name);
   
               unregisterMetrics(metrics, id);
           } catch (JMException e) {
               log.warn("Error unregistering AppInfo mbean", e);
           } finally {
               log.info("App info {} for {} unregistered", prefix, id);
           }
       }
   
       private static void registerMetrics(Metrics metrics, AppInfo appInfo, 
String clientId) {
           if (metrics == null) return;
   
           // add comments for this case
           metrics.addMetric(metricName(metrics, "version", Map.of()), 
(Gauge<String>) (config, now) -> appInfo.getVersion());
           metrics.addMetric(metricName(metrics, "commit-id", Map.of()), 
(Gauge<String>) (config, now) -> appInfo.getCommitId());
           metrics.addMetric(metricName(metrics, "start-time-ms", Map.of()), 
(Gauge<Long>) (config, now) -> appInfo.getStartTimeMs());
   
           // add comments for this case
           if (!metrics.config().tags().containsKey("client-id")) {
               metrics.addMetric(metricName(metrics, "version", 
Map.of("client-id", clientId)), (Gauge<String>) (config, now) -> 
appInfo.getVersion());
               metrics.addMetric(metricName(metrics, "commit-id", 
Map.of("client-id", clientId)), (Gauge<String>) (config, now) -> 
appInfo.getCommitId());
               metrics.addMetric(metricName(metrics, "start-time-ms", 
Map.of("client-id", clientId)), (Gauge<Long>) (config, now) -> 
appInfo.getStartTimeMs());
           }
       }
   
   ```



##########
clients/src/main/java/org/apache/kafka/common/utils/AppInfoParser.java:
##########
@@ -67,8 +68,11 @@ public static synchronized void registerAppInfo(String 
prefix, String id, Metric
             }
             AppInfo mBean = new AppInfo(nowMs);
             server.registerMBean(mBean, name);
-
-            registerMetrics(metrics, mBean); // prefix will be added later by 
JmxReporter
+            

Review Comment:
   please remove the indent.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to