MappedThrottlingPolicy
Maps different throttling rates to different groups of requests, according to the evaluation of throttlingRateMapper
.
Usage
{ "type": "ThrottlingFilter", "config": { "requestGroupingPolicy": expression, "throttlingRatePolicy": { "type": "MappedThrottlingPolicy", "config": { "throttlingRateMapper": runtime expression<string>, "throttlingRatesMapping": { "mapping1": { "numberOfRequests": integer, "duration": duration string }, "mapping2": { "numberOfRequests": integer, "duration": duration string } }, "defaultRate": { "numberOfRequests": integer, "duration": duration string } } } } }
Properties
"throttlingRateMapper"
: runtime expression<string>, requiredAn expression to categorize requests for mapping to a throttling rate in the
throttlingRatesMapping
.If this parameter is null or does not match any specified mappings, the default throttling rate is applied.
"throttlingRatesMapping"
: object, requiredA map of throttling rate by request group. Requests are categorized into groups by the evaluation of the expression
"throttlingRateMapper"
."mapping1"
and"mapping2"
: string, requiredThe evaluation of the expression
"throttlingRateMapper"
.The number of mappings is not limited to two.
"numberOfRequests"
: integer, requiredThe number of requests allowed through the filter in the time specified by
"duration"
."duration"
: duration string, requiredA time interval during which the number of requests passing through the filter is counted.
For information about supported formats for
duration
, see duration.
"defaultRate"
: object, requiredThe default throttling rate to apply if the evaluation of the expression
"throttlingRateMapper"
is null or is not mapped to a throttling rate."numberOfRequests"
: integer, requiredThe number of requests allowed through the filter in the time specified by
"duration"
."duration"
: duration string, requiredA time interval during which the number of requests passing through the filter is counted.
For information about supported formats for
duration
, see duration.
Example of a Mapped Throttling Policy
In the following example, requests from users with different statuses are mapped to different throttling rates. For information about how to set up and test this example, see "Configuring Mapped Throttling".
{ "name": "00-throttle-mapped", "baseURI": "http://app.example.com:8081", "condition": "${matches(request.uri.path, '^/home/throttle-mapped')}", "heap": [ { "name": "SystemAndEnvSecretStore-1", "type": "SystemAndEnvSecretStore" }, { "name": "AmService-1", "type": "AmService", "config": { "agent": { "username": "ig_agent", "passwordSecretId": "agent.secret.id" }, "secretsProvider": "SystemAndEnvSecretStore-1", "url": "http://openam.example.com:8088/openam/", "version": "7" } } ], "handler": { "type": "Chain", "config": { "filters": [ { "name": "OAuth2ResourceServerFilter-1", "type": "OAuth2ResourceServerFilter", "config": { "scopes": [ "mail", "employeenumber" ], "requireHttps": false, "realm": "OpenIG", "accessTokenResolver": { "name": "token-resolver-1", "type": "TokenIntrospectionAccessTokenResolver", "config": { "amService": "AmService-1", "providerHandler": { "type": "Chain", "config": { "filters": [ { "type": "HttpBasicAuthenticationClientFilter", "config": { "username": "ig_agent", "passwordSecretId": "agent.secret.id", "secretsProvider": "SystemAndEnvSecretStore-1" } } ], "handler": "ForgeRockClientHandler" } } } } } }, { "name": "ThrottlingFilter-1", "type": "ThrottlingFilter", "config": { "requestGroupingPolicy": "${contexts.oauth2.accessToken.info.mail}", "throttlingRatePolicy": { "name": "MappedPolicy", "type": "MappedThrottlingPolicy", "config": { "throttlingRateMapper": "${contexts.oauth2.accessToken.info.status}", "throttlingRatesMapping": { "gold": { "numberOfRequests": 6, "duration": "10 s" }, "silver": { "numberOfRequests": 3, "duration": "10 s" }, "bronze": { "numberOfRequests": 1, "duration": "10 s" } }, "defaultRate": { "numberOfRequests": 1, "duration": "10 s" } } } } } ], "handler": "ReverseProxyHandler" } } }
More Information
org.forgerock.openig.filter.throttling.MappedThrottlingPolicyHeaplet