-
Notifications
You must be signed in to change notification settings - Fork 3
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
Support weighting #7
base: master
Are you sure you want to change the base?
Conversation
Sadly this is a breaking change for the existing library. It explicitly moves away from shared memory and does switch to a better round robin implementation. I would consider merging this PR in two different pieces:
Also, you should then update readme file, pointing out that your superior implementation is available from another include, meanwhile leaving the old implementation as backward compatible option. |
local address = s["Address"] ~= "" and s["Address"] or na | ||
local port = s["Port"] | ||
-- If the weight parameter fails to be obtained or is passed incorrectly, set it to 1 | ||
local weight = s["Weights"]["Passing"] or 1 |
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.
This lookup may unwind the stack if response structure does not contain 'Weight' key.
I could not determine which consul version added this field into the API response.
If this key aways exist, then the error handling part of the following code is unnecessary.
If this key exists only after some Consul version, then all clients using earlier version will stop functioning permanently.
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.
In order to solve the consul issues #1088 and 4198, the Weights
field was added in cosnul 1.2.3 version,See consul-1.2.3 AgentWeights and #4468.
Also, When I tested with Consul v1.4.0, the response will always have the Weights
field by default, whether or not I passed in the Weights
field when I signed up for the service.
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.
Then just as a precaution, slap in Readme that this new code only works with Consul >1.2.3 :)
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.
Ok, I'll add dependencies later.
_persist(service_name, service) | ||
local ok, err = balancer.set_current_peer(upstream["address"], upstream["port"]) | ||
local server = rr_up:find() | ||
local ok, err = balancer.set_current_peer(server) |
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 could not find firm proof that this function behaves correctly if passed a string containing ':' separated host/port pair.
I checked here: https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/balancer.md#set_current_peer
and here: https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/balancer.lua#L109
Please verify this by testing.
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.
The find()
method does return a string of ip:port
, and as you can see from the lua-resty-balancer example, the ip:port
string can be passed directly to the set_current_peer()
method as an argument.
After testing, it is feasible, it is possible that the set_current_peer()
method is internally compatible.
Sorry, I didn't take these into consideration. I will resubmit PR later. |
A new independent PR has been submitted to address the above issues. See #8 . |
完善 README.md,添加配置及依赖
while not ngx.worker.exiting() do
instead ofwhile true do
to fix the problem that "nginx worker: process is shutting down" process of nginx cannot shutdown when reload nginx.