alibaba / alibaba/Sentinel

sentinel 1.8.0集成 zuul 1.x, API限流 servletPath匹配问题

Open
#1,886 2 comments 0 reactions 0 assignees View on GitHub
area/gateway-flow-control area/integrations
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

## Issue Description
zuul下面挂了多个子系统,各个子系统通过routeId做区分;想通过sentinel对各个子系统不同访问路劲进行限流控制;配置如下:
`private void initCustomizedApis() {
Set apiDefinitions = new HashSet<>();
ApiDefinition userQuery = new ApiDefinition();
userQuery.setApiName("user_query");
Set apiPaths = new HashSet<>();
userQuery.setPredicateItems(apiPaths);

ApiPathPredicateItem api = new ApiPathPredicateItem();
api.setPattern("/zuul/member/query/user");
api.setMatchStrategy(SentinelGatewayConstants.URL_MATCH_STRATEGY_EXACT);
apiPaths.add(api);

apiDefinitions.add(userQuery);
GatewayApiDefinitionManager.loadApiDefinitions(apiDefinitions);
}
`
`private void initGatewayRules() {
Set myRules = new HashSet<>();

GatewayFlowRule userQuery = new GatewayFlowRule();
userQuery.setResourceMode(SentinelGatewayConstants.RESOURCE_MODE_CUSTOM_API_NAME)
.setResource("user_query")
.setCount(2)
.setGrade(RuleConstant.FLOW_GRADE_QPS);

// 添加到规则列表
myRules.add(userQuery);

// 手动加载
GatewayRuleManager.loadRules(myRules);
}`

调试了一下,发现都是通过servletpath去匹配请求路劲,而我的servlet path是 /zuul,每次都是固定的;请问下,你们这个demo是怎么测试通过的?
‘public static Predicate exactPath(final String path) {
return new Predicate() {
@Override
public boolean test(RequestContext exchange) {
return exchange.getRequest().getServletPath().equals(path);
}
};
}’

exchange.getRequest().getServletPath()固定返回都是 '/zuul'
path: 是我自定义的url路劲

Type: *bug report* or *feature request*

### Describe what happened (or what feature you want)

### Describe what you expected to happen

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

1.
2.
3.

### Tell us your environment

### Anything else we need to know?

Contributor guide

Open the contributing guide

Research direction

Start with the shown exactPath predicate and the gateway API-definition and flow-rule setup, then reproduce the request through Zuul with the `/zuul` servlet path. Trace which request path the matcher receives and verify that the configured custom API is matched for the intended route; done means the rule distinguishes the subsystem URL rather than only the fixed servlet path.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.