Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1422: add BigQuery check to heartbeat #1516

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions telescope/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ async def lbheartbeat(request):
@routes.get("/__heartbeat__")
async def heartbeat(request):
checks = {}

# Check that `curl` has HTTP2 and HTTP3 for `checks.core.http_versions`
curl_cmd = subprocess.run(
[config.CURL_BINARY_PATH, "--version"],
Expand All @@ -228,8 +229,17 @@ async def heartbeat(request):
if not missing_features
else f"missing features {', '.join(missing_features)}"
)

# Bugzilla
bz_ping = await request.app["telescope.tracker"].ping()
checks["bugzilla"] = "ok" if bz_ping else "Bugzilla ping failed"

# Big Query
try:
checks["bigquery"] = (await utils.fetch_bigquery("SELECT 'ok';"))[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If bigquery is having an outage, this will also fail for us. Do we want this in our heartbeat because of that? Is there a way for us to check the exception to see if we received an auth error or a different error?

except Exception as exc:
checks["bigquery"] = str(exc)

status = 200 if all(v == "ok" for v in checks.values()) else 503
return web.json_response(checks, status=status)

Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from typing import List, Union
from unittest import mock

import pytest
import responses
Expand Down Expand Up @@ -58,6 +59,12 @@ def mock_aioresponses(cli):
yield m


@pytest.fixture
def mock_bigquery_client():
with mock.patch("telescope.utils.bigquery.Client") as mocked:
yield mocked


class ResponsesWrapper:
"""A tiny wrapper to mimic the aioresponses API."""

Expand Down
4 changes: 3 additions & 1 deletion tests/test_basic_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ async def test_lbheartbeat(cli):
assert response.status == 200


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

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

assert body["bugzilla"] == "ok"
assert body["bigquery"] == "bad credentials"
assert body["curl"] == "ok"
assert response.status == 200

Expand Down
Loading