{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/bouncer/pulls/comments/39982939","id":39982939,"diff_hunk":"@@ -0,0 +1,33 @@\n+module Bouncer\n+  module Outcome\n+    class Canary < Base\n+      HEADERS = {\n+        'Content-Type' => 'text/plain',\n+        # FIXME: stop this being overridden by our cacher middleware:\n+        'Cache-Control' => 'private'\n+      }\n+\n+      def serve\n+        if can_select_from_required_tables?","path":"lib/bouncer/outcome/canary.rb","position":11,"original_position":11,"commit_id":"d2e2e018812324d91f3859a601d2a6b5c5ab5bc5","original_commit_id":"d2e2e018812324d91f3859a601d2a6b5c5ab5bc5","user":{"login":"jennyd","id":1822424,"avatar_url":"https://avatars.githubusercontent.com/u/1822424?v=3","gravatar_id":"","url":"https://api.github.com/users/jennyd","html_url":"https://github.com/jennyd","followers_url":"https://api.github.com/users/jennyd/followers","following_url":"https://api.github.com/users/jennyd/following{/other_user}","gists_url":"https://api.github.com/users/jennyd/gists{/gist_id}","starred_url":"https://api.github.com/users/jennyd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jennyd/subscriptions","organizations_url":"https://api.github.com/users/jennyd/orgs","repos_url":"https://api.github.com/users/jennyd/repos","events_url":"https://api.github.com/users/jennyd/events{/privacy}","received_events_url":"https://api.github.com/users/jennyd/received_events","type":"User","site_admin":false},"body":"The queries in `can_select_from_required_tables?` will raise exceptions if the `bouncer` role doesn't have permission to SELECT from the database, so relying on its truthiness here isn't enough to return 503. We should handle the exceptions explicitly instead.\r\n\r\nIf the database (or just the `hosts` table) is entirely unavailable then an exception will be raised even earlier, at the point where the first query in `RequestContext` is invoked by the [first line in the `case` in `Bouncer::App`](https://github.com/alphagov/bouncer/blob/bdf9e139084ed4dd2c63403646ce92feff3c3721/lib/bouncer/app.rb#L11). In that case the response will still be 500 rather than 503 (for every request, not just the canary URL). I think that's OK - the different responses might even be helpful in tracking down the cause of the errors. We do incur the overhead of unhandled exceptions killing unicorns and having to fork new workers, rather than the exceptions being handled in-process, but that's already the case now.","created_at":"2015-09-21T15:16:57Z","updated_at":"2015-09-21T15:16:57Z","html_url":"https://github.com/alphagov/bouncer/pull/132#discussion_r39982939","pull_request_url":"https://api.github.com/repos/alphagov/bouncer/pulls/132","_links":{"self":{"href":"https://api.github.com/repos/alphagov/bouncer/pulls/comments/39982939"},"html":{"href":"https://github.com/alphagov/bouncer/pull/132#discussion_r39982939"},"pull_request":{"href":"https://api.github.com/repos/alphagov/bouncer/pulls/132"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/bouncer/pulls/132","id":45532980,"html_url":"https://github.com/alphagov/bouncer/pull/132","diff_url":"https://github.com/alphagov/bouncer/pull/132.diff","patch_url":"https://github.com/alphagov/bouncer/pull/132.patch","issue_url":"https://api.github.com/repos/alphagov/bouncer/issues/132","number":132,"state":"open","locked":false,"title":"Canary route","user":{"login":"tommyp","id":449004,"avatar_url":"https://avatars.githubusercontent.com/u/449004?v=3","gravatar_id":"","url":"https://api.github.com/users/tommyp","html_url":"https://github.com/tommyp","followers_url":"https://api.github.com/users/tommyp/followers","following_url":"https://api.github.com/users/tommyp/following{/other_user}","gists_url":"https://api.github.com/users/tommyp/gists{/gist_id}","starred_url":"https://api.github.com/users/tommyp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tommyp/subscriptions","organizations_url":"https://api.github.com/users/tommyp/orgs","repos_url":"https://api.github.com/users/tommyp/repos","events_url":"https://api.github.com/users/tommyp/events{/privacy}","received_events_url":"https://api.github.com/users/tommyp/received_events","type":"User","site_admin":false},"body":"If Bouncer goes down outside normal working hours, the people on call should be notified. The app and the check should also be documented in the opsmanual so that they are able to take appropriate action if necessary.\r\n\r\nThis PR adds a canary route at `/__canary__` which checks to see if it can select from 3 of the tables. If any of these 3 checks throw an error or can't connect, we return a `503`. [Ticket](https://trello.com/c/FrsSm5oK/69-alert-out-of-hours-if-bouncer-is-down).\r\n\r\nOriginal work done by @jennyd. Props to her for starting and helping me with this. ✊✊✊✊✊","created_at":"2015-09-21T10:26:27Z","updated_at":"2015-09-21T15:16:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"29607680c43a079c7d675a9dbbbb1f4de7417038","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/bouncer/pulls/132/commits","review_comments_url":"https://api.github.com/repos/alphagov/bouncer/pulls/132/comments","review_comment_url":"https://api.github.com/repos/alphagov/bouncer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/bouncer/issues/132/comments","statuses_url":"https://api.github.com/repos/alphagov/bouncer/statuses/d2e2e018812324d91f3859a601d2a6b5c5ab5bc5","head":{"label":"alphagov:canary","ref":"canary","sha":"d2e2e018812324d91f3859a601d2a6b5c5ab5bc5","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":11175369,"name":"bouncer","full_name":"alphagov/bouncer","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/bouncer","description":"A Rack-based redirector for sites which have moved to GOV.UK","fork":false,"url":"https://api.github.com/repos/alphagov/bouncer","forks_url":"https://api.github.com/repos/alphagov/bouncer/forks","keys_url":"https://api.github.com/repos/alphagov/bouncer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/bouncer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/bouncer/teams","hooks_url":"https://api.github.com/repos/alphagov/bouncer/hooks","issue_events_url":"https://api.github.com/repos/alphagov/bouncer/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/bouncer/events","assignees_url":"https://api.github.com/repos/alphagov/bouncer/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/bouncer/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/bouncer/tags","blobs_url":"https://api.github.com/repos/alphagov/bouncer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/bouncer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/bouncer/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/bouncer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/bouncer/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/bouncer/languages","stargazers_url":"https://api.github.com/repos/alphagov/bouncer/stargazers","contributors_url":"https://api.github.com/repos/alphagov/bouncer/contributors","subscribers_url":"https://api.github.com/repos/alphagov/bouncer/subscribers","subscription_url":"https://api.github.com/repos/alphagov/bouncer/subscription","commits_url":"https://api.github.com/repos/alphagov/bouncer/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/bouncer/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/bouncer/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/bouncer/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/bouncer/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/bouncer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/bouncer/merges","archive_url":"https://api.github.com/repos/alphagov/bouncer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/bouncer/downloads","issues_url":"https://api.github.com/repos/alphagov/bouncer/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/bouncer/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/bouncer/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/bouncer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/bouncer/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/bouncer/releases{/id}","created_at":"2013-07-04T11:45:30Z","updated_at":"2015-03-09T15:21:14Z","pushed_at":"2015-09-21T10:26:27Z","git_url":"git://github.com/alphagov/bouncer.git","ssh_url":"git@github.com:alphagov/bouncer.git","clone_url":"https://github.com/alphagov/bouncer.git","svn_url":"https://github.com/alphagov/bouncer","homepage":"","size":2647,"stargazers_count":2,"watchers_count":2,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":2,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"bdf9e139084ed4dd2c63403646ce92feff3c3721","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":11175369,"name":"bouncer","full_name":"alphagov/bouncer","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/bouncer","description":"A Rack-based redirector for sites which have moved to GOV.UK","fork":false,"url":"https://api.github.com/repos/alphagov/bouncer","forks_url":"https://api.github.com/repos/alphagov/bouncer/forks","keys_url":"https://api.github.com/repos/alphagov/bouncer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/bouncer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/bouncer/teams","hooks_url":"https://api.github.com/repos/alphagov/bouncer/hooks","issue_events_url":"https://api.github.com/repos/alphagov/bouncer/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/bouncer/events","assignees_url":"https://api.github.com/repos/alphagov/bouncer/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/bouncer/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/bouncer/tags","blobs_url":"https://api.github.com/repos/alphagov/bouncer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/bouncer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/bouncer/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/bouncer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/bouncer/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/bouncer/languages","stargazers_url":"https://api.github.com/repos/alphagov/bouncer/stargazers","contributors_url":"https://api.github.com/repos/alphagov/bouncer/contributors","subscribers_url":"https://api.github.com/repos/alphagov/bouncer/subscribers","subscription_url":"https://api.github.com/repos/alphagov/bouncer/subscription","commits_url":"https://api.github.com/repos/alphagov/bouncer/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/bouncer/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/bouncer/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/bouncer/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/bouncer/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/bouncer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/bouncer/merges","archive_url":"https://api.github.com/repos/alphagov/bouncer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/bouncer/downloads","issues_url":"https://api.github.com/repos/alphagov/bouncer/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/bouncer/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/bouncer/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/bouncer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/bouncer/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/bouncer/releases{/id}","created_at":"2013-07-04T11:45:30Z","updated_at":"2015-03-09T15:21:14Z","pushed_at":"2015-09-21T10:26:27Z","git_url":"git://github.com/alphagov/bouncer.git","ssh_url":"git@github.com:alphagov/bouncer.git","clone_url":"https://github.com/alphagov/bouncer.git","svn_url":"https://github.com/alphagov/bouncer","homepage":"","size":2647,"stargazers_count":2,"watchers_count":2,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/bouncer/pulls/132"},"html":{"href":"https://github.com/alphagov/bouncer/pull/132"},"issue":{"href":"https://api.github.com/repos/alphagov/bouncer/issues/132"},"comments":{"href":"https://api.github.com/repos/alphagov/bouncer/issues/132/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/bouncer/pulls/132/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/bouncer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/bouncer/pulls/132/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/bouncer/statuses/d2e2e018812324d91f3859a601d2a6b5c5ab5bc5"}}}}