alibaba / alibaba/Sentinel

spring cloud gateway 整合 sentinel 限流不生效

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

Description

## Issue Description

## version

spring cloud gateway 2.2.5.RELEASE
cloud Hoxton.SR8
spring boot 2.3.12

## dependencies

```xml

com.alibaba.cloud
spring-cloud-starter-alibaba-sentinel
provided

com.alibaba.csp
sentinel-core
1.8.0

com.alibaba.csp
sentinel-core
${sentinel.version}


com.alibaba.csp
sentinel-transport-simple-http
${sentinel.version}


com.alibaba.csp
sentinel-datasource-extension
${sentinel.version}


com.alibaba.csp
sentinel-datasource-nacos
${sentinel.version}


com.alibaba.csp
sentinel-parameter-flow-control
${sentinel.version}


com.alibaba.csp
sentinel-transport-common
${sentinel.version}


com.alibaba.csp
sentinel-spring-cloud-gateway-adapter
${sentinel.version}


com.alibaba.csp
sentinel-spring-webflux-adapter
${sentinel.version}

```

### Describe what happened (or what feature you want)
1、我在dashboard上保存流控规则后持久化后至nacos

![image](https://user-images.githubusercontent.com/10337065/124536236-33076180-de4a-11eb-984b-e8e852a74f55.png)

2、gateway 监听nacos规则发生变化后
GatewayRuleManager.loadRules 去加载了规则,但是访问资源时规制并没有生效
```java
case GATEWAY_API:
GatewayApiDefinitionManager.loadApiDefinitions(sentinelGatewayApiParser.convert(sentinelStrategyRule));
break;
case GATEWAY_FLOW:
GatewayRuleManager.loadRules(sentinelGatewayFlowRuleParser.convert(sentinelStrategyRule));
break;
```

### 结果限流并不生效,请问如何解决

### SentinelGatewayFilter routeId 会自动加上前缀,访问API时直接报404
![image](https://user-images.githubusercontent.com/10337065/124537209-07857680-de4c-11eb-8a30-a523fe206cbb.png)
![image](https://user-images.githubusercontent.com/10337065/124537243-1c620a00-de4c-11eb-9d94-9a1b24cfc361.png)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported behavior with Spring Cloud Gateway 2.2.5.RELEASE, Spring Boot 2.3.12, and the listed Sentinel dependencies. Read the GatewayRuleManager.loadRules path and SentinelGatewayFilter behavior, especially the routeId handling. Done means persisted rules take effect for gateway requests and valid API routes do not return 404.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.