Skip to content

Dynamic Rule Configuration

jialianglinjl edited this page Jun 25, 2018 · 9 revisions

All the rules can be queried or modified in memory and these modifications take effects immediately. And Sentinel also provides APIs for developers to defines its own rules.

Rule definitions

There are 3 kinds of rules: Flow rules, degrade rules, system rules.

1.Flow Rules

Flow Rule has following fields:

field description default value
resource resource name
count thredshold
grade depends on QPS or concurrency(active thread count) QPS
limitApp whether to count on callers no
strategy count on the resource itself; or on the relate resource(refResource),or on entry resource(refResource) resource itself
controlBehavior how to action after block criteria is met, to block immediately, or wait in queue, or slow warm up block immediatley

One resource can apply several rules

2.降级规则 降级规则包含下面几个重要的属性:

field 说明 默认值
resource 资源名,资源名是限流规则的作用对象
count 限流阈值
grade 根据RT降级还是根据异常比例降级 RT
timeWindow 降级的时间

同一个资源可以同时有多个降级规则。

3.系统保护规则

查询已有的规则

运行下面命令,则会返回现有生效的规则:

curl http://localhost:8719/getRules?type=? 其中,type=flow则以JSON格式返回现有的限流塑形规则;degrade则返回现有生效的降级规则列表;system则发挥系统保护规则

更改已有的规则

我们同时也可以通过下面命令,来修改已有规则:

curl http://localhost:8719/setRules?type=&data=,其中,type可以输入flow,degrade 等方式来制定更改的规则种类,data则是对应的JSON格式的规则。

定制自己的持久化规则

上面的规则配置,都是出于内存状态的。即如果应用发生了重启,这个规则就会失效。我们提供了开放的接口。你可以通过实现 DataSource的方式,来自定义自己的持久化规则。通常我们的建议有:

  1. 整合Diamond,动态的实时刷新配置规则
  2. 结合SQL,GitHub等来实现该规则
  3. 和Dashboard一起。

重要的例子请参考 <TODOTODOTODO>

Clone this wiki locally