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

feat: add redis liveness probe #699

Merged
merged 12 commits into from Jul 12, 2023
Merged
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 24 additions & 2 deletions flexmeasures/api/v3_0/health.py
Expand Up @@ -2,6 +2,8 @@
from flask_classful import FlaskView, route
from flask_json import as_json


from redis.exceptions import ConnectionError
from flexmeasures.data import db


Expand All @@ -14,6 +16,18 @@ def _check_sql_database():
return False


def _check_redis() -> bool:
"""Check status of the redis instance

:return: True if the redis instance is active, False otherwise
"""
try:
current_app.redis_connection.ping()
return True
except ConnectionError:
return False


class HealthAPI(FlaskView):

route_base = "/health"
Expand All @@ -32,11 +46,19 @@ def is_ready(self):
.. sourcecode:: json

{
'database_sql': True
'database_sql': True,
'database_redis': False
}

"""
status = {"database_sql": _check_sql_database()} # TODO: check redis

status = {
"database_sql": _check_sql_database(),
}

if current_app.config.get("FLEXMEASURES_REDIS_PASSWORD") is not None:
status["database_redis"] = _check_redis()

if all(status.values()):
return status, 200
else:
Expand Down