splett2 commented on a change in pull request #9386: URL: https://github.com/apache/kafka/pull/9386#discussion_r521564771
########## File path: core/src/test/scala/unit/kafka/network/ConnectionQuotasTest.scala ########## @@ -477,6 +568,99 @@ class ConnectionQuotasTest { assertTrue("Expected BlockedPercentMeter metric for EXTERNAL listener to be recorded", blockedPercentMeters("EXTERNAL").count() > 0) } + @Test + def testIpConnectionRateUpdate(): Unit = { + val config = KafkaConfig.fromProps(brokerPropsWithDefaultConnectionLimits) + connectionQuotas = new ConnectionQuotas(config, Time.SYSTEM, metrics) + connectionQuotas.addListener(config, listeners("EXTERNAL").listenerName) + connectionQuotas.addListener(config, listeners("ADMIN").listenerName) + connectionQuotas.addListener(config, listeners("REPLICATION").listenerName) + val defaultIpRate = 50 + val defaultOverrideRate = 20 + val overrideIpRate = 30 + val externalListener = listeners("EXTERNAL") + val adminListener = listeners("ADMIN") + // set a non-unlimited default quota so that we create ip rate sensors/metrics + connectionQuotas.updateIpConnectionRateQuota(None, Some(defaultIpRate)) + connectionQuotas.inc(externalListener.listenerName, externalListener.defaultIp, blockedPercentMeters("EXTERNAL")) + connectionQuotas.inc(adminListener.listenerName, adminListener.defaultIp, blockedPercentMeters("ADMIN")) + + // both IPs should have the default rate + verifyIpConnectionQuota(externalListener.defaultIp, defaultIpRate) + verifyIpConnectionQuota(adminListener.defaultIp, defaultIpRate) + + // external listener should have its in-memory quota and metric config updated + connectionQuotas.updateIpConnectionRateQuota(Some(externalListener.defaultIp.getHostAddress), Some(overrideIpRate)) + verifyIpConnectionQuota(externalListener.defaultIp, overrideIpRate) + + // update default + connectionQuotas.updateIpConnectionRateQuota(None, Some(defaultOverrideRate)) + + // external listener IP should not have its quota updated to the new default + verifyIpConnectionQuota(externalListener.defaultIp, overrideIpRate) + // admin listener IP should have its quota updated with to the new default + verifyIpConnectionQuota(adminListener.defaultIp, defaultOverrideRate) + + // remove default connection rate quota + connectionQuotas.updateIpConnectionRateQuota(None, None) + verifyIpConnectionQuota(adminListener.defaultIp, DynamicConfig.Ip.DefaultConnectionCreationRate) + + // remove override for external listener IP + connectionQuotas.updateIpConnectionRateQuota(Some(externalListener.defaultIp.getHostAddress), None) + verifyIpConnectionQuota(externalListener.defaultIp, DynamicConfig.Ip.DefaultConnectionCreationRate) + } + + @Test + def testIpConnectionRateQuotaUpdate(): Unit = { Review comment: I renamed to `testIpConnectionRateMetricUpdate` and `testEnforcedIpConnectionRateQuotaUpdate` to clarify. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org