From d78c419627c27b37a941c4aed1c82bb449a3d8bf Mon Sep 17 00:00:00 2001 From: Owen Marshall Date: Thu, 26 May 2016 13:38:55 -0400 Subject: [PATCH] Add sticky support to DRR lb --- server.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server.go b/server.go index ab51614c5..d8c728c2b 100644 --- a/server.go +++ b/server.go @@ -546,11 +546,21 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo } stickysession := configuration.Backends[frontend.Backend].LoadBalancer.Sticky + if stickysession { + sticky := roundrobin.NewStickySession(cookiename) + cookiename := "_TRAEFIK_SERVERNAME" + + } switch lbMethod { case types.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 for serverName, server := range configuration.Backends[frontend.Backend].Servers { url, err := url.Parse(server.URL) @@ -570,9 +580,7 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo case types.Wrr: log.Debugf("Creating load-balancer wrr") if stickysession { - cookiename := "_TRAEFIK_SERVERNAME" log.Debugf("... setting to sticky session with cookie named %v", cookiename) - sticky := roundrobin.NewStickySession(cookiename) rr, _ = roundrobin.New(saveBackend, roundrobin.EnableStickySession(sticky)) } lb = rr