alibaba / alibaba/Sentinel

[BUG] Nacos发布流控规则无法到Sentinel Dashboard

Open
#3,442 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

## Issue Description

Type: *bug report*

### Describe what happened
# 【Bug】Nacos发布流控规则无法到Sentinel Dashboard

> 版本说明:nacos=2.4.0、Sentinel Dashborad=1.8.8、spring.cloud.alibaba.version=2023.0.1.2

## 依赖

```xml

com.alibaba.cloud
spring-cloud-alibaba-sentinel-gateway

com.alibaba.csp
sentinel-datasource-nacos

```

## 配置

```yaml
spring:
cloud:
nacos:
server-addr: # Nacos 服务器地址
username: # Nacos用户名
password: # Nacos密码
discovery: # 【配置中心】配置项
namespace: dev # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
config: # 【注册中心】配置项
namespace: dev # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
sentinel:
datasource:
r1:
nacos:
username: # Nacos用户名
password: # Nacos密码
namespace: dev
# nacos地址
server-addr: # Nacos 服务器地址
# nacos中配置文件的data-id
data-id: ${spring.application.name}-sentinel
# nacos 分组
group-id: DEFAULT_GROUP
# 规则类型 流控
rule-type: flow
transport:
dashboard: 127.0.0.1:8080
client-ip: 127.0.0.1
```

## nacos配置流控

由于微服务创建的时候是用的是`dev`命名空间,因此需要在`dev`命名空间中创建配置。

```json
[
{
"resource": "system-admin-api",
"resourceMode": 0,
"count": 10,
"grade": 1,
"controlBehavior": 0,
"intervalSec": 10,
"burst": 0,
"maxQueueingTimeoutMs": 1000
}
]
```

image-20240823110214338
image-20240823110601723
此时可以看到我们设置的QPS是10,然后启动Sentinel Dashboard、网关和相应的业务微服务。

访问system-admin-api服务,可以看到QPS设置为10时访问没问题。

image-20240823111259823
修改Nacos配置进行限流(修改count为2)

image-20240823111430213
查看sentinel的record日志可以看到已经修改成功。

image-20240823111604519

测试后可以发现已经生效,1s内如果发送三个请求会被拦截一个。

image-20240823111854845
但是Sentinel Dashboard并未显示对应的值。

image-20240823112005888
## Sentinel Dashboard配置流控

### 情况一

在上面的情况中我们直接添加流控规则,将QPS的阈值设置为10。

image-20240823112259985
可以看到并未生效

image-20240823112409493
但是Dashboard控制台显示修改成功。

image-20240823112548749

### 情况二

重启网关和其他服务,先从dashboard配置再从nacos配置

此时nacos中的配置如下

```json
[
{
"resource": "system-admin-api",
"resourceMode": 0,
"count": 2,
"grade": 1,
"controlBehavior": 0,
"intervalSec": 10,
"burst": 0,
"maxQueueingTimeoutMs": 1000
}
]
```

dashboard的流控规则界面如下,由于是从内存中读取,每次的流控规则需要重新配置。

image-20240823112842025
但是从实时监控的面板上可以看到nacos中的配置已经生效了

image-20240823112958524
此时通过dashboard配置流控规则将QPS设置为1。

image-20240823113314096
可以看到已经生效

image-20240823113406477
然后再去nacos发布如下配置

image-20240823113444349
在sentinel record日志中可以看到已经更新了

image-20240823113542232
但是实际测试中显示更新失败

image-20240823113653367
同时dashboard中显示的流控规则的QPS没有改变。

image-20240823113717103

### Describe what you expected to happen

Nacos发布流控规则能够同步到Sentinel Dashboard

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

1.
2.
3.

### Tell us your environment

版本说明:nacos=2.4.0、Sentinel Dashborad=1.8.8、spring.cloud.alibaba.version=2023.0.1.2

### Anything else we need to know?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.