KAFKA-19753: Fix duplicated topic metrics in FetchMetricsManager for topic names containing dots#22553
Open
wilmerdooley wants to merge 1 commit into
Open
Conversation
…topic names containing dots Signed-off-by: wilmerdooley <wilmerdooley1@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since 4.1.0,
FetchMetricsManagerregisters 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 examplemy.topicandmy_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:
deprecated*MetricNamehelpers based on the mangled (dot-to-underscore) topic name, instead of wrapping the new-format name.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
FetchMetricsManagerTestcover 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