Ritikj55 opened a new pull request, #23763: URL: https://github.com/apache/kafka/pull/23763
### Summary This PR fixes KAFKA-21078, where the telemetry reporter was exporting metrics whose sensors were disabled by `metrics.recording.level`. `Sensor.add` registers metrics with the metrics registry regardless of whether the sensor's `RecordingLevel` is enabled. `Sensor.record` respects the recording level, but `KafkaMetricsCollector` previously had no way to know whether a metric came from a disabled sensor. As a result, disabled DEBUG-level metrics could still be pushed through client telemetry, often as zero-valued metrics. ### Problem At the default INFO recording level, DEBUG sensor metrics should not be collected. However, because the collector only filtered by telemetry subscription and numeric value, disabled sensor metrics were still emitted. This can unnecessarily increase telemetry payload size and backend cardinality, especially for Kafka Streams metrics with many per-store, per-node, and per-task series. ### Solution This PR propagates the sensor `RecordingLevel` into `KafkaMetric` when metrics are created through `Sensor.add`. `KafkaMetric` now exposes whether it is active for the current `MetricConfig.recordLevel()`. `KafkaMetricsCollector` checks this before collecting each metric and skips inactive metrics. Metrics that are not associated with a sensor continue to be treated as active, preserving existing behavior for standalone metrics. ### Tests Added coverage for: - `KafkaMetric.isActive()` for metrics without a sensor recording level. - `KafkaMetric.isActive()` across INFO, DEBUG, and TRACE recording levels. - `KafkaMetricsCollector` skipping a DEBUG sensor metric when the config is INFO. - `KafkaMetricsCollector` collecting that same metric once the config recording level ### AI assistance disclosure As per AI_POLICY/CONTRIBUTING.md , Codex (GPT 5.5 ) was used to assist to investigate the root cause, assist in the fix . All changes were reviewed by me before submission. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
