Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

1) Update the AppInfoMBean interface add to include a new method getClientId() .

Code Block
public interface AppInfoMBean {
    String getVersion();
    String getCommitId();
    Long getStartTimeMs();
    String getClientId();
}

2) Deprecated the old AppInfoMBean implementation and mark marked it deprecatedas @Deprecated.

Code Block
@Deprecated(since = "4.2")
public static class DeprecatedAppInfo implements AppInfoMBean {
} 

3) Add new AppInfoMBeanimplementationIntroduced a new implementation of AppInfoMBean.

Code Block
public static class AppInfo implements AppInfoMBean {

    private final Long startTimeMs;

    public AppInfo(long startTimeMs) {
        this.startTimeMs = startTimeMs;
        log.info("Kafka version: {}", AppInfoParser.getVersion());
        log.info("Kafka commitId: {}", AppInfoParser.getCommitId());
        log.info("Kafka startTimeMs: {}", startTimeMs);
        log.info("Kafka client id: {}", AppInfoParser.getClientId());
    }

	// skip...

    @Override
    public String getClientId() {
        return AppInfoParser.getClientId();
    }
}

4) When AppInfoParser register registers an MBean, we it will register both the new one and the deprecated oneimplementations.

Code Block
languagejava
public class AppInfoParser {
    private static final Logger log = LoggerFactory.getLogger(AppInfoParser.class);
    private static final String VERSION;
    private static final String COMMIT_ID;
    private static final String CLIENT_ID;

    protected static final String DEFAULT_VALUE = "unknown";

    static {
        Properties props = new Properties();
        try (InputStream resourceStream = AppInfoParser.class.getResourceAsStream("/kafka/kafka-version.properties")) {
            props.load(resourceStream);
        } catch (Exception e) {
            log.warn("Error while loading kafka-version.properties: {}", e.getMessage());
        }
        VERSION = props.getProperty("version", DEFAULT_VALUE).trim();
        COMMIT_ID = props.getProperty("commitId", DEFAULT_VALUE).trim();
        CLIENT_ID = props.getProperty("clientId", DEFAULT_VALUE).trim();
    }

    public static String getClientId() {
        return CLIENT_ID;
    }

    public static synchronized void registerAppInfo(String prefix, String id, Metrics metrics, long nowMs) {
        try {
            // skip...
            DeprecatedAppInfo deprecatedMBean = new DeprecatedAppInfo(nowMs);
            AppInfo mBean = new AppInfo(nowMs);
            server.registerMBean(deprecatedMBean, name);
            server.registerMBean(mBean, name);

            registerMetrics(metrics, mBean); // prefix will be added later by JmxReporter
        } catch (JMException e) {
            log.warn("Error registering AppInfo mbean", e);
        }
    }

}

Compatibility, Deprecation, and Migration Plan

For users currently relying on the AppInfoMBean without client-id, it will remain available until Kafka 5.0. New users are encouraged to use the new AppInfoMBean, which includes the client-id tag. This deprecation will be documented in upgrade.html.

In Kafka 5.0, the deprecated AppInfoMBean will be removedSince this is a newly introduced behavior, there are no compatibility concerns.

Test Plan

change unit test or Integration test to verify the new method.

Rejected Alternatives

A new deprecated configuration could be introduced to control the registration of this MBean.

Nevertheless, this approach is considered unnecessary, as it would introduce complexity without significant benefit.n/a