Skip to content

Conversation

m1a2st
Copy link
Collaborator

@m1a2st m1a2st commented Sep 6, 2025

All Kafka component register AppInfo metrics to track the application
start time or commit-id etc. These metrics are useful for monitoring and
debugging. However, the AppInfo doesn't provide client-id, which is an
important information for custom metrics reporter.

The AppInfoParser class registers a JMX MBean with the provided
client-id, but when it adds metrics to the Metrics registry, the
client-id is not included. This KIP aims to add the client-id as a tag.

@github-actions github-actions bot added triage PRs from the community clients small Small PRs labels Sep 6, 2025
@m1a2st m1a2st changed the title [WIP] KAFKA-15186 AppInfo metrics don't contain the client-id KAFKA-15186 AppInfo metrics don't contain the client-id Sep 6, 2025
@@ -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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the indent.

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")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move this condition into registerMetrics? for example:

    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());
        }
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!metrics.config().tags().containsKey("client-id")) may need to include clientId != null

@github-actions github-actions bot removed the triage PRs from the community label Sep 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants