开发者社区 > 云原生 > 正文

携程Apollo的规则无法自动更新

携程的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

展开
收起
白夜行fighting 2023-06-11 10:57:08 201 0
1 条回答
写回答
取消 提交回答
  • 第一个问题:

    我刚刚尝试了Apollo ,一切正常。

    我认为你可以在Apollo 更新关键flowRulesKey,而不是defaultFlowRuleValue。

    您可以在ApolloDataSource#initializeConfigChangeListener中调试以检查Apollo Listener是否正常。

    当数据在Apollo中更改时,检查它是否可以调试到这个Listener中。

    关于第二个问题:

    当您在sentinel console更新或添加新规则时,您的本地json文件无法更新为最新版本。这是对的。

    你可以更新你的本地json文件,它会在sentinel console更新。

    原回答者GitHub用户fangjian0423

    2023-06-11 12:04:05
    赞同 展开评论 打赏

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载