Skip to content

KAFKA-18735: Return null from ConfigEntity.name() for default quotas#22099

Open
mingyen066 wants to merge 2 commits intoapache:trunkfrom
mingyen066:KAFKA-18735-default-quota-callback
Open

KAFKA-18735: Return null from ConfigEntity.name() for default quotas#22099
mingyen066 wants to merge 2 commits intoapache:trunkfrom
mingyen066:KAFKA-18735-default-quota-callback

Conversation

@mingyen066
Copy link
Copy Markdown
Collaborator

@mingyen066 mingyen066 commented Apr 20, 2026

ConfigEntity.name() currently returns the ZooKeeper-era placeholder
string "<default>" for default quota entities (DEFAULT_USER_ENTITY
and DEFAULT_USER_CLIENT_ID). This is asymmetric with the Admin API:
callers create a default quota by passing null as the entity name —
the org.apache.kafka.common.quota.ClientQuotaEntity constructor
Javadoc 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 the
string "<default>" rather than null. The server-side ConfigEntity
Javadoc additionally documented an empty-string return value, which
matched neither the Admin API nor the actual implementation.

This change makes ConfigEntity.name() return null for default
entities, aligning the ClientQuotaCallback interface with the Admin
API, and updates the Javadoc accordingly. The internal DEFAULT_NAME
constant in ClientQuotaManager is removed, and the sanitizedUser() /
clientId() helpers on KafkaQuotaEntity are simplified to drop their
references to the placeholder string.

Compatibility note: custom ClientQuotaCallback implementations that
compare ConfigEntity.name() against the literal "<default>" will
need to check for null instead. In practice this pattern is uncommon:
well-written callbacks distinguish default entities by reference
comparison against the ClientQuotaManager.DEFAULT_USER_ENTITY and
DEFAULT_USER_CLIENT_ID singletons rather than by string comparison on
name(). Since the prior Javadoc documented an empty string return, any
comparison against "<default>" was relying on undocumented behavior.

The internal metric-tag lookup path in updateQuotaMetricConfigs is
unaffected: default entities are routed through the iterate-all-metrics
branch via updatedQuotaEntity = Optional.empty(), so sanitizedUser()
and clientId() are never invoked on a default-entity
KafkaQuotaEntity.

Reviewers: Chia-Ping Tsai chia7712@gmail.com

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.
@github-actions github-actions Bot added triage PRs from the community core Kafka Broker clients small Small PRs labels Apr 20, 2026
@Override
public String name() {
return DEFAULT_NAME;
return null;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a small but breaking change, so it requires a KIP, even though I'd personally love to merge it directly.

@github-actions github-actions Bot removed the triage PRs from the community label Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clients core Kafka Broker small Small PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants