support rejecting all requests by ratelimit

This commit is contained in:
Francis Dong
2023-06-28 16:57:50 +08:00
parent 1084c47743
commit d17a13b184

View File

@@ -161,10 +161,10 @@ public class FlowStat {
for (ResourceConfig resourceConfig : resourceConfigs) { for (ResourceConfig resourceConfig : resourceConfigs) {
long maxCon = resourceConfig.getMaxCon(); long maxCon = resourceConfig.getMaxCon();
long maxQPS = resourceConfig.getMaxQPS(); long maxQPS = resourceConfig.getMaxQPS();
if (maxCon > 0 || maxQPS > 0) { if (maxCon >= 0 || maxQPS >= 0) {
ResourceStat resourceStat = getResourceStat(resourceConfig.getResourceId()); ResourceStat resourceStat = getResourceStat(resourceConfig.getResourceId());
// check concurrent request // check concurrent request
if (maxCon > 0) { if (maxCon >= 0) {
long n = resourceStat.getConcurrentRequests().get(); long n = resourceStat.getConcurrentRequests().get();
if (n >= maxCon) { if (n >= maxCon) {
resourceStat.incrBlockRequestToTimeSlot(curTimeSlotId); resourceStat.incrBlockRequestToTimeSlot(curTimeSlotId);
@@ -184,7 +184,7 @@ public class FlowStat {
} }
// check QPS // check QPS
if (maxQPS > 0) { if (maxQPS >= 0) {
long total = resourceStat.getTimeSlot(curTimeSlotId).getCounter(); long total = resourceStat.getTimeSlot(curTimeSlotId).getCounter();
if (total >= maxQPS) { if (total >= maxQPS) {
resourceStat.incrBlockRequestToTimeSlot(curTimeSlotId); resourceStat.incrBlockRequestToTimeSlot(curTimeSlotId);