Skip to content

Commit f3d2607

Browse files
frankvickychia7712
authored andcommitted
MINOR: Remove unused QuotaConfgHandler (#18617)
Reviewers: Chia-Ping Tsai <[email protected]>
1 parent 8b0ef93 commit f3d2607

File tree

4 files changed

+37
-67
lines changed

4 files changed

+37
-67
lines changed

core/src/main/scala/kafka/server/ConfigHandler.scala

-58
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@
1717

1818
package kafka.server
1919

20-
import java.net.{InetAddress, UnknownHostException}
2120
import java.util.{Collections, Properties}
2221
import kafka.log.UnifiedLog
23-
import kafka.network.ConnectionQuotas
2422
import kafka.server.QuotaFactory.QuotaManagers
2523
import kafka.utils.Logging
2624
import org.apache.kafka.server.config.{QuotaConfig, ZooKeeperInternals}
27-
import org.apache.kafka.common.metrics.Quota
2825
import org.apache.kafka.common.metrics.Quota._
29-
import org.apache.kafka.common.utils.Sanitizer
3026
import org.apache.kafka.coordinator.group.GroupCoordinator
3127
import org.apache.kafka.server.ClientMetricsManager
3228
import org.apache.kafka.server.common.StopPartition
@@ -142,60 +138,6 @@ class TopicConfigHandler(private val replicaManager: ReplicaManager,
142138
}
143139
}
144140

145-
146-
/**
147-
* Handles <client-id>, <user> or <user, client-id> quota config updates in ZK.
148-
* This implementation reports the overrides to the respective ClientQuotaManager objects
149-
*/
150-
class QuotaConfigHandler(private val quotaManagers: QuotaManagers) {
151-
152-
def updateQuotaConfig(sanitizedUser: Option[String], sanitizedClientId: Option[String], config: Properties): Unit = {
153-
val clientId = sanitizedClientId.map(Sanitizer.desanitize)
154-
val producerQuota =
155-
if (config.containsKey(QuotaConfig.PRODUCER_BYTE_RATE_OVERRIDE_CONFIG))
156-
Some(new Quota(config.getProperty(QuotaConfig.PRODUCER_BYTE_RATE_OVERRIDE_CONFIG).toLong.toDouble, true))
157-
else
158-
None
159-
quotaManagers.produce.updateQuota(sanitizedUser, clientId, sanitizedClientId, producerQuota)
160-
val consumerQuota =
161-
if (config.containsKey(QuotaConfig.CONSUMER_BYTE_RATE_OVERRIDE_CONFIG))
162-
Some(new Quota(config.getProperty(QuotaConfig.CONSUMER_BYTE_RATE_OVERRIDE_CONFIG).toLong.toDouble, true))
163-
else
164-
None
165-
quotaManagers.fetch.updateQuota(sanitizedUser, clientId, sanitizedClientId, consumerQuota)
166-
val requestQuota =
167-
if (config.containsKey(QuotaConfig.REQUEST_PERCENTAGE_OVERRIDE_CONFIG))
168-
Some(new Quota(config.getProperty(QuotaConfig.REQUEST_PERCENTAGE_OVERRIDE_CONFIG).toDouble, true))
169-
else
170-
None
171-
quotaManagers.request.updateQuota(sanitizedUser, clientId, sanitizedClientId, requestQuota)
172-
val controllerMutationQuota =
173-
if (config.containsKey(QuotaConfig.CONTROLLER_MUTATION_RATE_OVERRIDE_CONFIG))
174-
Some(new Quota(config.getProperty(QuotaConfig.CONTROLLER_MUTATION_RATE_OVERRIDE_CONFIG).toDouble, true))
175-
else
176-
None
177-
quotaManagers.controllerMutation.updateQuota(sanitizedUser, clientId, sanitizedClientId, controllerMutationQuota)
178-
}
179-
}
180-
181-
class IpConfigHandler(private val connectionQuotas: ConnectionQuotas) extends ConfigHandler with Logging {
182-
183-
def processConfigChanges(ip: String, config: Properties): Unit = {
184-
val ipConnectionRateQuota = Option(config.getProperty(QuotaConfig.IP_CONNECTION_RATE_OVERRIDE_CONFIG)).map(_.toInt)
185-
val updatedIp = {
186-
if (ip != ZooKeeperInternals.DEFAULT_STRING) {
187-
try {
188-
Some(InetAddress.getByName(ip))
189-
} catch {
190-
case _: UnknownHostException => throw new IllegalArgumentException(s"Unable to resolve address $ip")
191-
}
192-
} else
193-
None
194-
}
195-
connectionQuotas.updateIpConnectionRateQuota(updatedIp, ipConnectionRateQuota)
196-
}
197-
}
198-
199141
/**
200142
* The BrokerConfigHandler will process individual broker config changes in ZK.
201143
* The callback provides the brokerId and the full properties set read from ZK.

core/src/main/scala/kafka/server/metadata/ClientQuotaMetadataManager.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class ClientQuotaMetadataManager(private[metadata] val quotaManagers: QuotaManag
105105
}
106106
}
107107

108-
private def handleIpQuota(ipEntity: QuotaEntity, quotaDelta: ClientQuotaDelta): Unit = {
108+
private[metadata] def handleIpQuota(ipEntity: QuotaEntity, quotaDelta: ClientQuotaDelta): Unit = {
109109
val inetAddress = ipEntity match {
110110
case IpEntity(ip) =>
111111
try {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package kafka.server.metadata
18+
19+
import org.apache.kafka.image.ClientQuotaDelta
20+
import org.junit.jupiter.api.Assertions.{assertDoesNotThrow, assertThrows}
21+
import org.junit.jupiter.api.Test
22+
import org.junit.jupiter.api.function.Executable
23+
24+
25+
class ClientQuotaMetadataManagerTest {
26+
27+
@Test
28+
def testHandleIpQuota(): Unit = {
29+
val manager = new ClientQuotaMetadataManager(null, null)
30+
assertThrows(classOf[IllegalArgumentException], () => manager.handleIpQuota(IpEntity("a"), new ClientQuotaDelta(null)))
31+
assertThrows(classOf[IllegalStateException], () => manager.handleIpQuota(UserEntity("a"), new ClientQuotaDelta(null)))
32+
assertDoesNotThrow { new Executable { def execute(): Unit = manager.handleIpQuota(DefaultIpEntity, new ClientQuotaDelta(null)) } }
33+
assertDoesNotThrow { new Executable { def execute(): Unit = manager.handleIpQuota(IpEntity("192.168.1.1"), new ClientQuotaDelta(null)) } }
34+
assertDoesNotThrow { new Executable { def execute(): Unit = manager.handleIpQuota(IpEntity("2001:db8::1"), new ClientQuotaDelta(null)) } }
35+
}
36+
}

core/src/test/scala/unit/kafka/server/DynamicConfigChangeTest.scala

-8
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,6 @@ class DynamicConfigChangeTest extends KafkaServerTestHarness {
486486
}
487487

488488
class DynamicConfigChangeUnitTest {
489-
@Test
490-
def testIpHandlerUnresolvableAddress(): Unit = {
491-
val configHandler = new IpConfigHandler(null)
492-
val props: Properties = new Properties()
493-
props.put(QuotaConfig.IP_CONNECTION_RATE_OVERRIDE_CONFIG, "1")
494-
495-
assertThrows(classOf[IllegalArgumentException], () => configHandler.processConfigChanges("illegal-hostname", props))
496-
}
497489

498490
@Test
499491
def shouldParseReplicationQuotaProperties(): Unit = {

0 commit comments

Comments
 (0)