@@ -42,8 +42,8 @@ class BrokerQuotaManager(private val config: BrokerQuotaManagerConfig,
42
42
43
43
override def delayQueueSensor : Sensor = brokerDelayQueueSensor
44
44
45
- def getMaxValueInQuotaWindow (quotaType : QuotaType ): Double = {
46
- if (config.quotaEnabled ) {
45
+ def getMaxValueInQuotaWindow (quotaType : QuotaType , request : RequestChannel . Request ): Double = {
46
+ if (shouldThrottle(request) ) {
47
47
quotaLimit(quotaType)
48
48
} else {
49
49
Double .MaxValue
@@ -67,28 +67,24 @@ class BrokerQuotaManager(private val config: BrokerQuotaManagerConfig,
67
67
68
68
def maybeRecordAndGetThrottleTimeMs (quotaType : QuotaType , request : RequestChannel .Request , value : Double ,
69
69
timeMs : Long ): Int = {
70
- if (! config.quotaEnabled) {
71
- // Quota is disabled, no need to throttle
72
- return 0
73
- }
74
-
75
- if (isInternalClient(request.context.clientId())) {
76
- // Internal clients are exempt from quota
77
- return 0
78
- }
79
-
80
- if (isInWhiteList(request.session.principal, request.context.clientId(), request.context.listenerName())) {
81
- // Client is in the white list, no need to throttle
82
- return 0
70
+ if (shouldThrottle(request)) {
71
+ maybeRecordAndGetThrottleTimeMs(quotaType, value, timeMs)
72
+ } else {
73
+ 0
83
74
}
84
-
85
- maybeRecordAndGetThrottleTimeMs(quotaType, value, timeMs)
86
75
}
87
76
88
77
override protected def throttleTime (e : QuotaViolationException , timeMs : Long ): Long = {
89
78
QuotaUtils .boundedThrottleTime(e, maxThrottleTimeMs, timeMs)
90
79
}
91
80
81
+ private def shouldThrottle (request : RequestChannel .Request ): Boolean = {
82
+ val quotaEnabled = config.quotaEnabled
83
+ val isInternal = isInternalClient(request.context.clientId())
84
+ val isWhiteListed = isInWhiteList(request.session.principal, request.context.clientId(), request.context.listenerName())
85
+ quotaEnabled && ! isInternal && ! isWhiteListed
86
+ }
87
+
92
88
private def isInternalClient (clientId : String ): Boolean = {
93
89
clientId.startsWith(QuotaConfigs .INTERNAL_CLIENT_ID_PREFIX )
94
90
}
0 commit comments