xianshun163 opened a new issue #5607:
URL: https://github.com/apache/apisix/issues/5607


   ### Issue description
   
   the traffic-split make some error,  as the error log show
   
   ### Environment
   
   - apisix version (cmd: `apisix version`): 2.10.1
   - OS (cmd: `uname -a`):  CentOS Linux release 7.6.1810 (Core)
   - OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`):nginx 
version: openresty/1.19.9.1
   - etcd version, if have (cmd: run `curl 
http://127.0.0.1:9090/v1/server_info` to get the info from server-info 
API):"etcd_version":"3.4.0",
   - apisix-dashboard version, if have: 2.10.1
   - the plugin runner version, if the issue is about a plugin runner (cmd: 
depended on the kind of runner):
   - luarocks version, if the issue is about installation (cmd: `luarocks 
--version`):
   
   
   ### Steps to reproduce
   
   1、I create a  rule  like this:  the  upstream is  a simple java app server
    curl http://127.0.0.1:9080/apisix/admin/routes/xs-app-r1 -H 'X-API-KEY: 
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   {
       "uri": "/index",
       "name": "蓝绿发布",
       "host": "local.xsapp.org",
       "plugins": {
           "traffic-split": {
               "rules": [
                   {
                                                                                
"match": [
                           {
                               "vars": [
                                   ["http_release","==","new_release"]
                               ]
                           }
                       ],
                       "weighted_upstreams": [
                           {
                                   "upstream_id": "382981255605519758",
                                   "weight": 2
                           },
                           {
                                "weight": 1
                           }
                       ]
                   }
               ]
           }
       },
       "upstream_id": "382981468860712334"
   }'
   
   2、I open  a global  plugin  key-auth  in the  dashboard
   
   3、I test it  like this :  curl http://127.0.0.1:9080/index -H 'release: 
new_release'   -H 'Host: local.xsapp.org'  -H "apikey: key-of-sam"
   
   4、sometimes it  work , some time it make  a error,  as the  error log  show。
   
   5、And then I  go to  print  some  error log  in the  lua  file,  you can see 
it  at the error log.
   
   ### Actual result
   
   as the error log show
   
   ### Error log
   
   2021/11/25 14:03:47 [warn] 24989#24989: *39085296 [lua] lrucache.lua:92: 
lrucache(): ----xs---begin to create_obj_fun---,key:table: 0x7f76788384f8, 
client: 127.0.0.1, server: _, request: "GET /index HTTP/1.1", host: 
"local.xsapp.org"
   2021/11/25 14:03:47 [error] 24989#24989: *39085296 [lua] 
traffic-split.lua:202: create_obj_fun(): ---xs-- 
upstream_obj:{"upstream_id":"382981255605519758","weight":2}, client: 
127.0.0.1, server: _, request: "GET /index HTTP/1.1", host: "local.xsapp.org"
   2021/11/25 14:03:47 [error] 24989#24989: *39085296 [lua] 
traffic-split.lua:205: create_obj_fun(): -----xs--- 
upstream_id:382981255605519758, client: 127.0.0.1, server: _, request: "GET 
/index HTTP/1.1", host: "local.xsapp.org"
   2021/11/25 14:03:47 [error] 24989#24989: *39085296 [lua] 
traffic-split.lua:202: create_obj_fun(): ---xs-- 
upstream_obj:{"upstream":"plugin#upstream#is#empty","weight":1}, client: 
127.0.0.1, server: _, request: "GET /index HTTP/1.1", host: "local.xsapp.org"
   2021/11/25 14:03:47 [error] 24989#24989: *39085296 [lua] 
traffic-split.lua:209: create_obj_fun(): ----xs--- upstream is not 
null:plugin#upstream#is#empty, client: 127.0.0.1, server: _, request: "GET 
/index HTTP/1.1", host: "local.xsapp.org"
   2021/11/25 14:03:47 [error] 24989#24989: *39085296 lua entry thread aborted: 
runtime error: /data/apisix-2.10.1/apisix/plugins/traffic-split.lua:210: 
attempt to index field 'upstream' (a string value)
   stack traceback:
   coroutine 0:
           /data/apisix-2.10.1/apisix/plugins/traffic-split.lua: in function 
'create_obj_fun'
           /data/apisix-2.10.1/apisix/core/lrucache.lua:93: in function 
'lrucache'
           /data/apisix-2.10.1/apisix/plugins/traffic-split.lua:268: in 
function 'phase_func'
           /data/apisix-2.10.1/apisix/plugin.lua:683: in function 'run_plugin'
           /data/apisix-2.10.1/apisix/init.lua:465: in function 
'http_access_phase'
           access_by_lua(nginx.conf:264):2: in main chunk, client: 127.0.0.1, 
server: _, request: "GET /index HTTP/1.1", host: "local.xsapp.org"
   
   
   --------- this is  my  traffic-split.lua
   198 local function new_rr_obj(weighted_upstreams)
   199     local server_list = {}
   200     -- 
core.log.error("---xs--upstream_obj:",core.json.delay_encode(weighted_upstreams,true))
   201     for i, upstream_obj in ipairs(weighted_upstreams) do
   202        core.log.error("---xs-- 
upstream_obj:",core.json.delay_encode(upstream_obj,true))
   203
   204        if upstream_obj.upstream_id then
   205             core.log.error("-----xs--- 
upstream_id:",upstream_obj.upstream_id)
   206             server_list[upstream_obj.upstream_id] = upstream_obj.weight
   207         elseif upstream_obj.upstream then
   208             -- Add a virtual id field to uniquely identify the upstream 
key.
   209             core.log.error("----xs--- upstream is not 
null:",tostring(upstream_obj.upstream))
   210             upstream_obj.upstream.vid = i
   211             server_list[upstream_obj.upstream] = upstream_obj.weight
   212         else
   213             -- If the upstream object has only the weight value, it means
   214             -- that the upstream weight value on the default route has 
been reached.
   215             -- Mark empty upstream services in the plugin.
   216             core.log.error("----xs--- all null")
   217             upstream_obj.upstream = "plugin#upstream#is#empty"
   218             server_list[upstream_obj.upstream] = upstream_obj.weight
   219
   220         end
   221     end
   222
   223     return roundrobin:new(server_list)
   224 end
   
   ------ some times,  the weighted_upstreams  value  is  differrent, if it is 
like the  second, it will  not  make err
   
1、weighted_upstreams:[{"upstream_id":"382981255605519758","weight":2},{"upstream":"plugin#upstream#is#empty","weight":1}],
   
2、weighted_upstreams:[{"upstream_id":"382981255605519758","weight":2},{"weight":1}]
   if  it like the first, the follow  code  will make  the error: 
   210             upstream_obj.upstream.vid = i
   
   
   ### Expected result
   
   do not  make error


-- 
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.

To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to