Status

Current state: Adopted (3.8.0)

Discussion thread: here

JIRA: here

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation

Kafka currently lacks a straightforward and efficient mechanism for determining whether a given metric is measurable. Existing approaches often rely on:

  • Exception-Based Measurability Check: While measurable() does provide the value provider, it throws an exception if the provider isn't an instance of Measurable. This means that checking for measurability incurs the overhead of exception handling and stack trace creation, in cases where the metric is not measurable.

  • Accessing Value Provider Field: KafkaMetricsCollector resort to Java reflection to inspect the underlying value provider field by making it accessible outside KafkaMetric class. This approach is fragile and can break with future Kafka changes.

This small KIP proposes to introduce a new method, isMeasurable(), to the KafkaMetric class, eliminating the need for accessing private fields or handling exceptions in case of non-measurable metrics.

Public Interfaces

  • Modification of the KafkaMetric class to include isMeasurable() method.

	/**
     * The method determines if the metric value provider is of type Measurable.
     *
     * @return true if the metric value provider is of type Measurable, false otherwise.
     */
    public boolean isMeasurable();


Proposed Changes

  1. Add isMeasurable() Method in KafkaMetric.java:

    • Introduce a new method to KafkaMetric class: boolean isMeasurable().

    • This method would internally check if the metric's underlying value provider implements the Measurable interface.

    • Returns true if the metric is measurable, false otherwise.

Compatibility, Deprecation, and Migration Plan

  • Since this is a completely new API, no backward compatibility concerns are anticipated.

  • Since nothing is deprecated in this KIP, users have no need to migrate unless they want to.

Test Plan

  • Verification of isMeasurable()'s behaviour and integration with existing functionalities.

Rejected Alternatives

Wrapper Object for exception-based measurability checks

Summary: This approach considered creating a wrapper object around KafkaMetric to mitigate the performance overhead associated with the exception-based measurable method. Similar to Open-Telemetry’s Kafka Client adapter, the wrapper would store the measurability information to avoid repeated exception handling.

Rejected because: While the wrapper concept addresses the issue of exception-based checks, it introduces additional complexity and potential overheads of maintaining the wrapper objects of KafkaMetric itself. The proposed isMeasurable() method provides a more focused and efficient solution for determining metric measurability and reducing unnecessary burden on users with wrapper objects.

  • No labels