Skip to content

Commit

Permalink
refactor: replace with weaker health check
Browse files Browse the repository at this point in the history
  • Loading branch information
DecFox committed Aug 10, 2024
1 parent 02a7d86 commit bc8f2c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
23 changes: 11 additions & 12 deletions ooniapi/services/oonifindings/src/oonifindings/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,24 @@ async def health(
errors = []

try:
db.query(models.OONIFinding).limit(1).all()
db.query(models.OONIFinding).limit(1).all()
except Exception as exc:
log.error(exc)
errors.append("db_error")
log.error(exc)
errors.append("db_error")

if settings.jwt_encryption_key == "CHANGEME":
err = "bad_jwt_secret"
log.error(err)
errors.append(err)
err = "bad_jwt_secret"
log.error(err)
errors.append(err)

if settings.prometheus_metrics_password == "CHANGEME":
err = "bad_prometheus_password"
log.error(err)
errors.append(err)

if len(errors) > 0:
raise HTTPException(status_code=400, detail="health check failed")
err = "bad_prometheus_password"
log.error(err)
errors.append(err)

status = "ok"
if len(errors) > 0:
status = "fail"

return {
"status": status,
Expand Down
7 changes: 4 additions & 3 deletions ooniapi/services/oonifindings/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ def test_health_good(client):
assert len(j["errors"]) == 0, j


# TODO(decfox): have a stronger health check test
def test_health_bad(client_with_bad_settings):
r = client_with_bad_settings.get("health")
j = r.json()
assert j["detail"] == "health check failed", j
assert r.status_code == 400
assert r.status_code == 200
assert j["status"] == "fail", j


def test_metrics(client):
r = client.get("/metrics")
client.get("/metrics")


@pytest.mark.asyncio
Expand Down

0 comments on commit bc8f2c9

Please sign in to comment.