Skip to content

Commit

Permalink
fix default tps control plugin (#11579)
Browse files Browse the repository at this point in the history
  • Loading branch information
godhth authored Jan 5, 2024
1 parent 97104b2 commit 8a69c9e
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.plugin.control.tps.barrier;

import com.alibaba.nacos.plugin.control.tps.MonitorType;
import com.alibaba.nacos.plugin.control.tps.TpsMetrics;
import com.alibaba.nacos.plugin.control.tps.request.BarrierCheckRequest;
import com.alibaba.nacos.plugin.control.tps.response.TpsCheckResponse;
Expand Down Expand Up @@ -57,9 +58,12 @@ public void reCreateRaterCounter(String name, TimeUnit period) {

@Override
public TpsCheckResponse applyTps(BarrierCheckRequest barrierCheckRequest) {

long count = rateCounter.getCount(barrierCheckRequest.getTimestamp());
long maxCount = getMaxCount();
if (MonitorType.INTERCEPT.getType().equals(getMonitorType()) && maxCount >= 0 && count >= maxCount) {
return new TpsCheckResponse(false, TpsResultCode.DENY_BY_POINT, "tps over limit :" + maxCount);
}
rateCounter.add(barrierCheckRequest.getTimestamp(), barrierCheckRequest.getCount());

return new TpsCheckResponse(true, TpsResultCode.PASS_BY_POINT, "success");
}

Expand Down Expand Up @@ -108,5 +112,4 @@ public void applyRuleDetail(RuleDetail ruleDetail) {
this.setMonitorType(ruleDetail.getMonitorType());
}
}

}

0 comments on commit 8a69c9e

Please sign in to comment.