Ben0625 commented on issue #4090:
URL: https://github.com/apache/apisix/issues/4090#issuecomment-823835952


   > You can try the traffic-split plug-in. Here is an example of configuration:
   > 
   > ```shell
   > 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
   
   > local rr_up, err = core.lrucache.plugin_ctx(plugin_name, ctx, new_rr_obj, 
weighted_upstreams)
   > local upstream = rr_up:find()
   
   I print the log to see `weighted_upstreams` before Line 281 and it is 
correct. But Line 288 does not give the right output.


-- 
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:
[email protected]


Reply via email to