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

Proposed by Tim Van Steenburgh on 2014-04-21
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 2014-04-21 Approve on 2014-04-30
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 on 2014-04-30

Enable sticky sessions by default

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
1=== modified file 'config.yaml'
2--- config.yaml 2014-01-07 18:44:15 +0000
3+++ config.yaml 2014-04-30 21:49:17 +0000
4@@ -101,8 +101,8 @@
5 - service_name: haproxy_service
6 service_host: "0.0.0.0"
7 service_port: 80
8- service_options: [balance leastconn]
9- server_options: maxconn 100
10+ service_options: [balance leastconn, cookie SRVNAME insert]
11+ server_options: maxconn 100 cookie S{i} check
12 type: string
13 description: |
14 Services definition(s). Although the variable type is a string, this is
15@@ -112,6 +112,15 @@
16 before the first variable, service_name, as above. Service options is a
17 comma separated list, server options will be appended as a string to
18 the individual server lines for a given listen stanza.
19+
20+ If your web application serves dynamic content based on users' login
21+ sessions, a visitor will experience unexpected behaviour if each request
22+ is proxied to a different backend web server. Session stickiness ensures
23+ that a visitor 'sticks' to the backend web server which served their
24+ first request. This is made possible by tagging each backend server
25+ with a cookie. Session are sticky by default. To turn off sticky sessions,
26+ remove the 'cookie SRVNAME insert' and 'cookie S{i}' stanzas from
27+ `service_options` and `server_options`.
28 sysctl:
29 default: ""
30 type: string
31
32=== modified file 'hooks/hooks.py'
33--- hooks/hooks.py 2014-01-21 15:46:29 +0000
34+++ hooks/hooks.py 2014-04-30 21:49:17 +0000
35@@ -298,8 +298,8 @@
36 service_config.append(
37 " errorfile %s %s" % (errorfile["http_status"], path))
38 if isinstance(server_entries, (list, tuple)):
39- for (server_name, server_ip, server_port,
40- server_options) in server_entries:
41+ for i, (server_name, server_ip, server_port,
42+ server_options) in enumerate(server_entries):
43 server_line = " server %s %s:%s" % \
44 (server_name, server_ip, server_port)
45 if server_options is not None:
46@@ -307,6 +307,7 @@
47 server_line += " " + server_options
48 else:
49 server_line += " " + " ".join(server_options)
50+ server_line = server_line.format(i=i)
51 service_config.append(server_line)
52 return '\n'.join(service_config)
53
54
55=== modified file 'tests/10_deploy_test.py'
56--- tests/10_deploy_test.py 2014-01-24 16:57:20 +0000
57+++ tests/10_deploy_test.py 2014-04-30 21:49:17 +0000
58@@ -53,6 +53,11 @@
59 page.raise_for_status()
60 print('Successfully got the Apache2 web page through haproxy IP address.')
61
62+# Test that sticky session cookie is present
63+if page.cookies.get('SRVNAME') != 'S0':
64+ msg = 'Missing or invalid sticky session cookie value: %s' % page.cookies.get('SRVNAME')
65+ amulet.raise_status(amulet.FAIL, msg=msg)
66+
67 # Test that the apache2 relation data is saved on the haproxy server.
68
69 # Get the sentry for apache and get the private IP address.

Subscribers

People subscribed via source and target branches