Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -105,6 +105,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("127.0.0.1", maxConnectionsPerIPOverride)
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.

Would it make more sense to use localhost like above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are right! I will address it!


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

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