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

默认的反脆弱插件存在优化点 #11626

Closed
floor07 opened this issue Jan 10, 2024 · 2 comments
Closed

默认的反脆弱插件存在优化点 #11626

floor07 opened this issue Jan 10, 2024 · 2 comments
Assignees
Labels

Comments

@floor07
Copy link
Contributor

floor07 commented Jan 10, 2024

public LocalSimpleCountRateCounter(String name, TimeUnit period) {
    super(name, period);
    slotList = new ArrayList<>(DEFAULT_RECORD_SIZE);
    for (int i = 0; i < DEFAULT_RECORD_SIZE; i++) {
        slotList.add(new TpsSlot());
    }
    long now = System.currentTimeMillis();
    
    if (period == TimeUnit.SECONDS) {
        startTime = RateCounter.getTrimMillsOfSecond(now);
    } else if (period == TimeUnit.MINUTES) {
        startTime = RateCounter.getTrimMillsOfMinute(now);
    } else if (period == TimeUnit.HOURS) {
        startTime = RateCounter.getTrimMillsOfHour(now);
    } else {
        //有bug
        getTrimMillsOfSecond(now);
    }
}

除了这里还有:SlotCountHolder 中的interceptedCount 总是0

static class SlotCountHolder {

    AtomicLong count = new AtomicLong();
    
    AtomicLong interceptedCount = new AtomicLong();
    
    @Override
    public String toString() {
        return "{" + count + "|" + interceptedCount + '}';
    }
}

注:
SimpleCountRuleBarrier并没有处理interceptedCount
@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");
}

@floor07 floor07 changed the title LocalSimpleCountRateCounter 没有给startTime赋值 反脆弱插件存在问题 Jan 10, 2024
@floor07 floor07 changed the title 反脆弱插件存在问题 默认的反脆弱插件存在问题 Jan 10, 2024
@floor07 floor07 changed the title 默认的反脆弱插件存在问题 默认的反脆弱插件存在优化点 Jan 10, 2024
@floor07
Copy link
Contributor Author

floor07 commented Jan 10, 2024

#11625

@floor07
Copy link
Contributor Author

floor07 commented Jan 10, 2024

@i will solve it@

KomachiSion pushed a commit that referenced this issue Feb 22, 2024
* Update LocalSimpleCountRateCounter.java

fixbug

* Update LocalSimpleCountRateCounter.java

bugfix

* fix:默认的nacos反脆弱插件的问题

* fix:默认的nacos反脆弱插件的问题

* fix:默认的nacos反脆弱插件的问题

* fix:默认的nacos反脆弱插件的问题

* fix:默认的nacos反脆弱插件的问题,调整为tryAdd

* fix:默认的nacos反脆弱插件的问题,调整为tryAdd

* 调整测试方式,保障流水线成功
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants