Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add Burst control capability for Applications #12162

Merged
merged 16 commits into from
Jan 5, 2024

Conversation

shilmyhasan
Copy link
Contributor

@shilmyhasan shilmyhasan commented Sep 24, 2023

The PR adds the capability to support burst control for Application policies similar to what the product already has for Subscription policies.

@@ -627,6 +638,15 @@ private boolean doThrottle(MessageContext messageContext) {
initThrottleForSubscriptionLevelSpikeArrest(messageContext, authenticationContext);
context.stop();
}

if(authenticationContext != null && authenticationContext.getApplicationSpikesArrestLimit() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in b56bf30

try {
parsedPolicy = AXIOMUtil.stringToOM(policy.toString());
} catch (XMLStreamException e) {
log.error("Error occurred while creating policy file for Hard Throttling.", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a reason why this exception is ignored (without throwing an exception and stopping the flow)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in b56bf30

String applicationLevelThrottleKey = authenticationContext.getApplicationId()+":"+authenticationContext.getUsername();
int maxRequestCount = authenticationContext.getApplicationSpikesArrestLimit();
int applicationSpikeArrestWindowUnitTime = 0;
if(maxRequestCount != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in b56bf30

private void initThrottleForApplicationLevelSpikeArrest(MessageContext synCtx,
AuthenticationContext authenticationContext) {
policyKeyApplication = authenticationContext.getApplicationTier();
String applicationLevelThrottleKey = authenticationContext.getApplicationId()+":"+authenticationContext.getUsername();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in b56bf30

}

private void setRateLimitDetails(ApplicationPolicy policy, ResultSet resultSet) throws SQLException {
if(resultSet.getInt(ThrottlePolicyConstants.COLUMN_RATE_LIMIT_COUNT) > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in b56bf30

@@ -180,6 +180,25 @@ public void setConsumerKey(String consumerKey) {
this.consumerKey = consumerKey;
}

private int applicationSpikesArrestLimit;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add the variables along with the other variables on the top?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored in 547e395

import org.wso2.carbon.apimgt.internal.service.dto.SubscriptionPolicyListDTO;
import org.wso2.carbon.apimgt.internal.service.dto.ThrottleLimitDTO;
import org.wso2.carbon.apimgt.internal.service.dto.URLMappingDTO;
import org.wso2.carbon.apimgt.internal.service.dto.*;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the import into individual

tharindu1st
tharindu1st previously approved these changes Dec 14, 2023
chamilaadhi
chamilaadhi previously approved these changes Dec 14, 2023
@CLAassistant
Copy link

CLAassistant commented Dec 14, 2023

CLA assistant check
All committers have signed the CLA.

@shilmyhasan shilmyhasan merged commit cf0537f into wso2:master Jan 5, 2024
3 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants