Implement Quota ignoring Target 500 responses

Not applicable

Hi @Anil Sagar @Ozan Seymen @Dino @arghya das

How do I implement a quota policy such that if target/downstream applications returns 500 http errors my quota counter will not increase.

Keeping the quota policy in proxy preflow I tried to do this using a JS policy where if the provider system returned 500 errors i would simply extract the ratelimit.Quota.class.allowed.count and manually decrease this by 1. My proxy got saved but the JS policy did not affect the counter. Instead I saw =/= symbol in Trace.

Is there any other way to do this.

I thought about creating a custom Java Quota code but I guess as per the documentation this approach would also be impossible.

Please advise.

0 8 224
8 REPLIES 8

Not applicable

Hi

Apigee edge quota service can be accessed from Node.js. Applyquota policy can be used to increment the quota by one whenever backend sends 500 errors.

One way of solving it is by increasing the value of quota so that increase in quota counter corresponds to increase in the value of quota also.

By setting allow to one everytime quota will increase by one.

quota.apply({
  identifier: 'Foo',
  timeUnit: 'hour',
  allow: 1,
  weight: 10
}, quotaResult);


Hope this helps.

@Tamilarasan , Above question is talking about decreasing the counter / Not to increment Quota in case of 500.

Your answer is related to increasing by one & more over Node.JS is a overkill.

@Anil Sagar Above question is if backend encounters 500 quota counter shoudn't increase .

One way of solving it is by increasing the value of quota so that increase in quota counter corresponds to increase in the value of quota also.

My solution will increment the value of quota by one .

@Arunava Paul ,

Reset Quota Policy in fault rules should work. See answer here that explains same where reset quota policy can be used to increase available quota count value.

@Anil Sagar

What if quota is configured at product level.Your solution will not handle it i believe.

Thanks @Anil Sagar @Tamilarasan

I'm guessing you meant in Target postflow right?

But in this case even if counter is reached requests will still go to Target right?

And I can place my quota only once in the flow.

Please advise

Target PreFlow / PostFlow , You can place in any. Preflow executes before conditional flows if any, Postflow executes after conditional flows if any.

@Arunava Paul , That's correct. How did i miss this simple thing! Client will see quota error if it reaches the limit. But, Request goes through the target & comes back. Yes, You are right. Above approach is not an ideal solution.

You should use Reset Quota Policy in fault rules to reset the quota to availablecount + 1 if the response errors out with 500. That should work. Let me know what do you think.

Hi @Anil Sagar

This approach looks better.

Trying with a javascript before reset-quota.

JS code is as below:-

var quotaAllowCount = context.getVariable("ratelimit.CopperQuota.allowed.count"); context.setVariable("newCount", quotaAllowCount + 1)

Reset-Quota is as below:-

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ResetQuota async="false" continueOnError="false" enabled="true" name="Reset-Quota-Copper">

<DisplayName>Reset Quota-Copper</DisplayName>

<Properties/>

<Quota name="CopperQuota">

<Identifier ref="_default">

<Allow countRef="newCount"/>

</Identifier>

</Quota>

</ResetQuota>

It's not re-setting.

Please advise.