-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added health checks with flask-healthz
Resolves: #352 Signed-off-by: Riccardi Dalexis <[email protected]>
- Loading branch information
Showing
6 changed files
with
68 additions
and
5 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
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,19 @@ | ||
from flask_healthz import HealthError | ||
from sqlalchemy_helpers import DatabaseStatus | ||
|
||
from mirrormanager2.database import DB | ||
|
||
|
||
def liveness(): | ||
pass | ||
|
||
|
||
def readiness(): | ||
try: | ||
status = DB.manager.get_status() | ||
except Exception as e: | ||
raise HealthError(f"Can't get the database status: {e}") from e | ||
if status is DatabaseStatus.NO_INFO: | ||
raise HealthError("Can't connect to the database") | ||
if status is DatabaseStatus.UPGRADE_AVAILABLE: | ||
raise HealthError("The database schema needs to be updated") |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,21 @@ | ||
from alembic import command | ||
|
||
from mirrormanager2.database import DB | ||
|
||
|
||
def test_healthz_readiness_ok(client, db): | ||
result = client.get("/healthz/ready") | ||
assert result.status_code == 200 | ||
|
||
|
||
def test_healthz_readiness_not_ok_when_old_schema(client, db): | ||
command.downgrade(DB.manager.alembic_cfg, "-1") | ||
|
||
result = client.get("/healthz/ready") | ||
assert result.status_code != 200 | ||
assert "The database schema needs to be updated" in result.get_data(as_text=True) | ||
|
||
|
||
def test_healthz_readiness_not_ok(client): | ||
result = client.get("/healthz/ready") | ||
assert result.status_code != 200 |