Skip to content

2.1.5 Configure API Quotas

Chris Wiechmann edited this page Jun 14, 2021 · 9 revisions

Since version 1.6.1 the handling of Quotas has changed significantly to provide more flexibility and control.

A new parameter: quotaMode has been introduced, which can be have one of the following options:

  • quotaMode=ignore
    The same as setting ignoreQuota=true. The quota handling is completely turned off.
  • quotaMode=replace
    With this mode, potentially existing Quotas for that API, that might have been manually configured, will be replaced by the configured quotas.
  • quotaMode=add
    This is the default option, if nothing else is provided. With that the APIM-CLI is adding configured quotas to potentially already existing quotas.
    In order to identify existing quotas the following Quota-Keys are used:
    API-Method,
    Quota-Type (Throttle Messages or Megabyte)
    Time range (Hour, Day, etc.)
    per-value (1, 2 ... days, hours, etc.).

Based on these keys the APIM-CLI is identifying existing quotas which are handled using mode: add as described below.
Let's take the following example. When someone manually configures the following quota in API-Manager for an API:
Quota config example 1

And the following is configured for the same API in the API-Config-File:

   "applicationQuota":{
      "restrictions":[
         {
            "method":"*",
            "type":"throttlemb",
            "config":{
               "period":"hour",
               "mb":50,
               "per":1
            }
         }
      ]
   }

Swagger-Promote will overwrite the manually configured Quota to 50MB instead 1.000MB as all Quota-Keys are the same. It is basically the same Quota-Restriction and therefore updated to the desired value.

But with the following example and the same configured Quotas as from above:

   "applicationQuota":{
      "restrictions":[
         {
            "method":"*",
            "type":"throttlemb",
            "config":{
               "period":"day",
               "mb":10000,
               "per":1
            }
         }
      ]
   }

An additional quota entry in combination with the existing one will be added. This would be the result: Quota config example 1

This is useful to combine different quotas for one API.

With version 1.6.1 and higher it is also possible to configure multiple quotas for an API at the same time. For instance this example:

   "applicationQuota":{
      "restrictions":[
         {
            "method":"*",
            "type":"throttlemb",
            "config":{
               "period":"day",
               "mb":10000,
               "per":1
            }
         }, 
         {
            "method":"*",
            "type":"throttlemb",
            "config":{
               "period":"hour",
               "mb":1000,
               "per":1
            }
         }, 
         {
            "method":"*",
            "type":"throttle",
            "config":{
               "period":"minute",
               "messages":2000,
               "per":30
            }
         }
      ]
   }

This configuration results into the following API-Manager setting for this API:
Quota config example 1

This is enforced by the API-Manager at runtime in combination.

When using quotaMode=add (which is the default) and changing Quota-Keys (e.g. Type, Time-range, Per) in the API-Configuration file Swagger-Promote cannot identify anymore if existing quotas has been added manually or by Swagger-Promote before. Therefore new Quota-Entries will be added.
The recommendation is to avoid too many Key changes in the API-Config-File, but if it's required two options:

  • replicate the API (maybe only once) with quotaMode=replace to bring it to the configured desired state
  • clean-up unused quotas in API-Manager manually

⚠️ Please be aware, that API-Method specific quotas are not yet supported. Hence method inside the API-Config-File must always be "*".

method: For now it must be "*", later options will be added to define method level quotas.
type: throttle for the number of message or throttlemb for number of Mega-Byte
period: Must be either [second|minute|hour|day|week]

Clone this wiki locally