You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/03/31 06:49:32 UTC
[GitHub] [apisix] Firstsawyou opened a new pull request #3955: feat(traffic-split): upstream.type support chash configuration
Firstsawyou opened a new pull request #3955:
URL: https://github.com/apache/apisix/pull/3955
fix #3858
Signed-off-by: Firstsawyou yuelinz99@gmail.com
### What this PR does / why we need it:
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
### Pre-submission checklist:
* [x] Did you explain what problem does this PR solve? Or what new features have been added?
* [x] Have you added corresponding test cases?
* [x] Have you modified the corresponding document?
* [x] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix/tree/master#community) first**
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] Firstsawyou commented on a change in pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
Firstsawyou commented on a change in pull request #3955:
URL: https://github.com/apache/apisix/pull/3955#discussion_r605454017
##########
File path: apisix/plugins/traffic-split.lua
##########
@@ -200,6 +200,11 @@ local function set_upstream(upstream_info, ctx)
}
}
+ if upstream_info.type == "chash" then
+ up_conf.hash_on = upstream_info.hash_on
+ up_conf.key = upstream_info.key
Review comment:
updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] Firstsawyou commented on a change in pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
Firstsawyou commented on a change in pull request #3955:
URL: https://github.com/apache/apisix/pull/3955#discussion_r605540491
##########
File path: t/plugin/traffic-split2.t
##########
@@ -376,28 +374,38 @@ location /t {
local t = require("lib.test_admin").test
local bodys = {}
local headers = {}
+ local headers2 = {}
headers["custom_header"] = "custom-one"
- for i = 1, 4 do
+ headers2["custom_header"] = "customtow"
Review comment:
Updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] Firstsawyou commented on a change in pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
Firstsawyou commented on a change in pull request #3955:
URL: https://github.com/apache/apisix/pull/3955#discussion_r605453298
##########
File path: docs/zh/latest/plugins/traffic-split.md
##########
@@ -47,7 +47,7 @@ traffic-split 插件使用户可以逐步引导各个上游之间的流量百分
| rules.weighted_upstreams | array[object] | 可选 | | | 上游配置规则列表。 |
| weighted_upstreams.upstream_id | string / integer | 可选 | | | 通过上游 id 绑定对应上游。 |
| weighted_upstreams.upstream | object | 可选 | | | 上游配置信息。 |
-| upstream.type | enum | 可选 | roundrobin | [roundrobin, chash] | roundrobin 支持权重的负载,chash 一致性哈希,两者是二选一的(目前只支持 `roundrobin`)。 |
+| upstream.type | enum | 可选 | roundrobin | [roundrobin, chash] | roundrobin 支持权重的负载,chash 一致性哈希,两者是二选一。 |
Review comment:
Updated.
##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,93 @@ host: localhost
x-real-ip: 127.0.0.1
--- no_error_log
[error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "weighted_upstreams": [
+ {
+ "upstream": {
+ "name": "chash_test",
+ "type": "chash",
+ "hash_on": "header",
+ "key": "custom_header",
+ "nodes": {
+ "127.0.0.1:1981":1,
+ "127.0.0.1:1982":1
+ }
+ },
+ "weight": 1
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
Review comment:
Updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tokers commented on a change in pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #3955:
URL: https://github.com/apache/apisix/pull/3955#discussion_r604799626
##########
File path: docs/zh/latest/plugins/traffic-split.md
##########
@@ -47,7 +47,7 @@ traffic-split 插件使用户可以逐步引导各个上游之间的流量百分
| rules.weighted_upstreams | array[object] | 可选 | | | 上游配置规则列表。 |
| weighted_upstreams.upstream_id | string / integer | 可选 | | | 通过上游 id 绑定对应上游。 |
| weighted_upstreams.upstream | object | 可选 | | | 上游配置信息。 |
-| upstream.type | enum | 可选 | roundrobin | [roundrobin, chash] | roundrobin 支持权重的负载,chash 一致性哈希,两者是二选一的(目前只支持 `roundrobin`)。 |
+| upstream.type | enum | 可选 | roundrobin | [roundrobin, chash] | roundrobin 支持权重的负载,chash 一致性哈希,两者是二选一。 |
Review comment:
I think it's necessary. @Firstsawyou
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on a change in pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #3955:
URL: https://github.com/apache/apisix/pull/3955#discussion_r604682035
##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,93 @@ host: localhost
x-real-ip: 127.0.0.1
--- no_error_log
[error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "weighted_upstreams": [
+ {
+ "upstream": {
+ "name": "chash_test",
+ "type": "chash",
+ "hash_on": "header",
+ "key": "custom_header",
+ "nodes": {
+ "127.0.0.1:1981":1,
+ "127.0.0.1:1982":1
+ }
+ },
+ "weight": 1
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 11: hit routes, hash_on custom header
+--- config
+location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local bodys = {}
+ local headers = {}
+ headers["custom_header"] = "custom-one"
+ for i = 1, 4 do
+ local _, _, body = t('/server_port', ngx.HTTP_GET, "", nil, headers)
+ bodys[i] = body
+ end
+
+ table.sort(bodys)
+ ngx.say(table.concat(bodys, ", "))
+ }
+}
+--- request
+GET /t
+--- response_body eval
+qr/1981, 1981, 1981, 1981|1982, 1982, 1982, 1982/
Review comment:
Since we only use `custom-one` as the key, in what situation 1982 will be used?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander merged pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
spacewander merged pull request #3955:
URL: https://github.com/apache/apisix/pull/3955
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] Firstsawyou commented on a change in pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
Firstsawyou commented on a change in pull request #3955:
URL: https://github.com/apache/apisix/pull/3955#discussion_r604814023
##########
File path: docs/zh/latest/plugins/traffic-split.md
##########
@@ -47,7 +47,7 @@ traffic-split 插件使用户可以逐步引导各个上游之间的流量百分
| rules.weighted_upstreams | array[object] | 可选 | | | 上游配置规则列表。 |
| weighted_upstreams.upstream_id | string / integer | 可选 | | | 通过上游 id 绑定对应上游。 |
| weighted_upstreams.upstream | object | 可选 | | | 上游配置信息。 |
-| upstream.type | enum | 可选 | roundrobin | [roundrobin, chash] | roundrobin 支持权重的负载,chash 一致性哈希,两者是二选一的(目前只支持 `roundrobin`)。 |
+| upstream.type | enum | 可选 | roundrobin | [roundrobin, chash] | roundrobin 支持权重的负载,chash 一致性哈希,两者是二选一。 |
Review comment:
Yes, agree.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on a change in pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #3955:
URL: https://github.com/apache/apisix/pull/3955#discussion_r605487441
##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,101 @@ host: localhost
x-real-ip: 127.0.0.1
--- no_error_log
[error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "weighted_upstreams": [
+ {
+ "upstream": {
+ "name": "chash_test",
+ "type": "chash",
+ "hash_on": "header",
+ "key": "custom_header",
+ "nodes": {
+ "127.0.0.1:1981":1,
+ "127.0.0.1:1982":1
+ }
+ },
+ "weight": 1
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 11: hit routes, hash_on custom header
+--- config
+location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local bodys = {}
+ local headers = {}
+ local headers2 = {}
+ headers["custom_header"] = "custom-one"
+ headers2["custom_header"] = "customtow"
+ for i = 1, 8, 2 do
+ local _, _, body = t('/server_port', ngx.HTTP_GET, "", nil, headers)
+ local _, _, body2 = t('/server_port', ngx.HTTP_GET, "", nil, headers2)
+ bodys[i] = body
+ bodys[i+1] = body2
+ end
+
+ table.sort(bodys)
+ ngx.say(table.concat(bodys, ", "))
+ }
+}
+--- response_body eval
+qr/1981, 1981, 1981, 1981, 1982, 1982, 1982, 1982/
Review comment:
Should be 1981, 1982, ...?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on a change in pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #3955:
URL: https://github.com/apache/apisix/pull/3955#discussion_r605530618
##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,101 @@ host: localhost
x-real-ip: 127.0.0.1
--- no_error_log
[error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "weighted_upstreams": [
+ {
+ "upstream": {
+ "name": "chash_test",
+ "type": "chash",
+ "hash_on": "header",
+ "key": "custom_header",
+ "nodes": {
+ "127.0.0.1:1981":1,
+ "127.0.0.1:1982":1
+ }
+ },
+ "weight": 1
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 11: hit routes, hash_on custom header
+--- config
+location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local bodys = {}
+ local headers = {}
+ local headers2 = {}
+ headers["custom_header"] = "custom-one"
+ headers2["custom_header"] = "customtow"
+ for i = 1, 8, 2 do
+ local _, _, body = t('/server_port', ngx.HTTP_GET, "", nil, headers)
+ local _, _, body2 = t('/server_port', ngx.HTTP_GET, "", nil, headers2)
+ bodys[i] = body
+ bodys[i+1] = body2
+ end
+
+ table.sort(bodys)
Review comment:
We should remove this line as it breaks the order introduced by chash.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on a change in pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #3955:
URL: https://github.com/apache/apisix/pull/3955#discussion_r605487441
##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,101 @@ host: localhost
x-real-ip: 127.0.0.1
--- no_error_log
[error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "weighted_upstreams": [
+ {
+ "upstream": {
+ "name": "chash_test",
+ "type": "chash",
+ "hash_on": "header",
+ "key": "custom_header",
+ "nodes": {
+ "127.0.0.1:1981":1,
+ "127.0.0.1:1982":1
+ }
+ },
+ "weight": 1
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 11: hit routes, hash_on custom header
+--- config
+location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local bodys = {}
+ local headers = {}
+ local headers2 = {}
+ headers["custom_header"] = "custom-one"
+ headers2["custom_header"] = "customtow"
+ for i = 1, 8, 2 do
+ local _, _, body = t('/server_port', ngx.HTTP_GET, "", nil, headers)
+ local _, _, body2 = t('/server_port', ngx.HTTP_GET, "", nil, headers2)
+ bodys[i] = body
+ bodys[i+1] = body2
+ end
+
+ table.sort(bodys)
+ ngx.say(table.concat(bodys, ", "))
+ }
+}
+--- response_body eval
+qr/1981, 1981, 1981, 1981, 1982, 1982, 1982, 1982/
Review comment:
Should be 1981, 1982, ...?
##########
File path: t/plugin/traffic-split2.t
##########
@@ -376,28 +374,38 @@ location /t {
local t = require("lib.test_admin").test
local bodys = {}
local headers = {}
+ local headers2 = {}
headers["custom_header"] = "custom-one"
- for i = 1, 4 do
+ headers2["custom_header"] = "customtow"
Review comment:
Better to avoid using a word that looks like typo
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on a change in pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #3955:
URL: https://github.com/apache/apisix/pull/3955#discussion_r605406782
##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,93 @@ host: localhost
x-real-ip: 127.0.0.1
--- no_error_log
[error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "weighted_upstreams": [
+ {
+ "upstream": {
+ "name": "chash_test",
+ "type": "chash",
+ "hash_on": "header",
+ "key": "custom_header",
+ "nodes": {
+ "127.0.0.1:1981":1,
+ "127.0.0.1:1982":1
+ }
+ },
+ "weight": 1
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 11: hit routes, hash_on custom header
+--- config
+location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local bodys = {}
+ local headers = {}
+ headers["custom_header"] = "custom-one"
+ for i = 1, 4 do
+ local _, _, body = t('/server_port', ngx.HTTP_GET, "", nil, headers)
+ bodys[i] = body
+ end
+
+ table.sort(bodys)
+ ngx.say(table.concat(bodys, ", "))
+ }
+}
+--- request
+GET /t
+--- response_body eval
+qr/1981, 1981, 1981, 1981|1982, 1982, 1982, 1982/
Review comment:
Agree
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] Firstsawyou commented on a change in pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
Firstsawyou commented on a change in pull request #3955:
URL: https://github.com/apache/apisix/pull/3955#discussion_r605393070
##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,93 @@ host: localhost
x-real-ip: 127.0.0.1
--- no_error_log
[error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "weighted_upstreams": [
+ {
+ "upstream": {
+ "name": "chash_test",
+ "type": "chash",
+ "hash_on": "header",
+ "key": "custom_header",
+ "nodes": {
+ "127.0.0.1:1981":1,
+ "127.0.0.1:1982":1
+ }
+ },
+ "weight": 1
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 11: hit routes, hash_on custom header
+--- config
+location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local bodys = {}
+ local headers = {}
+ headers["custom_header"] = "custom-one"
+ for i = 1, 4 do
+ local _, _, body = t('/server_port', ngx.HTTP_GET, "", nil, headers)
+ bodys[i] = body
+ end
+
+ table.sort(bodys)
+ ngx.say(table.concat(bodys, ", "))
+ }
+}
+--- request
+GET /t
+--- response_body eval
+qr/1981, 1981, 1981, 1981|1982, 1982, 1982, 1982/
Review comment:
I think we can add another header to trigger the use of 1982.
##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,93 @@ host: localhost
x-real-ip: 127.0.0.1
--- no_error_log
[error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "weighted_upstreams": [
+ {
+ "upstream": {
+ "name": "chash_test",
+ "type": "chash",
+ "hash_on": "header",
+ "key": "custom_header",
+ "nodes": {
+ "127.0.0.1:1981":1,
+ "127.0.0.1:1982":1
+ }
+ },
+ "weight": 1
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 11: hit routes, hash_on custom header
+--- config
+location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local bodys = {}
+ local headers = {}
+ headers["custom_header"] = "custom-one"
+ for i = 1, 4 do
+ local _, _, body = t('/server_port', ngx.HTTP_GET, "", nil, headers)
+ bodys[i] = body
+ end
+
+ table.sort(bodys)
+ ngx.say(table.concat(bodys, ", "))
+ }
+}
+--- request
+GET /t
+--- response_body eval
+qr/1981, 1981, 1981, 1981|1982, 1982, 1982, 1982/
Review comment:
I think we can add another header to trigger the use of 1982 ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] Firstsawyou commented on a change in pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
Firstsawyou commented on a change in pull request #3955:
URL: https://github.com/apache/apisix/pull/3955#discussion_r605539480
##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,101 @@ host: localhost
x-real-ip: 127.0.0.1
--- no_error_log
[error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "weighted_upstreams": [
+ {
+ "upstream": {
+ "name": "chash_test",
+ "type": "chash",
+ "hash_on": "header",
+ "key": "custom_header",
+ "nodes": {
+ "127.0.0.1:1981":1,
+ "127.0.0.1:1982":1
+ }
+ },
+ "weight": 1
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 11: hit routes, hash_on custom header
+--- config
+location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local bodys = {}
+ local headers = {}
+ local headers2 = {}
+ headers["custom_header"] = "custom-one"
+ headers2["custom_header"] = "customtow"
+ for i = 1, 8, 2 do
+ local _, _, body = t('/server_port', ngx.HTTP_GET, "", nil, headers)
+ local _, _, body2 = t('/server_port', ngx.HTTP_GET, "", nil, headers2)
+ bodys[i] = body
+ bodys[i+1] = body2
+ end
+
+ table.sort(bodys)
Review comment:
Updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] Firstsawyou commented on a change in pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
Firstsawyou commented on a change in pull request #3955:
URL: https://github.com/apache/apisix/pull/3955#discussion_r605454281
##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,93 @@ host: localhost
x-real-ip: 127.0.0.1
--- no_error_log
[error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "weighted_upstreams": [
+ {
+ "upstream": {
+ "name": "chash_test",
+ "type": "chash",
+ "hash_on": "header",
+ "key": "custom_header",
+ "nodes": {
+ "127.0.0.1:1981":1,
+ "127.0.0.1:1982":1
+ }
+ },
+ "weight": 1
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
Review comment:
updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on a change in pull request #3955: fix(traffic-split): upstream.type support chash configuration
Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #3955:
URL: https://github.com/apache/apisix/pull/3955#discussion_r604679235
##########
File path: docs/zh/latest/plugins/traffic-split.md
##########
@@ -47,7 +47,7 @@ traffic-split 插件使用户可以逐步引导各个上游之间的流量百分
| rules.weighted_upstreams | array[object] | 可选 | | | 上游配置规则列表。 |
| weighted_upstreams.upstream_id | string / integer | 可选 | | | 通过上游 id 绑定对应上游。 |
| weighted_upstreams.upstream | object | 可选 | | | 上游配置信息。 |
-| upstream.type | enum | 可选 | roundrobin | [roundrobin, chash] | roundrobin 支持权重的负载,chash 一致性哈希,两者是二选一的(目前只支持 `roundrobin`)。 |
+| upstream.type | enum | 可选 | roundrobin | [roundrobin, chash] | roundrobin 支持权重的负载,chash 一致性哈希,两者是二选一。 |
Review comment:
Can we add a separate passage for the features that haven't been implemented yet, like retry and service discovery?
By the way, we should also update the English version.
##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,93 @@ host: localhost
x-real-ip: 127.0.0.1
--- no_error_log
[error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "weighted_upstreams": [
+ {
+ "upstream": {
+ "name": "chash_test",
+ "type": "chash",
+ "hash_on": "header",
+ "key": "custom_header",
+ "nodes": {
+ "127.0.0.1:1981":1,
+ "127.0.0.1:1982":1
+ }
+ },
+ "weight": 1
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
Review comment:
There is no need to set `--- request`, we already set it in the add_block_preprocessor at the beginning of this file.
##########
File path: apisix/plugins/traffic-split.lua
##########
@@ -200,6 +200,11 @@ local function set_upstream(upstream_info, ctx)
}
}
+ if upstream_info.type == "chash" then
+ up_conf.hash_on = upstream_info.hash_on
+ up_conf.key = upstream_info.key
Review comment:
We can directly copy those fields without checking their type.
##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,93 @@ host: localhost
x-real-ip: 127.0.0.1
--- no_error_log
[error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "weighted_upstreams": [
+ {
+ "upstream": {
+ "name": "chash_test",
+ "type": "chash",
+ "hash_on": "header",
+ "key": "custom_header",
+ "nodes": {
+ "127.0.0.1:1981":1,
+ "127.0.0.1:1982":1
+ }
+ },
+ "weight": 1
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 11: hit routes, hash_on custom header
+--- config
+location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local bodys = {}
+ local headers = {}
+ headers["custom_header"] = "custom-one"
+ for i = 1, 4 do
+ local _, _, body = t('/server_port', ngx.HTTP_GET, "", nil, headers)
+ bodys[i] = body
+ end
+
+ table.sort(bodys)
+ ngx.say(table.concat(bodys, ", "))
+ }
+}
+--- request
+GET /t
+--- response_body eval
+qr/1981, 1981, 1981, 1981|1982, 1982, 1982, 1982/
Review comment:
Since we only use `custom-one` as the key, in what situation 1982 will be used?
##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,93 @@ host: localhost
x-real-ip: 127.0.0.1
--- no_error_log
[error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "weighted_upstreams": [
+ {
+ "upstream": {
+ "name": "chash_test",
+ "type": "chash",
+ "hash_on": "header",
+ "key": "custom_header",
+ "nodes": {
+ "127.0.0.1:1981":1,
+ "127.0.0.1:1982":1
+ }
+ },
+ "weight": 1
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
Review comment:
Ditto
##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,93 @@ host: localhost
x-real-ip: 127.0.0.1
--- no_error_log
[error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "weighted_upstreams": [
+ {
+ "upstream": {
+ "name": "chash_test",
+ "type": "chash",
+ "hash_on": "header",
+ "key": "custom_header",
+ "nodes": {
+ "127.0.0.1:1981":1,
+ "127.0.0.1:1982":1
+ }
+ },
+ "weight": 1
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 11: hit routes, hash_on custom header
+--- config
+location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local bodys = {}
+ local headers = {}
+ headers["custom_header"] = "custom-one"
+ for i = 1, 4 do
+ local _, _, body = t('/server_port', ngx.HTTP_GET, "", nil, headers)
+ bodys[i] = body
+ end
+
+ table.sort(bodys)
+ ngx.say(table.concat(bodys, ", "))
+ }
+}
+--- request
+GET /t
+--- response_body eval
+qr/1981, 1981, 1981, 1981|1982, 1982, 1982, 1982/
Review comment:
Since we only use `custom-one` as the key, in what situation 1982 will be used?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org