Merge lp:~tvansteenburgh/charms/precise/haproxy/sticky-sessions into lp:charms/haproxy

Proposed by Tim Van Steenburgh
Status: Merged
Merged at revision: 78
Proposed branch: lp:~tvansteenburgh/charms/precise/haproxy/sticky-sessions
Merge into: lp:charms/haproxy
Diff against target: 69 lines (+19/-4)
3 files modified
config.yaml (+11/-2)
hooks/hooks.py (+3/-2)
tests/10_deploy_test.py (+5/-0)
To merge this branch: bzr merge lp:~tvansteenburgh/charms/precise/haproxy/sticky-sessions
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+216618@code.launchpad.net

Description of the change

Enable sticky sessions by default

To post a comment you must log in.
78. By Tim Van Steenburgh

Enable sticky sessions by default

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'config.yaml'
--- config.yaml 2014-01-07 18:44:15 +0000
+++ config.yaml 2014-04-30 21:49:17 +0000
@@ -101,8 +101,8 @@
101 - service_name: haproxy_service101 - service_name: haproxy_service
102 service_host: "0.0.0.0"102 service_host: "0.0.0.0"
103 service_port: 80103 service_port: 80
104 service_options: [balance leastconn]104 service_options: [balance leastconn, cookie SRVNAME insert]
105 server_options: maxconn 100105 server_options: maxconn 100 cookie S{i} check
106 type: string106 type: string
107 description: |107 description: |
108 Services definition(s). Although the variable type is a string, this is108 Services definition(s). Although the variable type is a string, this is
@@ -112,6 +112,15 @@
112 before the first variable, service_name, as above. Service options is a112 before the first variable, service_name, as above. Service options is a
113 comma separated list, server options will be appended as a string to113 comma separated list, server options will be appended as a string to
114 the individual server lines for a given listen stanza.114 the individual server lines for a given listen stanza.
115
116 If your web application serves dynamic content based on users' login
117 sessions, a visitor will experience unexpected behaviour if each request
118 is proxied to a different backend web server. Session stickiness ensures
119 that a visitor 'sticks' to the backend web server which served their
120 first request. This is made possible by tagging each backend server
121 with a cookie. Session are sticky by default. To turn off sticky sessions,
122 remove the 'cookie SRVNAME insert' and 'cookie S{i}' stanzas from
123 `service_options` and `server_options`.
115 sysctl:124 sysctl:
116 default: ""125 default: ""
117 type: string126 type: string
118127
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2014-01-21 15:46:29 +0000
+++ hooks/hooks.py 2014-04-30 21:49:17 +0000
@@ -298,8 +298,8 @@
298 service_config.append(298 service_config.append(
299 " errorfile %s %s" % (errorfile["http_status"], path))299 " errorfile %s %s" % (errorfile["http_status"], path))
300 if isinstance(server_entries, (list, tuple)):300 if isinstance(server_entries, (list, tuple)):
301 for (server_name, server_ip, server_port,301 for i, (server_name, server_ip, server_port,
302 server_options) in server_entries:302 server_options) in enumerate(server_entries):
303 server_line = " server %s %s:%s" % \303 server_line = " server %s %s:%s" % \
304 (server_name, server_ip, server_port)304 (server_name, server_ip, server_port)
305 if server_options is not None:305 if server_options is not None:
@@ -307,6 +307,7 @@
307 server_line += " " + server_options307 server_line += " " + server_options
308 else:308 else:
309 server_line += " " + " ".join(server_options)309 server_line += " " + " ".join(server_options)
310 server_line = server_line.format(i=i)
310 service_config.append(server_line)311 service_config.append(server_line)
311 return '\n'.join(service_config)312 return '\n'.join(service_config)
312313
313314
=== modified file 'tests/10_deploy_test.py'
--- tests/10_deploy_test.py 2014-01-24 16:57:20 +0000
+++ tests/10_deploy_test.py 2014-04-30 21:49:17 +0000
@@ -53,6 +53,11 @@
53page.raise_for_status()53page.raise_for_status()
54print('Successfully got the Apache2 web page through haproxy IP address.')54print('Successfully got the Apache2 web page through haproxy IP address.')
5555
56# Test that sticky session cookie is present
57if page.cookies.get('SRVNAME') != 'S0':
58 msg = 'Missing or invalid sticky session cookie value: %s' % page.cookies.get('SRVNAME')
59 amulet.raise_status(amulet.FAIL, msg=msg)
60
56# Test that the apache2 relation data is saved on the haproxy server.61# Test that the apache2 relation data is saved on the haproxy server.
5762
58# Get the sentry for apache and get the private IP address.63# Get the sentry for apache and get the private IP address.

Subscribers

People subscribed via source and target branches