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

fix: cluster token checker #3407

Open
wants to merge 1 commit into
base: 1.8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ static TokenResult acquireClusterToken(/*@Valid*/ FlowRule rule, int acquireCoun
return new TokenResult(TokenResultStatus.FAIL);
}

double latestQps = metric.getAvg(ClusterFlowEvent.PASS);
double latestSum = metric.getSum(ClusterFlowEvent.PASS);
double globalThreshold = calcGlobalThreshold(rule) * ClusterServerConfigManager.getExceedCount();
double nextRemaining = globalThreshold - latestQps - acquireCount;
double nextRemaining = globalThreshold - latestSum - acquireCount;

if (nextRemaining >= 0) {
// TODO: checking logic and metric operation should be separated.
Expand All @@ -83,8 +83,8 @@ static TokenResult acquireClusterToken(/*@Valid*/ FlowRule rule, int acquireCoun
} else {
if (prioritized) {
// Try to occupy incoming buckets.
double occupyAvg = metric.getAvg(ClusterFlowEvent.WAITING);
if (occupyAvg <= ClusterServerConfigManager.getMaxOccupyRatio() * globalThreshold) {
double occupySum = metric.getSum(ClusterFlowEvent.WAITING);
if (occupySum <= ClusterServerConfigManager.getMaxOccupyRatio() * globalThreshold) {
int waitInMs = metric.tryOccupyNext(ClusterFlowEvent.PASS, acquireCount, globalThreshold);
// waitInMs > 0 indicates pre-occupy incoming buckets successfully.
if (waitInMs > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ static TokenResult acquireClusterToken(ParamFlowRule rule, int count, Collection
boolean hasPassed = true;
Object blockObject = null;
for (Object value : values) {
double latestQps = metric.getAvg(value);
double latestSum = metric.getSum(value);
double threshold = calcGlobalThreshold(rule, value);
double nextRemaining = threshold - latestQps - count;
double nextRemaining = threshold - latestSum - count;
remaining = nextRemaining;
if (nextRemaining < 0) {
hasPassed = false;
Expand Down