Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sentinel 无法解析nacos上的文件 #315

Closed
naturalyui opened this issue Jan 23, 2019 · 4 comments
Closed

sentinel 无法解析nacos上的文件 #315

naturalyui opened this issue Jan 23, 2019 · 4 comments
Labels
area/sentinel spring cloud alibaba sentinel

Comments

@naturalyui
Copy link

sentinel-server是1.4.0版本和客户端的一致,
不知道为什么通过nacos触发就转换不了,也看不到具体异常
image
我将这部分代码单独抽出来请求是可以正常转换的
image

目前测试了一下只有这种格式可以被正常转换
image

但是从sentinel那边传过来的格式并不是这样的,需要我自己去过滤格式

@fangjian0423
Copy link
Contributor

转换不了指的是转换失败还是成功了但是规则没有生效。

可以详细说一下要转换什么类型的规则,规则的 json 以及 application.properties 配置文件信息等内容。

@naturalyui
Copy link
Author

很抱歉回复晚了

我的环境:nacos在远端服务器,sentinel控制台和客户端都在本地

1、转换不了指的是nacos接收到了sentinel控制台发来限流规则的json,但sentinel客户端却认为是无效的的格式
2、以下是打印的日志及我sentinel客户端的bootstrap.properties配置文件
日志:
Sentinel JsonConverter can not convert {"app":"fool-zuul","gmtModified":1548291859739,"resource":"/auth/oauth/token","grade":1,"controlBehavior":0,"count":2.0,"id":1,"limitApp":"default","strategy":0,"clusterMode":false} to any rules, ignore

Sentinel JsonConverter Source list size is not equals to Target List, maybe a part of json is invalid. Source List: [{app=fool-zuul, gmtModified=1548291859739, resource=/auth/oauth/token, grade=1, controlBehavior=0, count=2.0, id=1, limitApp=default, strategy=0, clusterMode=false}], Target List: []

配置:
spring.cloud.sentinel.datasource.fool-zuul-flow.nacos.server-addr=${nacos.config.server-addr}
spring.cloud.sentinel.datasource.fool-zuul-flow.nacos.dataId=${spring.application.name}-flow-rules
spring.cloud.sentinel.datasource.fool-zuul-flow.nacos.groupId=fool-monitor
spring.cloud.sentinel.datasource.fool-zuul-flow.nacos.data-type=json

@fangjian0423
Copy link
Contributor

Hi @naturalyui ,感谢关注 Spring Cloud Alibaba.

Sentinel Starter 里的 JsonConverter 内部的 ObjectMapper 的 DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES 特性为 true,json 中的 app、id、gmtModified 这 3 个字段在对应的规则 com.alibaba.csp.sentinel.slots.block.flow.FlowRule 无法被识别,所以导致转换出错,去掉这 3 个字段即可。

目前最新的 0.2.1.RELEASE 版本中会对规则进行自动解析,判断 json 属于哪种规则,这种模式在某些情况下会存在 bug。

所以下个版本中去除了自动解析的方式,添加了一个新的字段 rule-type,表示是哪种规则。在最新的 sentinel-core-example 中有了例子。

@naturalyui
Copy link
Author

十分感谢解答!

@fangjian0423 fangjian0423 added the area/sentinel spring cloud alibaba sentinel label Mar 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/sentinel spring cloud alibaba sentinel
Projects
None yet
Development

No branches or pull requests

2 participants