You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by "chomingi (Jira)" <ji...@apache.org> on 2026/08/17 15:00:00 UTC

[jira] [Created] (KAFKA-20951) StreamsMetricsImpl retains duplicate sensor names when a sensor is removed and recreated

chomingi created KAFKA-20951:
--------------------------------

             Summary: StreamsMetricsImpl retains duplicate sensor names when a sensor is removed and recreated
                 Key: KAFKA-20951
                 URL: https://issues.apache.org/jira/browse/KAFKA-20951
             Project: Kafka
          Issue Type: Improvement
          Components: metrics, streams
    Affects Versions: 4.3.0
            Reporter: chomingi
            Assignee: chomingi


StreamsMetricsImpl keeps a per-level collection of sensor names (clientLevelSensors, threadLevelSensors, taskLevelSensors, nodeLevelSensors, topicLevelSensors, cacheLevelSensors, and storeLevelSensors) so that the corresponding sensors can be removed later.

A name is added to its collection in getSensors() or clientLevelSensor() only when metrics.getSensor(fullSensorName) returns null. removeSensor(Sensor) removes the sensor from the Metrics registry but leaves its name in the collection.
If the same sensor is later recreated, the registry lookup returns null again and the same name is recorded a second time. Repeating this cycle continues to append duplicate entries.

RecordQueue#close(), RecordCollectorImpl#removeAllProducedSensors(), and DefaultStateUpdater.StateUpdaterMetrics#clear() remove sensors through this path.
If the corresponding sensors are later recreated, their names are recorded again.

The sensors and their metrics are not retained; only their names remain.
Therefore, the impact is limited to these bookkeeping collections accumulating duplicate entries over the lifetime of a client.

KAFKA-9152 avoids duplicate bookkeeping while a sensor remains registered.
After a sensor is removed, however, the registry-based guard no longer detects the existing bookkeeping entry when the sensor is recreated.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)