Florestan Korp
Florestan Korp

Reputation: 711

Azure API Management inbound rule inheritance from base

When setting the rate-limit I apply to All Operations does it sum ALL endpoint calls together or is this rate limit per endpoint? This is crucial info when calculating a baseline for the maximum nr of calls, but I'm afraid I can't find any information in Azure itself about how this works...

Here is the policy I want to add to All Operations:

<rate-limit-by-key />

Then in my endpoint I want to just inherit by adding:

<base />

Upvotes: 0

Views: 659

Answers (2)

Florestan Korp
Florestan Korp

Reputation: 711

As it stands the calls under All operations get summed up in a single queue. So the rate limit counter is not for individual endpoints, not even if it is applied directly to an individual endpoint the reason being that the key is not unique to that enpoint.

So a call coming from one IP adress to different endpoints under the same inbound rule for example will update the counter for all enpoints using the same key (in this case the IP address).

To circumvent this I've made my keys unique by chaining IP address and operation name together forming a queue per endpoint and adding <rate-limit-by-key> to my endpoint instead of the <base />

The finished example inbound rule on my endpoint:

<rate-limit-by-key calls="xx" renewal-period="xx" counter-key="@(string.Join("-", context.Request.IpAddress, context.Operation.Id))" />

Upvotes: 2

Vitaliy Kurokhtin
Vitaliy Kurokhtin

Reputation: 7810

During request processing policies are executed sequentially. tag on lower level policies defines when upper level policies are executed. rate-limit-by-key works by maintaining one counter per provided key value irrelevant of where it's placed. If this counter goes over limits specified in policy request is blocked.

In other words, two rate-limit-by-key policies placed in different scopes will share counter value, but not limits.

Upvotes: 1

Related Questions