Skip to content

KAFKA-19753: Fix duplicated topic metrics in FetchMetricsManager for topic names containing dots#22553

Open
wilmerdooley wants to merge 1 commit into
apache:trunkfrom
wilmerdooley:oss/kafka-19753-fix-duplicated-topic
Open

KAFKA-19753: Fix duplicated topic metrics in FetchMetricsManager for topic names containing dots#22553
wilmerdooley wants to merge 1 commit into
apache:trunkfrom
wilmerdooley:oss/kafka-19753-fix-duplicated-topic

Conversation

@wilmerdooley

@wilmerdooley wilmerdooley commented Jun 12, 2026

Copy link
Copy Markdown

Since 4.1.0, FetchMetricsManager registers the KIP-1109 deprecated metrics (topic names with dots replaced by underscores) alongside the new verbatim-name metrics. The deprecated names were derived by string-wrapping the new-format metric name, which produced colliding and duplicated sensors when a consumer subscribes to topics whose names differ only by dots versus underscores (for example my.topic and my_topic), and left stale deprecated sensors registered when they should no longer be reported. Users scraping these metrics through Micrometer or Prometheus saw duplicated topic-tagged series.

This change:

  • Derives the deprecated metric and sensor names through dedicated deprecated*MetricName helpers based on the mangled (dot-to-underscore) topic name, instead of wrapping the new-format name.
  • Registers a deprecated sensor only when it does not collide with the sensor of a real topic whose name equals the mangled name, covering both registration orders (dotted topic seen first, underscore topic seen first).
  • Adds maybeRemoveDeprecated* cleanup so deprecated sensors and metrics are unregistered once they should no longer be reported, including during assignment updates, with collision-aware removal so a still-assigned partition's metrics are never dropped.

The deprecated metrics themselves remain in place for topics with dots, as intended by KIP-1109, until their removal in Kafka 5.0.

Testing: five new unit tests in FetchMetricsManagerTest cover the dotted-versus-underscore topic interplay in both registration orders, topics without dots (no deprecated sensor registered), the partition-level lag/lead/preferred-read-replica metrics, and assignment updates. Verified with the scoped module run ./gradlew :clients:test --tests org.apache.kafka.clients.consumer.internals.FetchMetricsManagerTest.

JIRA: https://issues.apache.org/jira/browse/KAFKA-19753

…topic names containing dots

Signed-off-by: wilmerdooley <wilmerdooley1@gmail.com>
@github-actions github-actions Bot added triage PRs from the community consumer clients labels Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clients consumer triage PRs from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant