Hi All,
With the new throttling implementation we are using CEP as the global
throttling engine.
*Implementation*
When API Request comes to the throttle handler, the relevant data is
publish to the CEP. Since all the events are publish to the super tenant
space, we are decided to add filter for execution planes based on tenant
domain. When the policy is published by a tenant, the tenant domain will be
added as a condition to filter the events for that particular tenant.
For eg : Application Level Throttle Policy for tenant(test.com) will be as
follow
@Plan:name('test.com_app_Large')@Plan:description('ExecutionPlan for
app_Large')@Import('org.wso2.throttle.processed.request.stream:1.0.0')
define stream RequestStream (messageID string, appKey string, appTier
string, subscriptionKey string, apiKey string, apiTier string,
subscriptionTier string, resourceKey string, resourceTier string,
userId string, apiContext string, apiVersion string, appTenant
string, apiTenant string, appId string, apiName string, propertiesMap
string);@Export('org.wso2.throttle.globalThrottle.stream:1.0.0')
define stream GlobalThrottleStream (throttleKey string, isThrottled bool);
FROM RequestStream
SELECT messageID, (appTenant == 'test.com' and appTier == 'Large') AS
isEligible, appKey AS throttleKey
INSERT INTO EligibilityStream;
FROM EligibilityStream[isEligible==true]#window.time(1 min)select
throttleKey, (count(messageID) >= 20) as isThrottledgroup by
throttleKey
INSERT ALL EVENTS into ResultStream;from
ResultStream#throttler:emitOnStateChange(throttleKey,
isThrottled)select *
insert into GlobalThrottleStream;
The execution plan name will be starts with ${tenantDomain} prefix with
throttle policy name. For Application level throttle policy name for tenant
will be ${tenantDomain}_app_${policyName} (eg: test.com_app_Large)
Like wise all respective tenant throttling policies will be associate with
a filter for tenant domain so that we can maintain separate policies for
each tenant.
*Throttling Levels and Tenant Filtering*
>From throttle handler, we will be publish tenant domain which belongs to
API creator(apiTenant) and the tenant domain of application creator
(appTenant)
In API Manager, we have four different of throttling levels.
- Application Level Throttle Policies : For this throttle policies,
appTenant will be added as a filter condition as the tenant admins of
application developers are creating the application level throttle
policies( eg : SELECT messageID, (appTenant == 'test.com' and appTier ==
'Large') AS isEligible)
- Subscription Level Throttle Policies : For this throttle policies
apiTenant will be added as a filter condition as the tenant admins of api
developers are creating the subscription level throttle policies (
eg : SELECT
messageID, (apiTenant == 'test.com' and subscriptionTier == 'Gold') AS
isEligible )
- Resource Level Throttle Policies : For this throttle policies
apiTenant will be added as a filter condition as the tenant admins of api
developers are creating the resource level throttle policies ( eg : SELECT
messageID, (apiTenant == 'test.com' and resourceTier == 'Ultimate') AS
isEligible )
- Custom Throttle Policies : This will only be supported for the super
tenant for this release
Policy Templates can be found in[1], [2], [3] for application, subsription
and resource level throttle policies.
Please share your thoughts and suggestions on this.
[1] -
https://github.com/harsha89/carbon-apimgt/blob/release-6.0.x/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/templates/throttle_policy_template_app.xml
[2] -
https://github.com/harsha89/carbon-apimgt/blob/release-6.0.x/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/templates/throttle_policy_template_resource.xml
[3] -
https://github.com/harsha89/carbon-apimgt/blob/release-6.0.x/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/templates/throttle_policy_template_resource_default.xml
Thanks,
Harsha
--
Harsha Kumara
Software Engineer, WSO2 Inc.
Mobile: +94775505618
Blog:harshcreationz.blogspot.com
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture