autoland: Ensure heartbeat endpoints do not cache (Bug 1339175). r?mars draft
authorDavid Walsh <dwalsh@mozilla.com>
Mon, 13 Feb 2017 14:03:31 -0600
changeset 129 f0d19861b172aa9bf2545ba2824255ba0cfa0ad6
parent 123 c06dc77f392d03da275ff752f6bc002e73ade8f9
child 130 dc33bd67cfa72c6a0d27bdc88e6fe5f39e159fff
child 131 ba5e942691c188422666a955017e59191aa0646e
push id79
push userbmo:dwalsh@mozilla.com
push dateTue, 14 Feb 2017 01:06:09 +0000
reviewersmars
bugs1339175
autoland: Ensure heartbeat endpoints do not cache (Bug 1339175). r?mars MozReview-Commit-ID: I21V7QdZtMB
autoland/public-web-api/autolandweb/dockerflow.py
autoland/public-web-api/tests/test_dockerflow_container_api.py
--- a/autoland/public-web-api/autolandweb/dockerflow.py
+++ b/autoland/public-web-api/autolandweb/dockerflow.py
@@ -2,31 +2,39 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 import tornado.web
 
 
 class LoadBalancerHeartbeatHandler(tornado.web.RequestHandler):
     """Handler for Dockerflow __lbheartbeat__."""
 
+    def compute_etag(self):
+        return None
+
     async def get(self):
         """Perform health check for load balancer.
 
         Since this is for load balancer checks it should not check
         backing services.
         """
         self.write({})
         self.set_status(200)
+        self.set_header('Cache-Control', 'no-cache')
 
 
 class HeartbeatHandler(tornado.web.RequestHandler):
     """Handler for Dockerflow __heartbeat__."""
 
+    def compute_etag(self):
+        return None
+
     async def get(self):
         """Perform health check for autoland backend."""
         self.write({})
         self.set_status(200)
+        self.set_header('Cache-Control', 'no-cache')
 
 
 DOCKERFLOW_ROUTES = [
     (r'/__lbheartbeat__/?$', LoadBalancerHeartbeatHandler),
     (r'/__heartbeat__/?$', HeartbeatHandler),
 ]
--- a/autoland/public-web-api/tests/test_dockerflow_container_api.py
+++ b/autoland/public-web-api/tests/test_dockerflow_container_api.py
@@ -22,15 +22,19 @@ def app():
     return make_app(False)
 
 
 @pytest.mark.gen_test
 async def test_loadbalancer_heartbeat_returns_200(http_client, base_url):
     lb_heartbeat_url = base_url + '/__lbheartbeat__'
     response = await http_client.fetch(lb_heartbeat_url)
     assert response.code == 200
+    assert response.headers['Cache-Control'] == 'no-cache'
+    assert len(response.headers.get_list('Etag')) == 0
 
 
 @pytest.mark.gen_test
 async def test_heartbeat_returns_200(http_client, base_url):
     lb_heartbeat_url = base_url + '/__heartbeat__'
     response = await http_client.fetch(lb_heartbeat_url)
     assert response.code == 200
+    assert response.headers['Cache-Control'] == 'no-cache'
+    assert len(response.headers.get_list('Etag')) == 0