MahsaSeifikar commented on code in PR #19742: URL: https://github.com/apache/kafka/pull/19742#discussion_r2164104393
########## core/src/main/scala/kafka/server/ClientQuotaManager.scala: ########## @@ -451,6 +450,41 @@ class ClientQuotaManager(private val config: ClientQuotaManagerConfig, } } + /** + * Helper method to update quotaTypesEnabled which is a bitwise OR combination of the enabled quota types. + * For example: + * - If UserQuotaEnabled = 2 and ClientIdQuotaEnabled = 1, then quotaTypesEnabled = 3 (2 | 1 = 3) + * - If UserClientIdQuotaEnabled = 4 and UserQuotaEnabled = 1, then quotaTypesEnabled = (4 | 1 = 5) + * - If UserClientIdQuotaEnabled = 4 and ClientIdQuotaEnabled = 2, then quotaTypesEnabled = 6 (4 | 2 = 6) + * - If all three are enabled (1 | 2 | 4), then quotaTypesEnabled = 7 + */ + private def updateQuotaTypes(): Unit = { + var updatedQuotaTypesEnabled = if (clientQuotaCallbackPlugin.isDefined) { + QuotaTypes.CustomQuotas + } else { + QuotaTypes.NoQuotas + } + + val activeQuotaTypes = scala.collection.mutable.Set[String]() + + activeQuotaEntities.forEach { + case KafkaQuotaEntity(Some(_), Some(_)) => + updatedQuotaTypesEnabled |= QuotaTypes.UserClientIdQuotaEnabled + activeQuotaTypes += "UserClientIdQuota" + case KafkaQuotaEntity(Some(_), None) => + updatedQuotaTypesEnabled |= QuotaTypes.UserQuotaEnabled + activeQuotaTypes += "UserQuota" + case KafkaQuotaEntity(None, Some(_)) => + updatedQuotaTypesEnabled |= QuotaTypes.ClientIdQuotaEnabled + activeQuotaTypes += "ClientIdQuota" + case _ => // Unexpected entity type + } + + quotaTypesEnabled = updatedQuotaTypesEnabled Review Comment: We don't expect the quota to change frequently, but we faced a case where a quota was set, then removed, and because `quotaTypesEnabled` wasn't updated, incorrect metric tags were generated, causing a memory issue. This PR addresses that specific rare case. I've added a couple of tests and performed manual testing to ensure it works reliably, even with frequent changes -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org