Rate Limiting Policy for Azure to limit specific subscriptions not working as intended

68 Views Asked by At

I have this in my inbound policy:

<choose>
    <when condition="@(context.Subscription.Name=="someName")" />
    <when condition="@(context.Subscription.Name=="otherName")" />
    <otherwise>
        <rate-limit calls="50" renewal-period="300" remaining-calls-variable-name="remainingCallsPerSubscription" />
    </otherwise>
</choose>

It does not seem to work as intended, throttling also the above named subscriptions, am I missing something?

p.s. I am on the consumption model

1

There are 1 best solutions below

0
Ikhtesam Afrin On

I have used the same policy to exempt the subscription keys which are being used from rate-limit policy.

For testing purpose, I have taken 10 calls.

<policies>
    <inbound>
        <base />
        <choose>
            <when condition="@(context.Subscription.Name=="test")" />
            <when condition="@(context.Subscription.Name=="demo")" />
            <otherwise>
                <rate-limit calls="10" renewal-period="300" remaining-calls-variable-name="remainingCallsPerSubscription" />
            </otherwise>
        </choose>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

While testing, you need to pass the subscription key name is Ocp-Apim-Subscription-Key and the value will be the value of your subscription key or else it will fetch the value of context.Subscription.Name as Built-in all-access subscription by default.

enter image description here enter image description here

When the value of context.Subscription.Name is false, I am getting expected response as shown below.

enter image description here

enter image description here enter image description here

In order to get the expected response, please make sure you don't have any other policy defined at global or API level.