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

Change the default load balancing method to least_conn #274

Merged
merged 2 commits into from
Apr 20, 2018

Conversation

Dean-Coakley
Copy link
Contributor

@Dean-Coakley Dean-Coakley commented Apr 19, 2018

  • Update default lb-method to be least_conn
  • Add lb-method test
  • Update documentation links
  • Reject "" lb-method annotation

Tested on both NGINX and NGINX Plus

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

@@ -39,7 +39,7 @@ The table below summarizes all of the options. For some of them, there are examp
| N/A | `http-snippets` | Sets a custom snippet in http context. | N/A | |
| `nginx.org/location-snippets` | `location-snippets` | Sets a custom snippet in location context. | N/A | |
| `nginx.org/server-snippets` | `server-snippets` | Sets a custom snippet in server context. | N/A | |
| `nginx.org/lb-method` | `lb-method` | Sets the [load balancing method](https://www.nginx.com/resources/admin-guide/load-balancer/#method). The default `""` specifies the round-robin method. | `""` | |
| `nginx.org/lb-method` | `lb-method` | Sets the [load balancing method](http://nginx.org/en/docs/http/load_balancing.html#nginx_load_balancing_methods). The default `""` specifies the `least_conn` method. | `""` | |
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to use this link -- https://docs.nginx.com/nginx/admin-guide/load-balancer/http-load-balancer/#choosing-a-load-balancing-method
Please mention: To use the round-robin method, specify round_robin. Remove "The default "" specifies the least_conn method"
Also, add least_conn to the default column.

@@ -45,6 +45,7 @@ data:
if ($new_uri) {
rewrite ^ $new_uri permanent;
}
lb-method: "" # default is least_conn. Sets the load balancing method for upstreams. See http://nginx.org/en/docs/http/load_balancing.html#nginx_load_balancing_methods
Copy link
Contributor

Choose a reason for hiding this comment

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

ingCfg.LBMethod = lbMethod
if cnf.isPlus() {
if parsedMethod, err := ParseLBMethodForPlus(lbMethod); err != nil {
glog.Errorf("Ingress %s/%s: Invalid value for the nginx.org/lb-method: got %q", ingEx.Ingress.GetNamespace(), ingEx.Ingress.GetName(), lbMethod)
Copy link
Contributor

Choose a reason for hiding this comment

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

could you print the returned err in the logs?

glog.Errorf("Ingress %s/%s: Invalid value for the nginx.org/lb-method: got %q", ingEx.Ingress.GetNamespace(), ingEx.Ingress.GetName(), lbMethod)

to

glog.Errorf("Ingress %s/%s: Invalid value for the nginx.org/lb-method, got %q: %v", ingEx.Ingress.GetNamespace(), ingEx.Ingress.GetName(), lbMethod, err)

Please do that here in Configurator and also in Controller

if method == "round_robin" {
return "", nil
}
if method == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should treat "" as an invalid value.

if method == "least_conn" || method == "ip_hash" {
return method, nil
}
return "", fmt.Errorf("Invalid load balancing method: %v", method)
Copy link
Contributor

Choose a reason for hiding this comment

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

change %v to %q here and in the other places in this file

input string
expected string
}{
{"", "least_conn"},
Copy link
Contributor

Choose a reason for hiding this comment

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

we should treat "" as an invalid value

@pleshakov pleshakov merged commit 4d337d4 into nginxinc:master Apr 20, 2018
@Dean-Coakley Dean-Coakley deleted the lb-method branch April 20, 2018 11:10
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.

2 participants