alibaba / alibaba/Sentinel

Can servlet filter(CommonFilter) support ParamFlow?

Open
#2,014 4 comments 0 reactions 0 assignees View on GitHub
area/hotspot-param-flow kind/discussion kind/feature
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

## Issue Description

Type: *feature request*

### Describe what happened (or what feature you want)
Can servlet filter support ParamFlow?
Servlet filter模式的限流(com.alibaba.csp.sentinel.adapter.servlet.CommonFilter)可以支持热点参数限流吗?

### Describe what you expected to happen
ParamFlow is supported in servlet filter mode.
热点参数限流可以在servlet限流模式中被支持。

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

1. Define a GET method by springMVC
使用springMVC定义一个GET方法
`
@GetMapping("param")
public String testParam(Integer param) {
LOGGER.info("Dubbo request succeed. param is [{}]", param);
return "Dubbo request succeed.";
}
`
2. Configure a param flow rule
如下所示,配置一条热点参数限流规则
`
[
{
"resource": "/param",
"limitApp": "default",
"grade": 1,
"paramIdx": 0,
"count": 1,
"controlBehavior": 0,
"maxQueueingTimeMs": 0,
"burstCount": 0,
"durationInSec": 1,
"paramFlowItemList": [
{
"object": "1",
"count": 2,
"classType": "int"
}
],
"clusterMode": false
}
]
`
3. Send a request '/param'
发送’param‘的http请求
4. The result is that the param flow rule is not activated.
结果是热点参数限流规则没有生效。
5. I found out the reason is that the com.alibaba.csp.sentinel.adapter.servlet.CommonFilter does not carry the arguments when it invoke com.alibaba.csp.sentinel.SphU#entry(java.lang.String, int, com.alibaba.csp.sentinel.EntryType)。
初步分析,原因是CommonFilter这个类调用SphU#entry方法时,没有传入参数列表。
6. If I define the get method like this , the param rule will be activated, because com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect carries the arguments.
如果使用@SentinelResource来做资源定义,热点参数限流规则可以生效。

@SentinelResource(value = "/param")
public String testParam(Integer param) {
LOGGER.info("Dubbo request succeed. param is [{}]", param);
return "Dubbo request succeed.";
}

### Tell us your environment
mac,sentinel-1.8.0

### Anything else we need to know?
No more.

Contributor guide

Open the contributing guide

Research direction

Start with com.alibaba.csp.sentinel.adapter.servlet.CommonFilter and inspect its call to com.alibaba.csp.sentinel.SphU#entry(java.lang.String, int, com.alibaba.csp.sentinel.EntryType); compare it with com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect, which carries method arguments. Done means the shown servlet-filter GET request activates the configured ParamFlow rule, as the annotated method does.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.