Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/src/main/scala/kafka/network/SocketServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,11 @@ class ConnectionQuotas(config: KafkaConfig, time: Time, metrics: Metrics) extend
connectionRatePerIp.getOrDefault(ip, defaultConnectionRatePerIp)
}

// Visible for testing
private[network] def maxConnectionsPerIpOverrideForIp(ip: InetAddress): Option[Int] = {
maxConnectionsPerIpOverrides.get(ip)
}

private[network] def addListener(config: KafkaConfig, listenerName: ListenerName): Unit = {
counts.synchronized {
if (!maxConnectionsPerListener.contains(listenerName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import org.apache.kafka.common.quota.{ClientQuotaAlteration, ClientQuotaEntity}
import org.apache.kafka.common.record.internal.{MemoryRecords, SimpleRecord}
import org.apache.kafka.common.requests.{ProduceRequest, ProduceResponse}
import org.apache.kafka.common.security.auth.SecurityProtocol
import org.apache.kafka.common.test.api.Flaky
import org.apache.kafka.common.{KafkaException, Uuid, requests}
import org.apache.kafka.network.SocketServerConfigs
import org.apache.kafka.server.config.QuotaConfig
Expand Down Expand Up @@ -81,7 +80,6 @@ class DynamicConnectionQuotaTest extends BaseRequestTest {
}
}

@Flaky("KAFKA-17999")
@Test
def testDynamicConnectionQuota(): Unit = {
val maxConnectionsPerIP = 5
Expand All @@ -105,6 +103,7 @@ class DynamicConnectionQuotaTest extends BaseRequestTest {
val maxConnectionsPerIPOverride = 7
props.put(SocketServerConfigs.MAX_CONNECTIONS_PER_IP_OVERRIDES_CONFIG, s"localhost:$maxConnectionsPerIPOverride")
reconfigureServers(props, perBrokerConfig = false, (SocketServerConfigs.MAX_CONNECTIONS_PER_IP_OVERRIDES_CONFIG, s"localhost:$maxConnectionsPerIPOverride"))
waitForMaxConnectionsOverrideApplied("localhost", maxConnectionsPerIPOverride)

verifyMaxConnections(maxConnectionsPerIPOverride, connectAndVerify)
}
Expand Down Expand Up @@ -416,4 +415,15 @@ class DynamicConnectionQuotaTest extends BaseRequestTest {
}.asJavaCollection
adminClient.alterClientQuotas(entries)
}

private def waitForMaxConnectionsOverrideApplied(ip: String, expected: Int): Unit = {
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.

This is only used once, maybe we can inline it? WDYT?

val addr = InetAddress.getByName(ip)
val quotas = brokers.head.socketServer.connectionQuotas

TestUtils.waitUntilTrue(
() => quotas.maxConnectionsPerIpOverrideForIp(addr).contains(expected),
s"maxConnectionsPerIpOverrides not applied yet for ip=$ip (expected=$expected, current=${quotas.maxConnectionsPerIpOverrideForIp(addr)})",
50000
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.

Do we need a timeout this long?

)
}
}
Loading