Enhance Load-balancing method validation log.

This commit is contained in:
Ludovic Fernandez 2018-05-22 09:20:03 +02:00 committed by Traefiker Bot
parent 0ba28bbc8b
commit bc26d9f0de
2 changed files with 14 additions and 9 deletions

View file

@ -1438,7 +1438,7 @@ func configureBackends(backends map[string]*types.Backend) {
}
}
} else {
log.Debugf("Validation of load balancer method for backend %s failed: %s. Using default method wrr.", backendName, err)
log.Debugf("Backend %s: %v", backendName, err)
var stickiness *types.Stickiness
if backend.LoadBalancer != nil {

View file

@ -211,16 +211,21 @@ var loadBalancerMethodNames = []string{
// NewLoadBalancerMethod create a new LoadBalancerMethod from a given LoadBalancer.
func NewLoadBalancerMethod(loadBalancer *LoadBalancer) (LoadBalancerMethod, error) {
var method string
if loadBalancer != nil {
method = loadBalancer.Method
for i, name := range loadBalancerMethodNames {
if strings.EqualFold(name, method) {
return LoadBalancerMethod(i), nil
}
if loadBalancer == nil {
return Wrr, errors.New("no load-balancer defined, fallback to 'wrr' method")
}
if len(loadBalancer.Method) == 0 {
return Wrr, errors.New("no load-balancing method defined, fallback to 'wrr' method")
}
for i, name := range loadBalancerMethodNames {
if strings.EqualFold(name, loadBalancer.Method) {
return LoadBalancerMethod(i), nil
}
}
return Wrr, fmt.Errorf("invalid load-balancing method '%s'", method)
return Wrr, fmt.Errorf("invalid load-balancing method %q, fallback to 'wrr' method", loadBalancer.Method)
}
// Configurations is for currentConfigurations Map