Add sticky support to DRR lb

This commit is contained in:
Owen Marshall 2016-05-26 13:38:55 -04:00 committed by Emile Vauge
parent dc52abf4ce
commit d78c419627
No known key found for this signature in database
GPG key ID: D808B4C167352E59

View file

@ -546,11 +546,21 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
} }
stickysession := configuration.Backends[frontend.Backend].LoadBalancer.Sticky stickysession := configuration.Backends[frontend.Backend].LoadBalancer.Sticky
if stickysession {
sticky := roundrobin.NewStickySession(cookiename)
cookiename := "_TRAEFIK_SERVERNAME"
}
switch lbMethod { switch lbMethod {
case types.Drr: case types.Drr:
log.Debugf("Creating load-balancer drr") log.Debugf("Creating load-balancer drr")
rebalancer, _ := roundrobin.NewRebalancer(rr, roundrobin.RebalancerLogger(oxyLogger)) if stickysession {
log.Debugf("... setting to sticky session with cookie named %v", cookiename)
rebalancer, _ := roundrobin.NewRebalancer(rr, roundrobin.RebalancerLogger(oxyLogger), roundrobin.RebalancerStickySession(sticky))
} else {
rebalancer, _ := roundrobin.NewRebalancer(rr, roundrobin.RebalancerLogger(oxyLogger))
}
lb = rebalancer lb = rebalancer
for serverName, server := range configuration.Backends[frontend.Backend].Servers { for serverName, server := range configuration.Backends[frontend.Backend].Servers {
url, err := url.Parse(server.URL) url, err := url.Parse(server.URL)
@ -570,9 +580,7 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
case types.Wrr: case types.Wrr:
log.Debugf("Creating load-balancer wrr") log.Debugf("Creating load-balancer wrr")
if stickysession { if stickysession {
cookiename := "_TRAEFIK_SERVERNAME"
log.Debugf("... setting to sticky session with cookie named %v", cookiename) log.Debugf("... setting to sticky session with cookie named %v", cookiename)
sticky := roundrobin.NewStickySession(cookiename)
rr, _ = roundrobin.New(saveBackend, roundrobin.EnableStickySession(sticky)) rr, _ = roundrobin.New(saveBackend, roundrobin.EnableStickySession(sticky))
} }
lb = rr lb = rr