-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request help: Correspondence between matched rules and upstreams within one route #4090
Comments
Look like the |
You can try the traffic-split plug-in. Here is an example of configuration: curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/hello",
"plugins": {
"traffic-split": {
"rules": [
{
"match": [
{
"vars": [
["http_id","==","1"]
]
}
],
"weighted_upstreams": [
{
"upstream": {
"name": "upstream_A",
"type": "roundrobin",
"nodes": {
"127.0.0.1:1981":1
}
},
"weight": 3
}
]
},
{
"match": [
{
"vars": [
["http_id","==","2"]
]
}
],
"weighted_upstreams": [
{
"upstream": {
"name": "upstream_B",
"type": "roundrobin",
"nodes": {
"127.0.0.1:1982":1
}
},
"weight": 3
}
]
}
]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
}
}' However, it may not take effect in APISIX 2.5. You can try it in versions before 2.5. |
I modify some input args at Line 281 of traffic-spllit.lua and try it in version 2.0 and there exist a bug. When I first send a request with "id = 1", it correctly chooses upstream_A. But after that, no matter what I send with "id = 1" or "id = 2", it always chooses upstream_A and never chooses upstream_B. Then I reload APISIX, this time I first send a request with "id = 2", it correctly chooses upstream_B. Then if I request with "id = 1" or "id = 2", it always chooses upstream_B. It seems that the problem is at Line 281 and Line 288 of traffic-split.lua
I print the log to see |
Yes, this is a known bug. If you want to implement this function in APISIX 2.5, you can refer to the following PR to modify the traffic-split.lua code. |
Since I use APISIX 2.0 before, I try your change at APISIX 2.0 and it works! |
I find a new bug here:
Reproduce steps:
Then you will see nodes of upstream_A be picked when requesting with id = 2 for some time. It looks messed up. |
This scenario has been covered by test cases, please see here: https://github.com/apache/apisix/blob/master/t/plugin/traffic-split2.t#L513-L613 |
My APISIX version is 2.0. I modify a little bit (At Line 194) to let this plugin run successfully.
I set 2 nodes instead of 1 and run the Reproduce steps. Then it messed up. |
The number of upstream nodes is not affected. There are many bug fixes between APISIX 2.0 and APISIX 2.5. You should upgrade to version 2.5 and try again. |
Request:
For now, if I have 10 correspondence, I have to create 10 routes with the same path "/test". Then set one correspondence for each route.
I check
traffic-split
plugin, it works well for 2 upstreams, but it doesn't seem to match more than 2 correspondence.Is it possible to set just one route and have multiple correspondence as
Request
describes?The text was updated successfully, but these errors were encountered: