Skip to content
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

port kong's ring-balancer to orange #138

Merged
merged 9 commits into from Nov 24, 2017
Merged

port kong's ring-balancer to orange #138

merged 9 commits into from Nov 24, 2017

Conversation

zhjwpku
Copy link
Collaborator

@zhjwpku zhjwpku commented Aug 2, 2017

This is premature pull , hope to acquire some advice

Signed-off-by: Zhao Junwang zhjwpku@gmail.com

Copy link
Collaborator

@sumory sumory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job!

current_try.balancer_start = nil

-- record overall latency
ngx.ctx.KONG_BALANCER_TIME = (ngx.ctx.KONG_BALANCER_TIME or 0) + try_latency
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KONG_BALANCER_TIME?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry about this typo

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if one peer down why not change another peer(rule)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sure i understand your mean, if one peer down, the balancer() will be called again due to the set_more_tries() methods, actually the whole balancer_by_lua will be called again, see https://groups.google.com/d/msg/openresty-en/iCUSw-dxOek/jX6rh2ecBQAJ


-- only care about upstreams stored in db
if utils.hostnameType(hostname) == "name" then
local upstreams = orange_db.get_json("balancer.selectors")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is balancer.selectors initialized?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

balancer.selectors will be initialized in Orange.init like other plugins. I want the balancer to reuse the selector and rules structure(upstream => selector, hosts => rules), this will make life easier.

you can see the balancer data structure here: https://gist.github.com/zhjwpku/ea6c9036897217abe1f50532b415f93c

name, port = hostname, 80
end

if upstreams and type(upstreams) == "table" then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better that we replace these logic into plugin balancer's access method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, definitely yes!

local common_api = require("orange.plugins.common_api")

local api = BaseAPI:new("balancer-api", 2)
api:merge_apis(common_api("balancer"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's probably not compatible with the common_api

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this, working on this

-- @usage hostname_type("123.123.123.123") --> "ipv4"
-- hostname_type("::1") --> "ipv6"
-- hostname_type("some::thing") --> "ipv6", but invalid...
function _M.hostnameType(name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hostnameType -> hostname_type

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I will change the style

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another style is you need indent 4 spaces......:)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use editorconfig to control this style problems......

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will change that.

btw, I use vim (:%s/ / /g) to do the trick ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, the white space is striped, :%s/__/____/g, take _ as whitespace ;)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

welcome to join the qq group 522410959 :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another question, do you prefer to use git commit --amend to address the PR edit, or just another commit?

@sumory
Copy link
Collaborator

sumory commented Aug 2, 2017

dynamic upstream is a plan in progressing for Orange v0.7. your pr could be a reference for this feature.

in my plan, dynamic upstream should be implemented as a plugin which would not break any current feature or usages such as divide upstream plugin.

users should consider whether they should use divide upstream or dynamic upstream by themselves. we'd better not restrict this point.

anyway, feel free to give any advice or implementation for this feature.

@noname007
Copy link
Collaborator

how to use ?

@noname007
Copy link
Collaborator

noname007 commented Aug 3, 2017

if could combine this and divid upstream may be more better job ! 👍

@zhjwpku
Copy link
Collaborator Author

zhjwpku commented Aug 3, 2017

@noname007 this feature uses mashape's ring-balancer, https://github.com/Mashape/lua-resty-dns-client, so that should be installed first.

$ luarocks install lua-resty-dns-client
$ luarocks install penlight

@zhjwpku
Copy link
Collaborator Author

zhjwpku commented Aug 3, 2017

@sumory in my current design, I am doing the dynamic upstream at the end of access context, at this time, the upstream_url has been already set. I handled with the upstream_url to see whether this is a upstream stored in the database, if it is, proxy_pass to the orange_upstream, otherwise it will remain its original target.

I like your proposal about implements this in a separate plugin, just one concern: what if we have same rules in both plugins? Not sure about this, just think it might be a little complicated to make sure the user won't add same rule in both plugins.

@noname007
Copy link
Collaborator

noname007 commented Aug 3, 2017 via email

@noname007 noname007 changed the base branch from master to v0.7.0-dev August 3, 2017 07:04
@noname007
Copy link
Collaborator

noname007 commented Aug 3, 2017 via email

if not balancer then
-- no balancer yet (or invalidated) so create a new one
balancer, err = ring_balancer.new({
wheelsize = upstream.slots,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhjwpku
Copy link
Collaborator Author

zhjwpku commented Aug 9, 2017

@sumory @noname007 Hi guys, please review the UI part, I am not good at JavaScript, sorry if I made some mistakes :)

-- modified by zhjwpku@github

local orange_db = require "orange.store.orange_db"
local pl_tablex = require "pl.tablex"
Copy link
Collaborator

@noname007 noname007 Aug 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"pl.tablex" what's this? please give a way to solve this kind of deps

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'd better not import such dependencies like penlight for now

@orangle
Copy link

orangle commented Sep 1, 2017

good job

@noname007
Copy link
Collaborator

noname007 commented Nov 6, 2017

when i visit uri: /balancer by pull this code, i got some exception ,and i saw 404 at the dashboard error.log/

@zhjwpku
Copy link
Collaborator Author

zhjwpku commented Nov 7, 2017

@noname007 can you paste(make a gist or pastebin) the error, so i can have a look?

@noname007
Copy link
Collaborator

@zhjwpku

2017/11/06 22:52:23 [error] 62058#0: *38 [lua] server.lua:59: func(): 404! not found., client: 127.0.0.1, server: , request: "GET /balancer/selectors?_=1509979943518 HTTP/1.1", host: "127.0.0.1:9999", referrer: "http://127.0.0.1:9999/balancer"

@zhjwpku
Copy link
Collaborator Author

zhjwpku commented Nov 7, 2017

@noname007 pls double check the file orange/plugins/balancer/api.lua is there. I am not sure what your codebase is, can you push your working space code to a git branch so we can discuss the code. Sorry about the trouble.

@noname007
Copy link
Collaborator

noname007 commented Nov 7, 2017

@zhjwpku
github上 pull request的代码实际上是有一个分支的,把git配置好后,就能获取到你pr的代码。因此和你pr的代码是一致的。检查到api.lua 文件也是存在的。

这个是在dashboard中打开balancer 图标时候发生的的。
看这个错误,可能是是没有路由到。不知道是不是你有什么配置。

@zhjwpku
Copy link
Collaborator Author

zhjwpku commented Nov 7, 2017

@noname007 这个插件我们已经在用了,目前还没有遇到过你说的问题。我抽时间部署一台新的机器上试一下,之后给你结果~

Signed-off-by: Zhao Junwang <zhjwpku@gmail.com>
Signed-off-by: Zhao Junwang <zhjwpku@gmail.com>
Signed-off-by: Zhao Junwang <zhjwpku@gmail.com>
Signed-off-by: Zhao Junwang <zhjwpku@gmail.com>
This bug cause the divde plugin not work, since for every none
balancer request, the request has an addition `http://`

Signed-off-by: Zhao Junwang <zhjwpku@gmail.com>
Signed-off-by: Zhao Junwang <zhjwpku@gmail.com>
Signed-off-by: Zhao Junwang <zhjwpku@gmail.com>
@zhjwpku
Copy link
Collaborator Author

zhjwpku commented Nov 16, 2017

@noname007 我把代码调整了一下,另外写了一篇部署的文档 Orange Balancer 安装及使用,你看下是否能够解决你之前遇到的问题

@sumory
Copy link
Collaborator

sumory commented Nov 24, 2017

would you please pull this pr to branch v0.7.0-dev?

@zhjwpku
Copy link
Collaborator Author

zhjwpku commented Nov 24, 2017

@sumory sorry but as far as i can see, the destination branch is already v0.7.0-dev, teach me how if i am wrong ;)

@sumory sumory merged commit 2b67d35 into orlabs:v0.7.0-dev Nov 24, 2017
@sumory
Copy link
Collaborator

sumory commented Nov 24, 2017

this feature has been merged into v0.7.0-dev branch. hope you will take more effort for v0.7.0 release. 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants