-
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
67 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,15 @@ | ||
from flask_healthz import HealthError | ||
from sqlalchemy.exc import OperationalError | ||
|
||
from mirrormanager2.database import DB | ||
|
||
|
||
def liveness(): | ||
pass | ||
|
||
|
||
def readiness(): | ||
try: | ||
DB.manager.get_status() | ||
except OperationalError as err: | ||
raise HealthError("Can't connect to the database") from err |
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,24 @@ | ||
import os | ||
|
||
from mirrormanager2.app import create_app | ||
|
||
|
||
def test_healthz_readiness_ok(client): | ||
result = client.get("/healthz/ready") | ||
assert result.status_code == 200 | ||
|
||
|
||
def test_healthz_readiness_not_ok(app): | ||
here = os.path.dirname(os.path.abspath(__file__)) | ||
app = create_app( | ||
{ | ||
"TESTING": True, | ||
# Set fake database | ||
"SQLALCHEMY_DATABASE_URI": "sqlite:///I/don't/exist.sqlite", | ||
"OIDC_CLIENT_SECRETS": os.path.join(here, "client_secrets.json"), | ||
"USE_FEDORA_MESSAGING": False, | ||
} | ||
) | ||
client = app.test_client() | ||
result = client.get("/healthz/ready") | ||
assert result.status_code != 200 |