Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-18530 Remove ZooKeeperInternals #18641

Merged
merged 22 commits into from
Feb 6, 2025
Merged

Conversation

m1a2st
Copy link
Contributor

@m1a2st m1a2st commented Jan 20, 2025

Jira: https://issues.apache.org/jira/browse/KAFKA-18530

Since Kafka 4.0 has deprecated ZooKeeper, we should also remove the ZooKeeperInternals class. However, we need to maintain backward compatibility for metric names.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@github-actions github-actions bot added triage PRs from the community core Kafka Broker small Small PRs labels Jan 20, 2025
@m1a2st m1a2st changed the title KAFKA 18530 Rename ZooKeeperInternals KAFKA-18530 Rename ZooKeeperInternals Jan 20, 2025
@@ -16,12 +16,11 @@
*/
package org.apache.kafka.server.config;

public class ZooKeeperInternals {
public class KraftInternals {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this name makes sense - there's nothing specific to kraft in this code. Can we move this constant to one of the quota classes and have the others reference it from there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing this would affect the default username and default client-id. Since this is a breaking change, I suggest we maintain consistency by keeping these default values. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

@m1a2st Could you please clean up the usage of ZooKeeperInternals.DEFAULT_STRING first? We are currently using ZooKeeperInternals.DEFAULT_STRING as a specific string for compatibility with the zk handler (QuotaConfigHandler). Since #18617 will remove QuotaConfigHandler, the kraft ClientQuotaMetadataManager no longer needs to use ZooKeeperInternals.DEFAULT_STRING.

After addressing above comment, we can move <default> to be a internal constant of ClientQuotaManager to ensure the compatibility of metrics kafka.server:type={Produce|Fetch},user=([-.\w]+),client-id=([-.\w]+)

@github-actions github-actions bot removed triage PRs from the community small Small PRs labels Jan 21, 2025
@@ -147,13 +148,13 @@ class ClientQuotaMetadataManager(private[metadata] val quotaManagers: QuotaManag
// Convert entity into Options with sanitized values for QuotaManagers
val (sanitizedUser, sanitizedClientId) = quotaEntity match {
case UserEntity(user) => (Some(Sanitizer.sanitize(user)), None)
case DefaultUserEntity => (Some(ZooKeeperInternals.DEFAULT_STRING), None)
case DefaultUserEntity => (Some(ClientQuotaManager.DefaultString), None)
Copy link
Member

Choose a reason for hiding this comment

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

We should use Option[BaseUserEntity] instead of a string. As mentioned previously (#18641 (comment)), there's no need for a specific string to represent the "default" value.

if (brokerId == ZooKeeperInternals.DEFAULT_STRING)
brokerConfig.dynamicConfig.updateDefaultConfig(properties)
else if (brokerConfig.brokerId == brokerId.trim.toInt) {
if (brokerConfig.brokerId == brokerId.trim.toInt) {
Copy link
Member

Choose a reason for hiding this comment

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

We must handle the "default" configs when the broker id is "empty"

@chia7712
Copy link
Member

@m1a2st could you please rebase code to include the recent flaky fixes?

@m1a2st m1a2st changed the title KAFKA-18530 Rename ZooKeeperInternals [WIP]KAFKA-18530 Rename ZooKeeperInternals Jan 30, 2025
@m1a2st m1a2st changed the title [WIP]KAFKA-18530 Rename ZooKeeperInternals KAFKA-18530 Rename ZooKeeperInternals Jan 31, 2025
): Option[ClientQuotaEntity.ConfigEntity] = {
if (sanitizedClientId.isEmpty)
None
else if (sanitizedClientId.get.name() == DefaultString)
Copy link
Member

Choose a reason for hiding this comment

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

in kraft, we don't use <default> so this check is weird. If this is used to fix test, then maybe we should revise the test

else if (sanitizedClientId.get.name() == DefaultString)
Some(DefaultClientIdEntity)
else {
val clientId = sanitizedClientId.map(s => Sanitizer.desanitize(s.name()))
Copy link
Member

Choose a reason for hiding this comment

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

we should handle the ClientIdEntity only.

@m1a2st m1a2st changed the title KAFKA-18530 Rename ZooKeeperInternals KAFKA-18530 Remove ZooKeeperInternals Feb 2, 2025
Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@m1a2st thanks for this patch

core/src/main/scala/kafka/server/DynamicConfig.scala Outdated Show resolved Hide resolved
@@ -48,13 +48,6 @@ import scala.collection._
import scala.jdk.CollectionConverters._

/**
* Dynamic broker configurations are stored in ZooKeeper and may be defined at two levels:
Copy link
Member

Choose a reason for hiding this comment

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

in kraft mode, the two levels are still existent. could you please revise it instead of removing it?

Copy link
Contributor

@clolov clolov Feb 3, 2025

Choose a reason for hiding this comment

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

Heya @m1a2st! I have a follow-up ask, while the two levels are still present they will no longer be under the path specified in this file since the path is ZK-specific. As long as we don't use this comment to generate documentation I am okay with this being removed in a subsequent PR. However, if we use this file to generate documentation could you change this as part of this PR?

Copy link
Member

Choose a reason for hiding this comment

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

I think those comments in DynamicBrokerConfig are not used to generate documentation, but it will be better to correct it - as least, the description about zk path must be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, then I will review once they have been changed 😊!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for @clolov and @chia7712, update this document. If there is any idea, please let me know

core/src/main/scala/kafka/server/ClientQuotaManager.scala Outdated Show resolved Hide resolved
@m1a2st
Copy link
Contributor Author

m1a2st commented Feb 3, 2025

Thanks for @chia7712 review, addressed all comments.

case DefaultUserEntity =>
(Some(ClientQuotaManager.DefaultUserEntity), None)
case ClientIdEntity(clientId) =>
(None, Some(ClientQuotaManager.ClientIdEntity(Sanitizer.sanitize(clientId))))
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to sanitize data in kraft mode? the zk path is gone so we don't need to align the data for zk anymore.

Copy link
Contributor Author

@m1a2st m1a2st Feb 5, 2025

Choose a reason for hiding this comment

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

In sanitize method, It deal with * and + symbols. Therefore, I think it is not only handling matters related to Zookeeper.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After under discussion, We should remove this sanitize, it is unused in this path.

val clientIdEntity = sanitizedClientId.map {
case ZooKeeperInternals.DEFAULT_STRING => DefaultClientIdEntity
case _ => ClientIdEntity(clientId.getOrElse(throw new IllegalStateException("Client-id not provided")))
val clientIdEntity = clientEntity match {
Copy link
Member

Choose a reason for hiding this comment

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

we don't need this conversion, right?

@chia7712 chia7712 merged commit a3d9d88 into apache:trunk Feb 6, 2025
9 checks passed
@chia7712
Copy link
Member

chia7712 commented Feb 6, 2025

@m1a2st please file a PR for 4.0 as there are some conflicts

chia7712 pushed a commit that referenced this pull request Feb 6, 2025
Since zk has been removed in 4.0, config handlers no longer need to handle the "<default>" value. This PR streamlines the config update process by eliminating the unnecessary string checks for "<default>"

Reviewers: Christo Lolov <[email protected]>, Ismael Juma <[email protected]>, Chia-Ping Tsai <[email protected]>
@chia7712
Copy link
Member

chia7712 commented Feb 6, 2025

please file a PR for 4.0 as there are some conflicts

I backport some cleanup to eliminate the conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants