Status

Current state: Under Discussion

Discussion thread: here 

JIRA: TODO 

Motivation

KIP-714 introduced the ClientTelemetryReceiver interface to enable MetricsReporter instances running on brokers to collect client telemetry metrics. Typically a reporter stores metrics it receives in a "metrics registry" and exposes them in a format suitable for the external monitoring system it is built for. This is exactly what JmxReporter does. Kafka clients and brokers explicitly delete their metrics when they are not used anymore. However for client telemetry metrics there isn't an explicit deletion mechanism.

Clients send their telemetry metrics at a regular interval, configured via telemetry subscriptions. Reporters are not aware of this push interval. Without the interval and an explicit deletion mechanism, reporters don't know when to clear client telemetry metrics and stop exposing them. This makes it hard to not expose stale metrics. Having uncertainty in metrics is a major problem as operators rely on them to manage their clusters and investigate issues.

This KIP proposes updating the context associated with each client telemetry push to include the push interval. This will enable reporters to properly manage the life cycle of client telemetry metrics.

Public Interfaces

package org.apache.kafka.server.telemetry;

import org.apache.kafka.server.authorizer.AuthorizableRequestContext;

/**
 * Context provided to {@link ClientTelemetryReceiver} implementations when receiving client metrics.
 */
public interface ClientTelemetryContext {

    /**
     * The interval defined via <code>metrics.interval</code> in the client metrics subscription
     * @return The interval in milliseconds
     */
    int pushIntervalMs();

    /**
     * The context associated with this request
     * @return The AuthorizableRequestContext associated with this request
     */
    AuthorizableRequestContext authorizableRequestContext();
}
import org.apache.kafka.common.metrics.MetricsReporter;

/**
 * A {@link MetricsReporter} may implement this interface to indicate support for collecting client
 * telemetry on the server side.
 */
public interface ClientTelemetryExporterProvider {

    /**
     * Called by the broker to fetch instance of {@link ClientTelemetryExporter}.
     * <p>
     * This instance may be cached by the broker.
     *
     * @return broker side instance of {@link ClientTelemetryExporter}.
     */
    ClientTelemetryExporter clientExporter();

}


Proposed Changes

Compatibility, Deprecation, and Migration Plan

The existing interfaces, ClientTelemetryReceiver and ClientTelemetry, are kept and deprecated. They will be removed in the next major version, Kafka 5.0.0. All existing implementations will keep working until then.

To use the new features, implementations will need to implement the new interfaces, ClientTelemetryExporterProvider and ClientTelemetryExporter.

Test Plan

Adequate unit and integration tests will be added to ensure ClientTelemetryReceiver implementations use the old or new contexts.

Rejected Alternatives

N/A