Quota policy - Throws Error:Unexpected response code: 500

Not applicable

I want to perform quota based limitation. For each user account our add on appliation generate a unique API Key based on we need to say if this tenant has reached their limit or not say 1000 per day per tenant. We just want to use Apigee Edge for proxy and throttling.

As per my understanding we've to use the <identifier> element with the quota policy because <identifier> element does value of a variable and for every unique value of that variable it creates a seperate counter. Thats' the reason from the 'request header' i'm using ''Zapiaccesskey' value.

Here is the request header:

request.headers
Out[1]: EnvironHeaders([('Authorization', u'JWT eyJ0eXAiciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsInFzaCI6ImZjZDU1YjIzNx5WVRwaEkRBdE9ERmxNUzFoTURFeU5HUmhNR0l5TVRZZUsImlhdCI6MTQ1NjQ4Mjc5NX0.chMhYrYob99FYc8Dv6VuHC8CLnx5-aRNTHLC2znNMrI'), ('Content-Length', u'69'), ('User-Agent', u'ZFJImporter'), ('Connection', u'Keep-Alive'), ('Host', u'192.168.200.91:5000'), ('Zapiaccesskey', u'amlyYTphOWU4YzYwZS00MzExLTRjNDAtODFaW4'), ('Content-Type', u'application/json; charset=UTF-8')])


Here is what I've done so far:

1. Created an Apigee Proxy

2. Attached a Quota policy

Here is the Quota Policy I created :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Quota async="false" continueOnError="false" enabled="true" name="Quota-1">
    <DisplayName>Quota-1</DisplayName>
    <Properties/>
    <Allow count="10"/>
    <Identifier ref="request.header.Zapiaccesskey"/>
    <Interval ref="request.header.quota_count">1</Interval>
    <Distributed>true</Distributed>
    <Synchronous>false</Synchronous>
    <TimeUnit ref="request.header.quota_timeout">month</TimeUnit>
</Quota>

The issue what I'm seeing is that even if I try to make a request using two different API keyss still I get the below error. The strange thing is that even if I try to make request with a newly generated (3rd) API key, it throw the same "Quota Limit Exceeded" error.

Error:Unexpected response code: 500 {"fault":{"faultstring":"Rate limit quota violation. Quota limit  exceeded. Identifier : ZjU3ONWUtZjY

Could someone please help me in fixing this issue.

Solved Solved
0 6 496
1 ACCEPTED SOLUTION

Hi, I'm sorry to hear you're having difficulty with the Quota policy.

I've put together a simple screencast showing it in action. I've used the exact configuration for the quota that you showed above. Maybe you can borrow from this screencast to get it working for you.

One of the things that can trip people up: Apigee Edge will remember the quota count for the duration of the quota TimeUnit. If you use a TimeUnit of 1 month, then Apigee Edge will remember if a quota has been exhausted, for up to 1 month. In which case, requests using the same identifier will receive a 500 response, indicating the quota has been exceeded. It might be easier to use a shorter TimeUnit for quotas, during testing. an hour, or a day. That way, you need to wait only 1 hour or 1 day before Apigee Edge automatically resets the quota count.

This might not be the problem you are facing though, because you said you used a newly generated identifier, and even in that case, the quota was still showing as exceeded. I cannot explain that observation.

View solution in original post

6 REPLIES 6

Hi, I'm sorry to hear you're having difficulty with the Quota policy.

I've put together a simple screencast showing it in action. I've used the exact configuration for the quota that you showed above. Maybe you can borrow from this screencast to get it working for you.

One of the things that can trip people up: Apigee Edge will remember the quota count for the duration of the quota TimeUnit. If you use a TimeUnit of 1 month, then Apigee Edge will remember if a quota has been exhausted, for up to 1 month. In which case, requests using the same identifier will receive a 500 response, indicating the quota has been exceeded. It might be easier to use a shorter TimeUnit for quotas, during testing. an hour, or a day. That way, you need to wait only 1 hour or 1 day before Apigee Edge automatically resets the quota count.

This might not be the problem you are facing though, because you said you used a newly generated identifier, and even in that case, the quota was still showing as exceeded. I cannot explain that observation.

Thanks a lot @Dino

As you suggested I changed the quota TimeUnit from 1 month to hour and Allow Count to 5 for quick testing.

What I noticed is when I make a request from API Key -1, it finishes successfully but on the 2nd request it throws same "Quota limit exceeded" and same thing happen when I try with API Key -2. The strange thing that I noticed is for a single request that we made it show 6 transactions in the "Trace Console", which I believe is equal to allowed Quota value(<Allow count="5"/>), right?

This also shows that the quota policy seems to be working fine. Any suggestion.

4083-capture.png

ok - that's a good clue. What you are seeing in the Trace UI means is that Apigee Edge really is receiving ...5 or 6 or whatever.... requests for every ONE you think you are sending. Those are distinct requests. And each one is being counted by the Quota policy.

If Apigee Edge is handling 5 or 6 requests, it will exceed your configured Quota count.

The next mystery is why you are seeing 5 or 6 requests when you think you should be sending only one request.

And I don't have a good explanation for that.

One possibility: something ELSE is invoking the API. The way to determine this is to check the inbound client IP address. This will be visible in the Trace UI.

It is possible even that there is a stray policy within the Proxy itself that is invoking the API. If you have a ServiceCallout or a JS policy, those things can be invoking your API, in a recursive manner.

But You will have to diagnose this part.

Good luck.

@Dino I looked at the test importer utility logs and find that it's indeed creating six requests for each test case that I upload. I can adjust the quota limitations accordingly, I believe it shouldn't be a problem. Though, I've an another challenge, I understand that we can make individual API proxies available for the customers to use and it's recommended to rather create API products(bundle of proxies) but our requriement is just to use Apigee Edge for proxy, throttling at this stage so I don't think it's required to create Product. Is this assumption true? Also, how will I be charged for using Apigee Edge Platform?

Hi Varun, please ask new questions via the "Ask a Question" button.

4099-ask-a-question-2.png

Sure @Dino Thanks