alibaba/Sentinel

Duplicate inbound QPS in some adapters | 入口QPS 重复统计问题

Open

#2,931 opened on Nov 1, 2022

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Java (23,109 stars) (8,150 forks)batch import
area/metricshelp wanted

Description

Issue Description

我这边使用的sentinel 的版本是:1.8.1

系统规则里面有一个入口QPS 统计,并可以对它进行限流。 对于我使用的版本 中如果我有多个资源在API 中定义,这些定义的资源名称对某一个相同的API 的匹配结果都为TRUE的时候。 全局统计(Constants.ENTRY_NODE) 将对该API 的一次请求重复计数。最终导致的结果是这一次请求被认为是多次QPS,与正常逻辑相违背。

Type: bug report or feature request 我认为它是一个BUG。我们应该将这些去重,但感觉这个问题似乎不是那么好处理。 除了http 请求的API 以外,其他的资源(使用注解定义的)应该也有这种重复的问题,这种重复就更难处理了吧。 参考:com.alibaba.csp.sentinel.Constants#ENTRY_NODE

关键代码片段

@Spi(order = Constants.ORDER_STATISTIC_SLOT)
public class StatisticSlot extends AbstractLinkedProcessorSlot<DefaultNode> {

    @Override
    public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count,
                      boolean prioritized, Object... args) throws Throwable {
            ... 
            if (resourceWrapper.getEntryType() == EntryType.IN) {
                // Add count for global inbound entry node for global statistics.
                Constants.ENTRY_NODE.increaseThreadNum();
                Constants.ENTRY_NODE.addPassRequest(count);
            }
            ... 
    }
}

com.alibaba.csp.sentinel.slots.system.SystemRuleManager#checkSystem


public final class SystemRuleManager {

    public static void checkSystem(ResourceWrapper resourceWrapper) throws BlockException {
        ...

        // total qps
        double currentQps = Constants.ENTRY_NODE == null ? 0.0 : Constants.ENTRY_NODE.successQps();
        if (currentQps > qps) {
            throw new SystemBlockException(resourceWrapper.getName(), "qps");
        }

        ...
    }
}

Describe what happened (or what feature you want)

Describe what you expected to happen

How to reproduce it (as minimally and precisely as possible)

Tell us your environment

Anything else we need to know?

Contributor guide

Duplicate inbound QPS in some adapters | 入口QPS 重复统计问题 · alibaba/Sentinel#2931 | Good First Issue