feat: Implement traffic splitting plugin#2935
Conversation
|
Please write a better title and desc |
|
@Firstsawyou CI failed, please fix it. |
|
@spacewander @membphis @tokers I don't know what caused this. |
|
@Firstsawyou What is the name of this plugin? the PR title and code file are not the same. |
updated. |
Not yet , please read your desc again |
t/plugin/dynamic-upstream.t
Outdated
| === TEST 5: Multiple vars rules and multiple plugin upstream | ||
| --- config | ||
| location /t { | ||
| content_by_lua_block { |
There was a problem hiding this comment.
Reduce the total code length in content_by_lua_block
There was a problem hiding this comment.
Thank you very much, I will try.
|
We should use traffic split instead dynamic-upstream, in the future, the traffic split plugin will provide the labels based selector to choose nodes inside a upstream, this function is not covered by the name dynamic-upstream, which gives us an illusion this plugin is used for choosing one upstream from multiple upstreams. |
Ok i will update later. |
|
There was a problem when this |
|
No, please fix it in this PR |
6d88ccb to
f11e9b2
Compare
|
@Firstsawyou Could you paste some sample traffic split configurations here to help us understand the schema better. |
|
@Firstsawyou Please resolve the conflicts. |
@tokers These are two cases, which will help you understand: Grayscale ReleaseTraffic is split according to the weight value configured by upstreams in the plugin (the rule of {
"weight": 2
}There is only a curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/index.html",
"plugins": {
"traffic-split": {
"rules": [
{
"upstreams": [
{
"upstream": {
"name": "upstream_A",
"type": "roundrobin",
"nodes": {
"127.0.0.1:1981":10
},
"timeout": {
"connect": 15,
"send": 15,
"read": 15
}
},
"weight": 4
},
{
"weight": 2
}
]
}
]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
}
}'Custom ReleaseMultiple matching rules can be set in curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/index.html",
"plugins": {
"traffic-split": {
"rules": [
{
"match": [
{
"vars": [
["arg_name","==","jack"],
["http_user-id",">","23"],
["http_apisix-key","~~","[a-z]+"]
]
}
],
"upstreams": [
{
"upstream": {
"name": "upstream_A",
"type": "roundrobin",
"nodes": {
"127.0.0.1:1981":10
}
},
"weight": 4
},
{
"weight": 2
}
]
}
]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
}
}' |
| ["http_user-id",">","23"], | ||
| ["http_apisix-key","~~","[a-z]+"] |
close #2303 close #2603
What this PR does / why we need it:
Implement a traffic splitting plugin, the plugin is named
traffic-split. The main function of the plug-in is to divide the request traffic according to the specified ratio and divert it to the corresponding "upstream". The functions ofGray release,Blue-green releaseandCustom releasecan be realized through this plugin.Related issue:
https://github.com/apache/apisix/issues/2303
https://github.com/apache/apisix/issues/2603
Mailing list discussion address:
https://lists.apache.org/thread.html/rf02dc53a4af5d98d2513d89256b47466934d129af06d0bdcdb49cc8e%40%3Cdev.apisix.apache.org%3E
Pre-submission checklist: