apollo持久化sentinel_sentinel-apollo拉模式

代码地址: zhaoyunxing92/spring-boot-learn-box/tree/master/spring-boot-sentinel/sentinel-apollo

使用apollo为sentinel做数据持久化,sentinel的使用可以看sentinel使用,本项目打算采用spring-cloud-alibaba跟sentinel整合

背景

我们的项目即将上线了,但是缺少一个流量防卫兵,这个很要命,于是一周前我就开始着手看sentinel

为什么是sentinel

正如你们所理解的市面上有很多服务降级方案,如我也用过的hystrix,但是它没有完善的持久方案和后端管理界面再加上我也看了一片sentinel作者宿何的一篇比照文章Sentinel-与-Hystrix-的比照,已经我们现在的技术不太适合使用spring cloud体系

参考文档sentinel动态规则扩展

Sentinel使用Apollo存储规则

spring-cloud-alibaba

整合流程

pom.xmlorg.springframework.cloudspring-cloud-starter-alibaba-sentinel0.9.0.RELEASEcom.alibaba.cspsentinel-datasource-apollo1.6.0

application.ymlspring: application: name: spring-boot-sentinel-apollo cloud: sentinel: transport: port: 8719 # 向sentinel-dashboard传输数据的端口 默认:8719 dashboard: localhost:8100 # sentinel-dashboard log: dir: ./logs # 默认值${home}/logs/csp/ switch-pid: true # 日志带上线程id datasource: flow: # 流控规则 apollo: namespaceName: application flowRulesKey: flowRules rule-type: flow #flow,degrade,authority,system, param-flow degrade: # 熔断降级规则 apollo: namespaceName: application flowRulesKey: degrades rule-type: degrade authority: # 受权规则 未验证,官方不推荐 apollo: namespaceName: application flowRulesKey: authoritys rule-type: authority system: # 系统规则 apollo: namespaceName: application flowRulesKey: systems rule-type: system param-flow: # 热点规则 apollo: namespaceName: application flowRulesKey: paramflows rule-type: param-flowapp: id: ${spring.application.name}apollo: meta: http://127.0.0.1:8080 cacheDir: ./apolloconfig # 缓存文件位置

java@SpringBootApplication@EnableApolloConfig // 开启apollopublic class SpringSentinelApolloServer { public static void main(String[] args) { SpringApplication.run(SpringSentinelApolloServer.class, args); }}

jvm参数配置-Denv=DEV

flow(流控规则)参数格式json[ { "resource": "/hello", "limitApp": "default", "grade": 1, "count": 3, "strategy": 0, "controlBehavior": 0, "clusterMode": false }]

flow(流控规则)参数规则说明字段形容默认值resource资源名,即限流规则的作用对象

limitApp流控针对的调用来源,若为 default 则不区分调用来源default

grade限流阈值类型(QPS 或者并发线程数);0代表根据并发数量来限流,1代表根据QPS来进行流量控制QPS 模式

count限流阈值

strategy调用关系限流策略

controlBehavior流量控制效果(直接拒绝、Warm Up、匀速排队)拒绝

clusterMode能否为集群模式

system 系统规则参数格式,四个参数只能选择一个不可设置-1[{"qps": 2}]

system参数列表参数说明avgLoad最大的 load

avgRt所有入口流量的平均响应时间

maxThread入口流量的最大并发数

qps所有入口资源的 QPS

degrade 参数格式 json[ { "resource": "/rt", "count": 50, "timeWindow": 5, "grade": 0 }, { "resource": "/count", "count": 5, "timeWindow": 8, "grade": 2 }, { "resource": "/erro", "count": 0.5, "timeWindow": 5, "grade": 1 }]

degrade(熔断降级规则)参数规则说明字段形容默认值resource资源名,即限流规则的作用对象

count阈值

grade降级模式,根据 RT (0)、异常数(2)、 异常比例(1)RT (0)

timeWindow降级的时间,单位为 s

param-flow(热点规则) json[ { "resource": "/hello", "grade": 1, "paramIdx": 1, "count": 10, "paramFlowItemList": [] }]

param-flow(热点规则) 参数字段形容默认值resource资源名,必填

grade限流模式qps(1)

paramIdx热点参数的索引,必填,对应 SphU.entry(xxx, args) 中的参数索引位置

count限流阈值,必填

paramFlowItemList参数例外项,可以针对指定的参数值单独设置限流阈值,不受前面 count 阈值的限制。

apollo上配置server.port = 7852server.servlet.context-path = /sentinelflowRules = [{"resource": "/hello","limitApp": "default","grade": 1,"count": 3,"strategy": 0,"controlBehavior": 0,"clusterMode": false}]degrades = [{"resource": "/rt","count": 50,"timeWindow": 5,"grade": 0},{"resource": "/count","count": 5,"timeWindow": 8,"grade": 2},{"resource": "/erro","count": 0.5,"timeWindow": 5,"grade": 1}]authoritys = [{"resource": "/hello","limitApp": "192.168.12.215","strategy": 1}]paramflows = [{"resource": "/hello","grade": 1,"paramIdx": 1,"count": 10,"paramFlowItemList": []}]systems = [{"qps": 20}]

拉去规则成功日志2019-05-14 09:26:46.072 INFO 10100 --- [ main] o.s.c.a.s.c.SentinelDataSourceHandler : [Sentinel Starter] DataSource authority-sentinel-apollo-datasource load 1 AuthorityRule 2019-05-14 09:26:46.090 INFO 10100 --- [ main] o.s.c.a.s.c.SentinelDataSourceHandler : [Sentinel Starter] DataSource degrade-sentinel-apollo-datasource load 3 DegradeRule 2019-05-14 09:26:46.099 INFO 10100 --- [ main] o.s.c.a.s.c.SentinelDataSourceHandler : [Sentinel Starter] DataSource flow-sentinel-apollo-datasource load 1 FlowRule 2019-05-14 09:26:46.115 INFO 10100 --- [ main] o.s.c.a.s.c.SentinelDataSourceHandler : [Sentinel Starter] DataSource param-flow-sentinel-apollo-datasource load 1 ParamFlowRule 2019-05-14 09:26:46.122 INFO 10100 --- [ main] o.s.c.a.s.c.SentinelDataSourceHandler : [Sentinel Starter] DataSource system-sentinel-apollo-datasource load 1 SystemRule

测试接口

http://localhost:7852/sentinel/hello

最终效果图

sentinel-dashboard

apollo-dashboard

结尾

相信坚持看完的同学已经崩溃了,拉模式的配置太头疼了.确实为了完成这篇文章,里面的参数都是我在浏览器里面抓取过来的耗费了我大量的时间,巧的是sentinel官方也意识到了这点他们提供了推模式只不过需要修改sentinel-dashboard的源码,后面我会把真理好的代码提交在sentinel-dashboard-apollo仓库,已经需改了一点,有兴趣的可以先去看

最后

假如你想理解更多的文章可以微信搜索zhaoyx92,或者者扫码关注,7*24的技术支撑

zhaoyx92

文章同步github

简书

csdn

个人博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
root@in_dev_docker:/apollo# bash scripts/msf_create_lossless_map.sh /apollo/hdmap/pcd_apollo/ 50 /apollo/hdmap/ /apollo/bazel-bin WARNING: Logging before InitGoogleLogging() is written to STDERR E0715 22:08:35.399576 6436 lossless_map_creator.cc:162] num_trials = 1 Pcd folders are as follows: /apollo/hdmap/pcd_apollo/ Resolution: 0.125 Dataset: /apollo/hdmap/pcd_apollo Dataset: /apollo/hdmap/pcd_apollo/ Loaded the map configuration from: /apollo/hdmap//lossless_map/config.xml. Saved the map configuration to: /apollo/hdmap//lossless_map/config.xml. Saved the map configuration to: /apollo/hdmap//lossless_map/config.xml. E0715 22:08:35.767315 6436 lossless_map_creator.cc:264] ieout_poses = 1706 Failed to find match for field 'intensity'. Failed to find match for field 'timestamp'. E0715 22:08:35.769896 6436 velodyne_utility.cc:46] Un-organized-point-cloud E0715 22:08:35.781770 6436 lossless_map_creator.cc:275] Loaded 245443D Points at Trial: 0 Frame: 0. F0715 22:08:35.781791 6436 base_map_node_index.cc:101] Check failed: false *** Check failure stack trace: *** scripts/msf_create_lossless_map.sh: line 11: 6436 Aborted (core dumped) $APOLLO_BIN_PREFIX/modules/localization/msf/local_tool/map_creation/lossless_map_creator --use_plane_inliers_only true --pcd_folders $1 --pose_files $2 --map_folder $IN_FOLDER --zone_id $ZONE_ID --coordinate_type UTM --map_resolution_type single root@in_dev_docker:/apollo# bash scripts/msf_create_lossless_map.sh /apollo/hdmap/pcd_apollo/ 50 /apollo/hdmap/
07-16

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值