Skip to content

Commit 52c1de3

Browse files
committed
Fix #1422: add BigQuery check to heartbeat
1 parent ba8b8ac commit 52c1de3

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

telescope/app.py

+10
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ async def lbheartbeat(request):
216216
@routes.get("/__heartbeat__")
217217
async def heartbeat(request):
218218
checks = {}
219+
219220
# Check that `curl` has HTTP2 and HTTP3 for `checks.core.http_versions`
220221
curl_cmd = subprocess.run(
221222
[config.CURL_BINARY_PATH, "--version"],
@@ -228,8 +229,17 @@ async def heartbeat(request):
228229
if not missing_features
229230
else f"missing features {', '.join(missing_features)}"
230231
)
232+
233+
# Bugzilla
231234
bz_ping = await request.app["telescope.tracker"].ping()
232235
checks["bugzilla"] = "ok" if bz_ping else "Bugzilla ping failed"
236+
237+
# Big Query
238+
try:
239+
checks["bigquery"] = (await utils.fetch_bigquery("SELECT 'ok';"))[0]
240+
except Exception as exc:
241+
checks["bigquery"] = str(exc)
242+
233243
status = 200 if all(v == "ok" for v in checks.values()) else 503
234244
return web.json_response(checks, status=status)
235245

tests/conftest.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from typing import List, Union
3+
from unittest import mock
34

45
import pytest
56
import responses
@@ -58,6 +59,12 @@ def mock_aioresponses(cli):
5859
yield m
5960

6061

62+
@pytest.fixture
63+
def mock_bigquery_client():
64+
with mock.patch("telescope.utils.bigquery.Client") as mocked:
65+
yield mocked
66+
67+
6168
class ResponsesWrapper:
6269
"""A tiny wrapper to mimic the aioresponses API."""
6370

tests/test_basic_endpoints.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ async def test_lbheartbeat(cli):
3333
assert response.status == 200
3434

3535

36-
async def test_heartbeat(cli, config, mock_aioresponses):
36+
async def test_heartbeat(cli, config, mock_aioresponses, mock_bigquery_client):
3737
config.BUGTRACKER_URL = "http://bugzilla.local"
3838
mock_aioresponses.get(
3939
config.BUGTRACKER_URL + "/rest/whoami", payload={"name": "foo"}
4040
)
41+
mock_bigquery_client.return_value.query.side_effect = ValueError("bad credentials")
4142

4243
response = await cli.get("/__heartbeat__")
4344
body = await response.json()
4445

4546
assert body["bugzilla"] == "ok"
47+
assert body["bigquery"] == "bad credentials"
4648
assert body["curl"] == "ok"
4749
assert response.status == 200
4850

0 commit comments

Comments
 (0)