携程的Apollo被用作存储,我在Apollo中配置了三条规则,如下所示:
"FlowRules": [ { "controlBehavior": 0, "count": 1.0, "grade": 1, "limitApp": "default", "maxQueueingTimeMs": 500, "refResource": null, "resource": "/p1", "strategy": 0, "warmUpPeriodSec": 10 }, { "controlBehavior": 0, "count": 1.0, "grade": 1, "limitApp": "default", "maxQueueingTimeMs": 500, "refResource": null, "resource": "/p", "strategy": 0, "warmUpPeriodSec": 10 }, { "controlBehavior": 0, "count": 1.0, "grade": 1, "limitApp": "default", "maxQueueingTimeMs": 500, "refResource": null, "resource": "testresource", "strategy": 0, "warmUpPeriodSec": 10 } ]
And, in my local macbook, to visit http://localhost:myport/actuator/sentinel that I could see these three rules. But, I tried to modify the rules in Apollo, which two rules were removed and, it seems that Sentinel console still fetch these three original rules or, is there any additional command that I need to run or not? I am not sure that is it an issue or Sentinel does not support fetch latest rules from external data source, such as zookeeper or apollo. What I read is from https://github.com/alibaba/Sentinel/wiki/FAQ - 规则存储与动态规则数据源(DataSource)
它似乎也不会影响作为数据存储的外部json文件。我在Sentinel控制台中添加了一个新规则,但根本没有更改json文件。
Apollo运行良好,其版本为1.1,我从Apollo存储库中获得了最新版本。自那以后,一些配置已成功设置如下:
spring.cloud.sentinel.transport.dashboard = localhost:8989 spring.cloud.sentinel.transport.port = 8721 spring.cloud.sentinel.datasource.type = apollo spring.cloud.sentinel.datasource.namespaceName = application spring.cloud.sentinel.datasource.flowRulesKey = flowRules spring.cloud.sentinel.datasource.converter = myParser spring.cloud.sentinel.datasource.defaultFlowRuleValue = [ { "resource": "testresource", "controlBehavior": 0, "count": 1.0, "grade": 1, "limitApp": "default", "strategy": 0 } ] server.port = 5550 management.endpoints.web.exposure.include = * management.endpoints.web.cors.allowed-origins = * management.endpoints.web.cors.allowed-methods = * management.endpoint.health.show-details = ALWAYS
And, my application will use these config when startup. The flowrulevalue could be shown via http://localhost:5550/actuator/sentinel url. Also, my application run ok. But, updating the defaultFlowRuleValue via apollo, these latest rules could not be updated via endpoint of actuator and sentinel console(still the old ones).
在我的主类中,添加了以下代码:
@SentinelDataSource("spring.cloud.sentinel.datasource") private ReadableDataSource dataSource;
@bean public Converter myParser() { return new JsonFlowRuleListParser(); }
甚至,我也尝试使用spring.cloud.setinel.datasource.type=文件基于 https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md (ReadableDataSource 支持)
spring.cloud.stinel.datasource.file=我在apollo中的本地json文件。要在sentinel控制台中更新或添加新规则,我的本地json文件无法更新为最新。
甚至,我通过存储库使用了示例代码sentinel-demo apollo数据源,在apollo中,有一个示例应用程序sentinel-demo,其配置如下:
sentinel-demo, whose config is below: spring.cloud.sentinel.transport.dashboard = localhost:8989 spring.cloud.sentinel.transport.port = 8721 spring.cloud.sentinel.datasource.type = apollo spring.cloud.sentinel.datasource.namespaceName = application spring.cloud.sentinel.datasource.flowRulesKey = flowRules spring.cloud.sentinel.datasource.converter = myParser spring.cloud.sentinel.datasource.defaultFlowRuleValue = [\n {\n "resource": "testresource",\n "controlBehavior": 0,\n "count": 1.0,\n "grade": 1,\n "limitApp": "default",\n "strategy": 0\n }\n ]
这条规则似乎没有影响。
原提问者GitHub用户quzhixue-Kimi
第一个问题:
我刚刚尝试了Apollo ,一切正常。
我认为你可以在Apollo 更新关键flowRulesKey,而不是defaultFlowRuleValue。
您可以在ApolloDataSource#initializeConfigChangeListener中调试以检查Apollo Listener是否正常。
当数据在Apollo中更改时,检查它是否可以调试到这个Listener中。
关于第二个问题:
当您在sentinel console更新或添加新规则时,您的本地json文件无法更新为最新版本。这是对的。
你可以更新你的本地json文件,它会在sentinel console更新。
原回答者GitHub用户fangjian0423
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。