-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add health check endpoint at /api/healthz (#128)
- Loading branch information
1 parent
5f14922
commit 51ab8c9
Showing
4 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from typing import Any | ||
|
||
from flask import Blueprint | ||
from sqlalchemy import text | ||
|
||
from api.extensions import db | ||
|
||
bp_name = "api-health-check" | ||
bp_url_prefix = "/api/healthz" | ||
bp = Blueprint(bp_name, __name__, url_prefix=bp_url_prefix) | ||
|
||
|
||
@bp.route("", methods=["GET"]) | ||
def health_check() -> Any: | ||
try: | ||
db.session.execute(text("SELECT 1")) | ||
except Exception as e: | ||
return {"status": "error", "error": str(e)}, 500 | ||
|
||
return {"status": "ok"}, 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from flask import Flask, url_for | ||
from flask.testing import FlaskClient | ||
from flask_sqlalchemy import SQLAlchemy | ||
|
||
|
||
def test_health_check(app: Flask, client: FlaskClient, db: SQLAlchemy) -> None: | ||
# test unauthenticated requests by setting the current user email to "Unauthenticated" | ||
app.config["CURRENT_OKTA_USER_EMAIL"] = "Unauthenticated" | ||
|
||
# test 200 | ||
health_check_url = url_for("api-health-check.health_check") | ||
rep = client.get(health_check_url) | ||
assert rep.status_code == 200 |