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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job!
orange/plugins/balancer/handler.lua
Outdated
current_try.balancer_start = nil | ||
|
||
-- record overall latency | ||
ngx.ctx.KONG_BALANCER_TIME = (ngx.ctx.KONG_BALANCER_TIME or 0) + try_latency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KONG_BALANCER_TIME
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry about this typo
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
orange/orange.lua
Outdated
|
||
-- only care about upstreams stored in db | ||
if utils.hostnameType(hostname) == "name" then | ||
local upstreams = orange_db.get_json("balancer.selectors") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
orange/orange.lua
Outdated
name, port = hostname, 80 | ||
end | ||
|
||
if upstreams and type(upstreams) == "table" then |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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")) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
orange/utils/utils.lua
Outdated
-- @usage hostname_type("123.123.123.123") --> "ipv4" | ||
-- hostname_type("::1") --> "ipv6" | ||
-- hostname_type("some::thing") --> "ipv6", but invalid... | ||
function _M.hostnameType(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hostnameType
-> hostname_type
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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......:)
There was a problem hiding this comment.
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......
There was a problem hiding this comment.
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 ;)
There was a problem hiding this comment.
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 ;)
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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?
dynamic upstream is a plan in progressing for Orange v0.7. your pr could be a reference for this feature. in my plan, users should consider whether they should use anyway, feel free to give any advice or implementation for this feature. |
how to use ? |
if could combine this and divid upstream may be more better job ! 👍 |
@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 |
@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. |
i think no one will add same server to the same upstream :)
your design good ,i can set the upstream url by divid upstream plug 。 good!
…-----
http://blog.soul11201.com
2017-08-03 11:02 GMT+08:00 Zhao Junwang <notifications@github.com>:
@sumory <https://github.com/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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#138 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AIHtAOd-iKevG5kywVOtDTD9huIkzfGZks5sUTgsgaJpZM4Oq3ly>
.
|
i more like another commit !
…-----
http://blog.soul11201.com
2017-08-03 15:06 GMT+08:00 Zhao Junwang <notifications@github.com>:
***@***.**** commented on this pull request.
------------------------------
In orange/utils/utils.lua
<#138 (comment)>:
> @@ -193,6 +193,25 @@ function _M.load_module_if_exists(module_name)
end
end
+--- checks the hostname type; ipv4, ipv6, or name.
+-- Type is determined by exclusion, not by validation. So if it returns 'ipv6' then
+-- it can only be an ipv6, but it is not necessarily a valid ipv6 address.
+-- @param name the string to check (this may contain a portnumber)
+-- @return string either; 'ipv4', 'ipv6', or 'name'
+-- @Usage hostname_type("123.123.123.123") --> "ipv4"
+-- hostname_type("::1") --> "ipv6"
+-- hostname_type("some::thing") --> "ipv6", but invalid...
+function _M.hostnameType(name)
another question, do you prefer to use git commit --amend to address the
PR edit, or just another commit?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#138 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AIHtALjZxmLJXwPkmPZ14rjQ692DuC8vks5sUXF8gaJpZM4Oq3ly>
.
|
orange/utils/balancer.lua
Outdated
if not balancer then | ||
-- no balancer yet (or invalidated) so create a new one | ||
balancer, err = ring_balancer.new({ | ||
wheelsize = upstream.slots, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
good job |
when i visit uri: /balancer by pull this code, i got some exception ,and i saw 404 at the dashboard error.log/ |
@noname007 can you paste(make a gist or pastebin) the error, so i can have a look? |
|
@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. |
@zhjwpku 这个是在dashboard中打开balancer 图标时候发生的的。 |
@noname007 这个插件我们已经在用了,目前还没有遇到过你说的问题。我抽时间部署一台新的机器上试一下,之后给你结果~ |
Signed-off-by: Zhao Junwang <zhjwpku@gmail.com>
Signed-off-by: Zhao Junwang <zhjwpku@gmail.com>
thanks https://github.com/noname007 to point this ref: http://mashape.github.io/lua-resty-dns-client/modules/resty.dns.balancer.html#new 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>
Signed-off-by: Zhao Junwang <zhjwpku@gmail.com>
@noname007 我把代码调整了一下,另外写了一篇部署的文档 Orange Balancer 安装及使用,你看下是否能够解决你之前遇到的问题 |
would you please pull this pr to branch v0.7.0-dev? |
@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 ;) |
this feature has been merged into v0.7.0-dev branch. hope you will take more effort for v0.7.0 release. 😃 |
This is premature pull , hope to acquire some advice
Signed-off-by: Zhao Junwang zhjwpku@gmail.com