Merge lp:~flacoste/launchpad/bug-721324 into lp:launchpad

Proposed by Francis J. Lacoste
Status: Merged
Approved by: Francis J. Lacoste
Approved revision: no longer in the source branch.
Merged at revision: 12419
Proposed branch: lp:~flacoste/launchpad/bug-721324
Merge into: lp:launchpad
Diff against target: 93 lines (+32/-2)
3 files modified
lib/canonical/config/schema-lazr.conf (+7/-0)
lib/canonical/launchpad/webapp/haproxy.py (+10/-2)
lib/canonical/launchpad/webapp/tests/test_haproxy.py (+15/-0)
To merge this branch: bzr merge lp:~flacoste/launchpad/bug-721324
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Benji York (community) code* Approve
Review via email: mp+50365@code.launchpad.net

Commit message

[r=bac,benji][bug=721324] Made the haproxy going down status configurable.

Description of the change

This branch makes the result code to return when the app server is going down
configurable through a config variable.

That's for the +haproxy monitoring URL. We were returning 500, but it's
possible that 404 results in better behavior from HAProxy. We have to test to
make sure, so I'm making this result code configurable.

I didn't use a feature flag to control this because we don't want the +haproxy
URL to hit the database. (It gets a special DB policy and a
NullFeatureController.)

Let me know if you have any questions.

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

This branch looks good. Approved (but I'm doing mentored reviews so
Brad will review my review before you get a full approval.)

I only have two small (ignorable) thoughts about the branch:

The comment about the default value being 500 in the docstring could
easily get out of sync with reality. Maybe we should point to the place
the default is configured instead.

The second is that perhaps the test should use an invalid status code
instead. I worry that someone might introduce a bug that would cause a
404 to be generated when requesting /+haproxy instead of the configured
value and the test wouldn't fail. Perhaps the test should configure the
status to be 999 just to be sure we're getting back the status we
configured and not one someone else is setting.

review: Approve (code*)
Revision history for this message
Robert Collins (lifeless) wrote :

I like your suggestion about the docstring Benji. There is already a test that 500 is returned by default - so the page is being tested with both 404 and 500 responses, so I think your second suggestion would be redundant.

Revision history for this message
Francis J. Lacoste (flacoste) wrote :

Thanks for the review.

I've pushed modifications for both comments and will wait for Brad's approval.

Revision history for this message
Brad Crittenden (bac) wrote :

As Robert said, the docstring comment was spot on. I notice there is another docstring for the __call__ method that mentions returning 200 or 500 and I think it should be updated similarly.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/config/schema-lazr.conf'
2--- lib/canonical/config/schema-lazr.conf 2011-02-18 00:14:02 +0000
3+++ lib/canonical/config/schema-lazr.conf 2011-02-21 18:25:28 +0000
4@@ -938,6 +938,13 @@
5 # datatype: int
6 port: 11371
7
8+[haproxy_status_view]
9+# Configuration for the +haproxy monitoring URL
10+
11+# Result code to return when the app server is going down.
12+# datatype: int
13+going_down_status: 500
14+
15 [initialisedistroseries]
16 dbuser: initialisedistroseries
17
18
19=== modified file 'lib/canonical/launchpad/webapp/haproxy.py'
20--- lib/canonical/launchpad/webapp/haproxy.py 2010-12-17 20:58:27 +0000
21+++ lib/canonical/launchpad/webapp/haproxy.py 2011-02-21 18:25:28 +0000
22@@ -11,6 +11,8 @@
23 'switch_going_down_flag',
24 ]
25
26+from canonical.config import config
27+
28 # This is the global flag, when this is True, the HAProxy view
29 # will return 500, it returns 200 otherwise.
30 going_down_flag = False
31@@ -46,6 +48,10 @@
32 restart them. The probe URL will then return 500 and the app server will
33 be taken out of rotation. Once HAProxy reports that all connections to the
34 app servers are finished, we can restart the server safely.
35+
36+ The returned result code when the server is going down can be configured
37+ through the haproxy_status_view.going_down_status configuration variable.
38+ It defaults to 500 (as set in lib/canonical/config/schema-lazr.conf).
39 """
40
41 def __init__(self, context, request):
42@@ -53,10 +59,12 @@
43 self.request = request
44
45 def __call__(self):
46- """Return 200 or 500 depending on the global flag."""
47+ """Return 200 or going down status depending on the global flag."""
48 global going_down_flag
49+
50 if going_down_flag:
51- self.request.response.setStatus(500)
52+ self.request.response.setStatus(
53+ config.haproxy_status_view.going_down_status)
54 return u"May day! May day! I'm going down. Stop the flood gate."
55 else:
56 self.request.response.setStatus(200)
57
58=== modified file 'lib/canonical/launchpad/webapp/tests/test_haproxy.py'
59--- lib/canonical/launchpad/webapp/tests/test_haproxy.py 2010-12-17 20:58:27 +0000
60+++ lib/canonical/launchpad/webapp/tests/test_haproxy.py 2011-02-21 18:25:28 +0000
61@@ -6,6 +6,9 @@
62 __metaclass__ = type
63 __all__ = []
64
65+from textwrap import dedent
66+
67+from canonical.config import config
68 from canonical.testing.layers import FunctionalLayer
69 from canonical.launchpad.webapp import haproxy
70 from canonical.launchpad.webapp.dbpolicy import (
71@@ -15,6 +18,7 @@
72 from canonical.launchpad.webapp.servers import LaunchpadTestRequest
73
74 from zope.app.testing.functional import HTTPCaller
75+
76 from lp.testing import TestCase
77
78
79@@ -47,3 +51,14 @@
80 self.assertEquals(False, haproxy.going_down_flag)
81 haproxy.switch_going_down_flag()
82 self.assertEquals(True, haproxy.going_down_flag)
83+
84+ def test_HAProxyStatusView_status_code_is_configurable(self):
85+ config.push('change_haproxy_status_code', dedent('''
86+ [haproxy_status_view]
87+ going_down_status: 499
88+ '''))
89+ self.addCleanup(config.pop, 'change_haproxy_status_code')
90+ haproxy.set_going_down_flag(True)
91+ result = self.http(u'GET /+haproxy HTTP/1.0', handle_errors=False)
92+ self.assertEquals(499, result.getStatus())
93+