splett2 commented on a change in pull request #9386: URL: https://github.com/apache/kafka/pull/9386#discussion_r526525212
########## File path: core/src/main/scala/kafka/network/SocketServer.scala ########## @@ -1476,33 +1650,36 @@ class ConnectionQuotas(config: KafkaConfig, time: Time, metrics: Metrics) extend * Creates sensor for tracking the connection creation rate and corresponding connection rate quota for a given * listener or broker-wide, if listener is not provided. * @param quotaLimit connection creation rate quota - * @param listenerOpt listener name if sensor is for a listener + * @param connectionQuotaEntity entity to create the sensor for */ - private def createConnectionRateQuotaSensor(quotaLimit: Int, listenerOpt: Option[String] = None): Sensor = { - val sensorName = listenerOpt.map(listener => s"ConnectionAcceptRate-$listener").getOrElse("ConnectionAcceptRate") - val sensor = metrics.sensor(sensorName, rateQuotaMetricConfig(quotaLimit)) - sensor.add(connectionRateMetricName(listenerOpt), new Rate, null) - info(s"Created $sensorName sensor, quotaLimit=$quotaLimit") - sensor + private def getOrCreateConnectionRateQuotaSensor(quotaLimit: Int, connectionQuotaEntity: ConnectionQuotaEntity): Sensor = { + Option(metrics.getSensor(connectionQuotaEntity.sensorName)).getOrElse { Review comment: I will add this detail to `recordIpConnectionMaybeThrottle`. I think that is a more fitting place to put the comment, since that's the section of code that calls `connectionRateForIp` and `getOrCreateConnectionRateQuotaSensor` which are the components we need to be atomic. ---------------------------------------------------------------- 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