Versions Compared

Key

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

...

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 theKafkaMetric class 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.

Code Block
	/**
     * 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();

...

  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 theMeasurable interface interface.

    • Return Returns true if the metric is measurable, false otherwise 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.

...

Summary: This approach considered creating a wrapper object aroundKafkaMetric to  to mitigate the performance overhead associated with the exception-based measurable() methodmeasurable 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  method provides a more focused and efficient solution for determining metric measurability and reducing unnecessary burden on users with wrapper objects.