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

Support the random load balancing method #376

Merged
merged 1 commit into from
Sep 17, 2018

Conversation

eduardborges
Copy link
Contributor

Proposed changes

Add support for the new load balancing random algorithm

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto master
  • I will ensure my PR is targeting the master branch and pulling from my branch from my own fork

Copy link
Contributor

@pleshakov pleshakov left a comment

Choose a reason for hiding this comment

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

random algorithm is a bit more involved. take a look at http://nginx.org/en/docs/http/ngx_http_upstream_module.html#random it takes two additional parameters. It is important to consider those cases and validate them.

Copy link
Contributor

@pleshakov pleshakov left a comment

Choose a reason for hiding this comment

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

Please see my comments

@@ -10,6 +10,9 @@ func TestParseLBMethod(t *testing.T) {
{"least_conn", "least_conn"},
{"round_robin", ""},
{"ip_hash", "ip_hash"},
{"random", "random"},
{"random two", "random two"},
{"random two least_conn", "random two least_conn"},
{"hash $request_id", "hash $request_id"},
Copy link
Contributor

Choose a reason for hiding this comment

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

please also test for some of invalid input:
random one, random two ip_hash, random two least_time

{"random two", "random two"},
{"random two least_conn", "random two least_conn"},
{"random two least_time=header", "random two least_time=header"},
{"random two least_time=last_byte", "random two least_time=last_byte"},
Copy link
Contributor

Choose a reason for hiding this comment

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

please also test on some of invalid input:
random one
random two ip_hash"

func validateRandomLBMethodForPlus(method string) (string, error) {
keyWords := strings.Split(method, " ")
if keyWords[0] == "random" {
if len(keyWords) == 1 || len(keyWords) == 2 && keyWords[1] == "two" ||
Copy link
Contributor

Choose a reason for hiding this comment

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

since the total number of combinations for the random algorithms is small, I suggest to putting them in the nginxPlusLBValidInput map. This will simplify the code.

@@ -17,6 +17,10 @@ func ParseLBMethod(method string) (string, error) {
method, err := validateHashLBMethod(method)
return method, err
}
if strings.HasPrefix(method, "random") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest creating a map with valid input for NGINX OSS, similar to nginxPlusLBValidInput. It will include least_conn, ip_hash and combinations for the random method.

@pleshakov pleshakov changed the title Add support for the new load balancing random algorithm Support the random load balancing method Sep 17, 2018
Brings support for the random load balancing method -
http://nginx.org/en/docs/http/ngx_http_upstream_module.html#random
- added in NGINX OSS 1.15.1 and NGINX Plus R16.
@pleshakov pleshakov force-pushed the add-support-lb-random-algortihm branch from 312d362 to 0ea4885 Compare September 17, 2018 10:59
@pleshakov pleshakov merged commit 5c7be23 into master Sep 17, 2018
@pleshakov pleshakov deleted the add-support-lb-random-algortihm branch September 17, 2018 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants