orange icon indicating copy to clipboard operation
orange copied to clipboard

no new() function in random.lua,which is balancer plugin require

Open liulei18 opened this issue 5 years ago • 2 comments

Version

v0.7.0

Description

to archive dynamic upstream

Plugin

balancer plugin & divide plugin

Configuration

  • the configuration as same as 安装和使用文档可参考Orange Balancer 安装及使用 ,this is the guide doc in orange/orange/plugins/balancer/README.md
  • nginx.conf
upstream hello {
    server 127.0.0.1;
    balancer_by_lua_block {
        local orange = context.orange
        orange.balancer()
    }
}

    # test server 1
    server {
        listen 8881;

        location / {
            content_by_lua_block {
                ngx.say("8881")
            }
        }
    }

    # test server 2
    server {
        listen 8882;

        location / {
            content_by_lua_block {
                ngx.say("8882")
            }
        }
    }

    # test server 3
    server {
        listen 8883;

        location / {
            content_by_lua_block {
                ngx.say("8883")
            }
        }
    }

    server {
        listen 80;

        location /balancer {
                rewrite_by_lua_block {
                        local orange = context.orange
                        orange.redirect()
                        orange.rewrite()
                }

                access_by_lua_block {
                        local orange = context.orange
                        orange.access()
                }

                # proxy
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection $connection_upgrade;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Scheme $scheme;
                proxy_pass $upstream_url;

                header_filter_by_lua_block {
                        local orange = context.orange
                        orange.header_filter()
                }

                body_filter_by_lua_block {
                        local orange = context.orange
                        orange.body_filter()
                }
                log_by_lua_block {
                        local orange = context.orange
                        orange.log()
                }
        }
    }
  • balancer image

  • divide image

Execute

  • curl 'http://ip:port/balancer'

Error Log

2019/07/16 16:48:14 [error] 389667#0: *20 lua entry thread aborted: runtime error: ./lualib/resty/dns/balancer.lua:1027: attempt to call field 'new' (a nil value)
stack traceback:
coroutine 0:
	./lualib/resty/dns/balancer.lua: in function 'randomlist'
	./lualib/resty/dns/balancer.lua:1129: in function 'new'
	/usr/local/orange/orange/utils/balancer.lua:145: in function 'get_balancer'
	/usr/local/orange/orange/utils/balancer.lua:241: in function 'balancer_execute'
	/usr/local/orange/orange/plugins/balancer/handler.lua:95: in function 'access'
	/usr/local/orange/orange/orange.lua:166: in function 'access'
	access_by_lua(orange.conf:669):3: in function <access_by_lua(orange.conf:669):1>, client: 192.168.90.26, server: orange.com, request: "GET /balancer HTTP/1.1", host: "orange.com"

Solution

  • I install third-party packages as required according to README.md like this
#opm --install-dir=./ get zhangbao0325/orangelib      //opm download the 3rd packages
  • i read the source code in lualib/resty/dns/balancer.lua
local lrandom = require "random"
local function randomlist(size)
 xxxx
 ........
  local randomizer = lrandom.new(158841259)
  ........
  xxxx
end
  • According to the error log, i find the reason. according to above order installs package has a problem in lualib/resty/random.lua, no new() function in random.lua

  • where can i find correct random.lua file,can you give me some suggestion? hope for your answer. thanks @zhangbao0325 @zhjwpku

liulei18 avatar Jul 16 '19 10:07 liulei18

  • balancer plugin is dependent on lua-resty-dns-client libary. and this isssue has solved by @Tieske,the contributor of Kong.
  • here are the steps to solve the problem 1 rm the file /usr/local/orange/lualib/resty/random.lua. random.lua is downloaded by opm --install-dir=./ get zhangbao0325/orangelib 2 Install dependencies by luarocks install lrandom
  • if you want see more details, see also https://github.com/Kong/lua-resty-dns-client/issues/71#issuecomment-511929529
  • i suggest you to remove random.lua in zhangbao0325/orangelib and add luarocks install lrandom into README.md @zhangbao0325

liulei18 avatar Jul 18 '19 10:07 liulei18

I feel sorry for causing your confusion and trouble , and I have confirmed this problem . So I update zhangbao0325/orangelib again and modified the README.md. Thank you again and wait for your more suggestions.

zhangbao0325 avatar Jul 18 '19 19:07 zhangbao0325