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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package org.wso2.carbon.apimgt.api.model.policy;

public class ApplicationPolicy extends Policy {
private int rateLimitCount;
private String rateLimitTimeUnit;
private int applicationId;

private byte[] customAttributes;
Expand All @@ -43,10 +45,24 @@
this.customAttributes = customAttributes;
}

public String getRateLimitTimeUnit() {
return rateLimitTimeUnit;

Check warning on line 49 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/ApplicationPolicy.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/ApplicationPolicy.java#L49

Added line #L49 was not covered by tests
}
public void setRateLimitTimeUnit(String rateLimitTimeUnit) {
this.rateLimitTimeUnit = rateLimitTimeUnit;
}

Check warning on line 53 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/ApplicationPolicy.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/ApplicationPolicy.java#L52-L53

Added lines #L52 - L53 were not covered by tests
public int getRateLimitCount() {
return rateLimitCount;

Check warning on line 55 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/ApplicationPolicy.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/ApplicationPolicy.java#L55

Added line #L55 was not covered by tests
}
public void setRateLimitCount(int rateLimitCount) {
this.rateLimitCount = rateLimitCount;
}

Check warning on line 59 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/ApplicationPolicy.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/ApplicationPolicy.java#L58-L59

Added lines #L58 - L59 were not covered by tests

@Override
public String toString() {
return "ApplicationPolicy [policyName=" + getPolicyName()
+ ", applicationId =" + applicationId + ", description=" + getDescription() + ", defaultQuotaPolicy="
+ getDefaultQuotaPolicy() + "]";
+ getDefaultQuotaPolicy() + ", rateLimitCount=" + getRateLimitCount() + ", rateLimitTimeUnit="
+ getRateLimitTimeUnit() + "]";

Check warning on line 66 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/ApplicationPolicy.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/ApplicationPolicy.java#L65-L66

Added lines #L65 - L66 were not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,28 @@
*/
public class ApplicationPolicy extends Policy {

private int rateLimitCount = -1;
private String rateLimitTimeUnit = null;

Check warning on line 27 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/subscription/ApplicationPolicy.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/subscription/ApplicationPolicy.java#L26-L27

Added lines #L26 - L27 were not covered by tests

@Override
public String getCacheKey() {

return POLICY_TYPE.APPLICATION + DELEM_PERIOD + super.getCacheKey();
}

public String getRateLimitTimeUnit() {
return rateLimitTimeUnit;

Check warning on line 36 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/subscription/ApplicationPolicy.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/subscription/ApplicationPolicy.java#L36

Added line #L36 was not covered by tests
}

public void setRateLimitTimeUnit(String rateLimitTimeUnit) {
this.rateLimitTimeUnit = rateLimitTimeUnit;
}

Check warning on line 41 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/subscription/ApplicationPolicy.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/subscription/ApplicationPolicy.java#L40-L41

Added lines #L40 - L41 were not covered by tests

public int getRateLimitCount() {
return rateLimitCount;

Check warning on line 44 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/subscription/ApplicationPolicy.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/subscription/ApplicationPolicy.java#L44

Added line #L44 was not covered by tests
}

public void setRateLimitCount(int rateLimitCount) {
this.rateLimitCount = rateLimitCount;
}

Check warning on line 49 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/subscription/ApplicationPolicy.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/subscription/ApplicationPolicy.java#L48-L49

Added lines #L48 - L49 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public enum Throttling implements FaultSubCategory {
BLOCKED,
CUSTOM_POLICY_LIMIT_EXCEEDED,
BURST_CONTROL_LIMIT_EXCEEDED,
APPLICATION_BURST_CONTROL_LIMIT_EXCEEDED,
QUERY_TOO_DEEP,
QUERY_TOO_COMPLEX,
OTHER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
return FaultSubCategories.Throttling.CUSTOM_POLICY_LIMIT_EXCEEDED;
case APIThrottleConstants.SUBSCRIPTION_BURST_THROTTLE_OUT_ERROR_CODE:
return FaultSubCategories.Throttling.BURST_CONTROL_LIMIT_EXCEEDED;
case APIThrottleConstants.APPLICATION_BURST_THROTTLE_OUT_ERROR_CODE:
return FaultSubCategories.Throttling.APPLICATION_BURST_CONTROL_LIMIT_EXCEEDED;

Check warning on line 113 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/analytics/FaultCodeClassifier.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/analytics/FaultCodeClassifier.java#L113

Added line #L113 was not covered by tests
case APIThrottleConstants.GRAPHQL_QUERY_TOO_DEEP:
case WebSocketApiConstants.FrameErrorConstants.GRAPHQL_QUERY_TOO_DEEP:
return FaultSubCategories.Throttling.QUERY_TOO_DEEP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
private String subscriber;
private List<String> throttlingDataList;
private int spikeArrestLimit;
private int applicationSpikesArrestLimit;
private String subscriberTenantDomain;
private String spikeArrestUnit;
private boolean stopOnQuotaReach;
Expand Down Expand Up @@ -180,6 +181,23 @@
this.consumerKey = consumerKey;
}

public String getApplicationSpikesArrestUnit() {
return applicationSpikesArrestUnit;

Check warning on line 185 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/AuthenticationContext.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/AuthenticationContext.java#L185

Added line #L185 was not covered by tests
}

public void setApplicationSpikesArrestUnit(String applicationSpikesArrestUnit) {
this.applicationSpikesArrestUnit = applicationSpikesArrestUnit;
}

private String applicationSpikesArrestUnit;

public int getApplicationSpikesArrestLimit(){
return applicationSpikesArrestLimit;
}
public void setApplicationSpikesArrestLimit(int applicationSpikesArrestLimit) {
this.applicationSpikesArrestLimit = applicationSpikesArrestLimit;
}

public int getSpikeArrestLimit() {
return spikeArrestLimit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@
authContext.setSubscriberTenantDomain(info.getSubscriberTenantDomain());
authContext.setSpikeArrestLimit(info.getSpikeArrestLimit());
authContext.setSpikeArrestUnit(info.getSpikeArrestUnit());
authContext.setApplicationSpikesArrestLimit(info.getApplicationSpikeArrestLimit());
authContext.setApplicationSpikesArrestUnit(info.getApplicationSpikeArrestUnit());

Check warning on line 356 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/oauth/OAuthAuthenticator.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/oauth/OAuthAuthenticator.java#L355-L356

Added lines #L355 - L356 were not covered by tests
authContext.setStopOnQuotaReach(info.isStopOnQuotaReach());
authContext.setIsContentAware(info.isContentAware());
APISecurityUtils.setAuthenticationContext(synCtx, authContext, securityContextHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class APIThrottleConstants {
public static final int APPLICATION_THROTTLE_OUT_ERROR_CODE = 900803;
public static final int SUBSCRIPTION_THROTTLE_OUT_ERROR_CODE = 900804;
public static final int SUBSCRIPTION_BURST_THROTTLE_OUT_ERROR_CODE = 900807;
public static final int APPLICATION_BURST_THROTTLE_OUT_ERROR_CODE = 900809;
public static final int BLOCKED_ERROR_CODE = 900805;
public static final int CUSTOM_POLICY_THROTTLE_OUT_ERROR_CODE = 900806;
public static final int CONNECTIONS_COUNT_THROTTLE_OUT_ERROR_CODE = 900808;
Expand All @@ -47,6 +48,8 @@ public class APIThrottleConstants {
public static final String HARD_THROTTLING_CONFIGURATION = "hard_throttling_limits";
public static final String PRODUCTION_HARD_LIMIT = "PRODUCTION_HARD_LIMIT";
public static final String SUBSCRIPTION_BURST_LIMIT = "SUBSCRIPTION_BURST_LIMIT";
public static final String APPLICATION_BURST_LIMIT = "APPLICATION_BURST_LIMIT";
public static final String APPLICATION_BURST_LIMIT_EXCEEDED = "APPLICATION_BURST_LIMIT_EXCEED";
public static final String SANDBOX_HARD_LIMIT = "SANDBOX_HARD_LIMIT";
public static final String THROTTLED_OUT_REASON = APIConstants.THROTTLE_OUT_REASON_KEY;
public static final String THROTTLED_NEXT_ACCESS_TIMESTAMP = "NEXT_ACCESS_TIME";
Expand Down
Loading
Loading