Skip to content

Commit 17ffb13

Browse files
authored
Merge pull request #1137 from rkevin-arch/healthcheck-head-request
Allow head requests for the health endpoint
2 parents b81d913 + ecde6b4 commit 17ffb13

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

binderhub/health.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,12 @@ async def check_pod_quota(self):
151151
}
152152
return usage
153153

154-
async def get(self):
154+
async def check_all(self):
155+
"""Runs all health checks and returns a tuple (overall, checks).
156+
157+
`overall` is a bool representing the overall status of the service
158+
`checks` contains detailed information on each check's result
159+
"""
155160
checks = []
156161
check_futures = []
157162

@@ -176,7 +181,15 @@ async def get(self):
176181
overall = all(
177182
check["ok"] for check in checks if check["service"] != "Pod quota"
178183
)
184+
return overall, checks
185+
186+
async def get(self):
187+
overall, checks = await self.check_all()
179188
if not overall:
180189
self.set_status(503)
181-
182190
self.write({"ok": overall, "checks": checks})
191+
192+
async def head(self):
193+
overall, checks = await self.check_all()
194+
if not overall:
195+
self.set_status(503)

binderhub/tests/test_health.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ async def test_basic_health(app):
2727
quota_check["total_pods"]
2828
== quota_check["build_pods"] + quota_check["user_pods"]
2929
)
30+
31+
# HEAD requests should work as well
32+
r = await async_requests.head(app.url + "/health")
33+
assert r.status_code == 200

0 commit comments

Comments
 (0)