You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/04/12 01:12:28 UTC
[apisix] branch master updated: chore(traffic-split): remove the
default match rule of the traffic-split plugin (#4019)
This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new de80319 chore(traffic-split): remove the default match rule of the traffic-split plugin (#4019)
de80319 is described below
commit de8031902904fba58f8eb8197bc5dba99f88adac
Author: Yuelin Zheng <22...@qq.com>
AuthorDate: Mon Apr 12 09:12:19 2021 +0800
chore(traffic-split): remove the default match rule of the traffic-split plugin (#4019)
---
apisix/plugins/traffic-split.lua | 24 ++++++++++++++----------
docs/en/latest/plugins/traffic-split.md | 2 +-
docs/zh/latest/plugins/traffic-split.md | 2 +-
3 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/apisix/plugins/traffic-split.lua b/apisix/plugins/traffic-split.lua
index c8f22a2..5364438 100644
--- a/apisix/plugins/traffic-split.lua
+++ b/apisix/plugins/traffic-split.lua
@@ -44,9 +44,6 @@ local match_schema = {
vars = vars_schema
}
},
- -- When there is no `match` rule, the default rule passes.
- -- Perform upstream logic of plugin configuration.
- default = {{ vars = {{"server_port", ">", 0}}}}
}
@@ -247,9 +244,15 @@ function _M.access(conf, ctx)
return
end
- local weighted_upstreams, match_flag
+ local weighted_upstreams
+ local match_passed = true
+
for _, rule in ipairs(conf.rules) do
- match_flag = true
+ if not rule.match then
+ weighted_upstreams = rule.weighted_upstreams
+ break
+ end
+
for _, single_match in ipairs(rule.match) do
local expr, err = expr.new(single_match.vars)
if err then
@@ -257,20 +260,21 @@ function _M.access(conf, ctx)
return 500, err
end
- match_flag = expr:eval(ctx.var)
- if match_flag then
+ match_passed = expr:eval(ctx.var)
+ if match_passed then
break
end
end
- if match_flag then
+ if match_passed then
weighted_upstreams = rule.weighted_upstreams
break
end
end
- core.log.info("match_flag: ", match_flag)
- if not match_flag then
+ core.log.info("match_passed: ", match_passed)
+
+ if not match_passed then
return
end
diff --git a/docs/en/latest/plugins/traffic-split.md b/docs/en/latest/plugins/traffic-split.md
index df646fd..9189a81 100644
--- a/docs/en/latest/plugins/traffic-split.md
+++ b/docs/en/latest/plugins/traffic-split.md
@@ -42,7 +42,7 @@ Note: The ratio between each upstream may not so accurate since the drawback of
| Name | Type | Requirement | Default | Valid | Description |
| ------------------------------ | ------------- | ----------- | ------- | ------- | ---------------------------------------------------------------------------------------- |
-| rules.match | array[object] | optional | | | List of matching rules. |
+| rules.match | array[object] | optional | | | List of matching rules, by default the list is empty and the rule will be executed unconditionally. |
| rules.match.vars | array[array] | optional | | | A list consisting of one or more {var, operator, val} elements, like this: {{var, operator, val}, {var, operator, val}, ...}}. For example: {"arg_name", "==", "json"}, which means that the current request parameter name is json. The var here is consistent with the naming of Nginx internal variables, so request_uri, host, etc. can also be used; for the operator part, the currently supported operators are ==, ~=, ~~, [...]
| rules.weighted_upstreams | array[object] | optional | | | List of upstream configuration rules. |
| weighted_upstreams.upstream_id | string/integer| optional | | | The upstream id is bound to the corresponding upstream. |
diff --git a/docs/zh/latest/plugins/traffic-split.md b/docs/zh/latest/plugins/traffic-split.md
index 799d714..045ab54 100644
--- a/docs/zh/latest/plugins/traffic-split.md
+++ b/docs/zh/latest/plugins/traffic-split.md
@@ -42,7 +42,7 @@ traffic-split 插件使用户可以逐步引导各个上游之间的流量百分
| 参数名 | 类型 | 可选项 | 默认值 | 有效值 | 描述 |
| ---------------------- | --------------| ------ | ------ | ------ | -------------------- |
-| rules.match | array[object] | 可选 | | | 匹配规则列表 |
+| rules.match | array[object] | 可选 | | | 匹配规则列表,默认为空且规则将被无条件执行。 |
| rules.match.vars | array[array] | 可选 | | | 由一个或多个{var, operator, val}元素组成的列表,类似这样:{{var, operator, val}, {var, operator, val}, ...}}。例如:{"arg_name", "==", "json"},表示当前请求参数 name 是 json。这里的 var 与 Nginx 内部自身变量命名是保持一致,所以也可以使用 request_uri、host 等;对于 operator 部分,目前已支持的运算符有 ==、~=、~~、>、<、in、has 和 ! 。操作符的具体用法请看 [lua-resty-expr](https://github.com/api7/lua-resty-expr#operator-list) 的 `operator-list` 部分。 |
| rules.weighted_upstreams | array[object] | 可选 | | | 上游配置规则列表。 |
| weighted_upstreams.upstream_id | string / integer | 可选 | | | 通过上游 id 绑定对应上游。 |