Quota Timer

Currently, in Quota policy timer starts after 1st request arrives or after specific time mentioned in StartTime tag.

Is it possible in Quota policy to start the timer after Quota limit exceeds+1 Request i.e.

Suppose, I have allowed 5 request per minute in Quota policy. Now, I want to start Quota timer after 6th Request arrives. So, on 6th request I will get Quota exceed limit error and 1 min interval will start at that time only.

EDIT

Suppose, I have allowed 5 requests per 2 minute using quota policy. Now, one application hits the proxy at 4:00 pm and at time same time quota timer will start. So, If all 5 requests are executed within 1 min then other incoming requests will be blocked till 4:02 pm and after 4:02 pm only user will get 5 requests again.

I want to customize quota policy in such a way that if 5 requests is executed within 1 min and when the 6th request arrives, then my timer will start i.e. if 6th request came at 4:01 pm then timer will start and quota will block incoming requests including 6th request till 4:03 pm. Instead of starting timer on 1st request I want to start it when 6th request arrives.

So, I want to know if there is possibility to customize quota policy or do I need to use some extensions to achieve this functionality.

Solved Solved
0 4 220
1 ACCEPTED SOLUTION

You cannot use a single quota to behave that way.

It kind of sounds like the "3rd grade substitute teacher" quota. That person gave people an extra timeout for asking to not be in timeout.

If I were trying to build this, I would use a quota for the rate limit, setting the continueOnError attribute to true. I'd use logic after the quota policy to check the context variables to see if the first quota met its rate limit.

Then, if the rate limit was met, I'd have a second bit of logic that stored the timeout. Let's say it's 2 minutes from now. So we'd need some arithmetic (maybe in JavaScript) to get the time in 2 minutes. I'd want to store that in KVM, using for the key, the identifier used in the previous Quota policy.

Finally, I'd need to insert some logic *before* the Quota policy, with a KVM GET , to retrieve the timeout for this call. There are two cases:

  1. the timeout value is not found.
  2. The timeout value is found

In the first case, just roll through to the Quota policy. In the second case, there are two sub-cases:

  1. the timeout has elapsed (it's in the past)
  2. the timeout has not elapsed (it's in the future)

If the timeout is in the past, then just delete the KVM Entry (or not, probably doesn't matter) and then roll through to the Quota.

If the timeout is in the future, then, reject the call (429) with a message saying "you're still in timeout". Optionally you could extend the timeout a little further, say 2 minutes after THIS call, using KVM PUT again.

To keep it sane, I'd probably want to use sharedflows for the logic that checks for timeout.

View solution in original post

4 REPLIES 4

Your question is not clear.

Is it possible in Quota policy to start the timer after Quota limit exceeds+1 Request

You cannot "start the timer" after the limit is exceeded. By definition, if there is a limit to exceed, then there has been a timer started. So your question isn't sensible.

Let me say it a different way. It sounds to me that you want to start the quota timer AFTER a quota limit has been exceeded. But if a quota limit has been exceeded, then... there IS a quota timer, and it started some time ago in the past. That's how quotas work.

on 6th request I will get Quota exceed limit error and 1 min interval will start at that time only.

And what happens after the (second) timer starts? I'm not clear on the situation or experience you're hoping to enable.

Maybe you could try again to explain what you want, with more examples, or ... maybe explain it more slowly or something.

Hey @Dino-at-Google,

Let me explain my question with an example to give you better understanding.

Example

Suppose, I have allowed 5 requests per 2 minute using quota policy. Now, one application hits the proxy at 4:00 pm and at time same time quota timer will start. So, If all 5 requests are executed within 1 min then other incoming requests will be blocked till 4:02 pm and after 4:02 pm only user will get 5 requests again.

I want to customize quota policy in such a way that if 5 requests is executed within 1 min and when the 6th request arrives, then my timer will start i.e. if 6th request came at 4:01 pm then timer will start and quota will block incoming requests including 6th request till 4:03 pm. Instead of starting timer on 1st request I want to start it when 6th request arrives.

So, I want to know if there is possibility to customize quota policy or do I need to use some extensions to achieve this functionality.

I hope this will help.

You cannot use a single quota to behave that way.

It kind of sounds like the "3rd grade substitute teacher" quota. That person gave people an extra timeout for asking to not be in timeout.

If I were trying to build this, I would use a quota for the rate limit, setting the continueOnError attribute to true. I'd use logic after the quota policy to check the context variables to see if the first quota met its rate limit.

Then, if the rate limit was met, I'd have a second bit of logic that stored the timeout. Let's say it's 2 minutes from now. So we'd need some arithmetic (maybe in JavaScript) to get the time in 2 minutes. I'd want to store that in KVM, using for the key, the identifier used in the previous Quota policy.

Finally, I'd need to insert some logic *before* the Quota policy, with a KVM GET , to retrieve the timeout for this call. There are two cases:

  1. the timeout value is not found.
  2. The timeout value is found

In the first case, just roll through to the Quota policy. In the second case, there are two sub-cases:

  1. the timeout has elapsed (it's in the past)
  2. the timeout has not elapsed (it's in the future)

If the timeout is in the past, then just delete the KVM Entry (or not, probably doesn't matter) and then roll through to the Quota.

If the timeout is in the future, then, reject the call (429) with a message saying "you're still in timeout". Optionally you could extend the timeout a little further, say 2 minutes after THIS call, using KVM PUT again.

To keep it sane, I'd probably want to use sharedflows for the logic that checks for timeout.

Thank you for the quick response 🙂

I know that it's kind of giving extra timeout which is not a part of quota policy at all. But this is what we need to achieve.