KAFKA-18735: Return null from ConfigEntity.name() for default quotas#22099
Open
mingyen066 wants to merge 2 commits intoapache:trunkfrom
Open
KAFKA-18735: Return null from ConfigEntity.name() for default quotas#22099mingyen066 wants to merge 2 commits intoapache:trunkfrom
mingyen066 wants to merge 2 commits intoapache:trunkfrom
Conversation
Align the Javadoc with the intended semantics where default quotas are represented by null, matching how the Admin API uses null to denote default client quota entities.
…pers Change DEFAULT_USER_ENTITY and DEFAULT_USER_CLIENT_ID to return null from ConfigEntity.name(), matching the Admin API representation of default client quota entities. Drop the internal DEFAULT_NAME constant and simplify KafkaQuotaEntity.sanitizedUser() and clientId() so that neither method returns the legacy ZooKeeper-era "<default>" string. The internal metric-tag lookup path in updateQuotaMetricConfigs is unaffected: default entities are routed through the iterate-all-metrics branch (updatedQuotaEntity=Optional.empty()), so sanitizedUser() and clientId() are never invoked on a default-entity KafkaQuotaEntity in practice. This is a behavior change in the ClientQuotaCallback SPI. Third party implementations that compare ConfigEntity.name() against the literal string "<default>" must be updated to check for null instead. The prior behavior contradicted the Javadoc, which documented an empty-string return value, so such comparisons were relying on undocumented behavior. Add tests asserting that ConfigEntity.name() returns null for all default-entity paths produced by transferToClientQuotaEntity, and that explicit-name entities continue to return their configured name.
chia7712
reviewed
Apr 20, 2026
| @Override | ||
| public String name() { | ||
| return DEFAULT_NAME; | ||
| return null; |
Member
There was a problem hiding this comment.
It's a small but breaking change, so it requires a KIP, even though I'd personally love to merge it directly.
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.
ConfigEntity.name()currently returns the ZooKeeper-era placeholderstring
"<default>"for default quota entities (DEFAULT_USER_ENTITYand
DEFAULT_USER_CLIENT_ID). This is asymmetric with the Admin API:callers create a default quota by passing
nullas the entity name —the
org.apache.kafka.common.quota.ClientQuotaEntityconstructorJavadoc states "if a name is null, then it is mapped to the built-in
default entity name" — but when the broker forwards that same default
quota to a custom
ClientQuotaCallback, the entity name arrives as thestring
"<default>"rather thannull. The server-sideConfigEntityJavadoc additionally documented an empty-string return value, which
matched neither the Admin API nor the actual implementation.
This change makes
ConfigEntity.name()returnnullfor defaultentities, aligning the
ClientQuotaCallbackinterface with the AdminAPI, and updates the Javadoc accordingly. The internal
DEFAULT_NAMEconstant in
ClientQuotaManageris removed, and thesanitizedUser()/clientId()helpers onKafkaQuotaEntityare simplified to drop theirreferences to the placeholder string.
Compatibility note: custom
ClientQuotaCallbackimplementations thatcompare
ConfigEntity.name()against the literal"<default>"willneed to check for
nullinstead. In practice this pattern is uncommon:well-written callbacks distinguish default entities by reference
comparison against the
ClientQuotaManager.DEFAULT_USER_ENTITYandDEFAULT_USER_CLIENT_IDsingletons rather than by string comparison onname(). Since the prior Javadoc documented an empty string return, anycomparison against
"<default>"was relying on undocumented behavior.The internal metric-tag lookup path in
updateQuotaMetricConfigsisunaffected: default entities are routed through the iterate-all-metrics
branch via
updatedQuotaEntity = Optional.empty(), sosanitizedUser()and
clientId()are never invoked on a default-entityKafkaQuotaEntity.Reviewers: Chia-Ping Tsai chia7712@gmail.com