rabbah commented on a change in pull request #2684: Decorate throttled error
response with count/limit.
URL:
https://github.com/apache/incubator-openwhisk/pull/2684#discussion_r136547404
##########
File path:
core/controller/src/main/scala/whisk/core/entitlement/RateThrottler.scala
##########
@@ -45,43 +46,41 @@ class RateThrottler(description: String,
defaultMaxPerMinute: Int, overrideMaxPe
* @param user the identity to check
* @return true iff subject namespace is below allowed limit
*/
- def check(user: Identity)(implicit transid: TransactionId): Boolean = {
+ def check(user: Identity)(implicit transid: TransactionId): RateLimit = {
val uuid = user.uuid // this is namespace identifier
- val rate = rateMap.getOrElseUpdate(uuid, new RateInfo)
+ val throttle = rateMap.getOrElseUpdate(uuid, new RateInfo)
val limit = overrideMaxPerMinute(user).getOrElse(defaultMaxPerMinute)
- val belowLimit = rate.check(limit)
- logging.debug(this, s"namespace = ${uuid.asString} rate =
${rate.count()}, limit = $limit, below limit = $belowLimit")
- belowLimit
+ val rate = TimedRateLimit(throttle.update(limit), limit)
+ logging.debug(this, s"namespace = ${uuid.asString} rate =
${rate.count}, limit = $limit")
+ rate
}
}
/**
* Tracks the activation rate of one subject at minute-granularity.
*/
private class RateInfo {
- var lastMin = getCurrentMinute
- var lastMinCount = 0
-
- def count() = lastMinCount
+ @volatile var lastMin = getCurrentMinute
+ var lastMinCount = new AtomicInteger()
Review comment:
mmhmm.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services