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: allow setting Redis connection options #304

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The following health checks are bundled with this project:
- AWS S3 storage
- Celery task queue
- Celery ping
- Redis
- RabbitMQ
- Migrations

Expand Down Expand Up @@ -111,6 +112,8 @@ on django.conf.settings with the required format to connect to your redis server

REDIS_URL = redis://localhost:6370

Additional connection options may be specified by defining a variable ``HEALTHCHECK_REDIS_URL_OPTIONS`` on the settings module.

Setting up monitoring
---------------------

Expand Down
18 changes: 18 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,21 @@ Using `django.settings` you may exert more fine-grained control over the behavio
- Number
- 3
- Specifies the maximum total time for a task to complete and return a result, including queue time.

Redis Health Check
------------------

The Redis health check allows customising the underlying connection:

.. list-table:: Additional Settings
:widths: 25 10 10 55
:header-rows: 1

* - Name
- Type
- Default
- Description
* - `HEALTHCHECK_REDIS_URL_OPTIONS`
- Dict
- {}
- Additional arguments which will be passed as keyword arguments to the Redis connection class initialiser.
3 changes: 2 additions & 1 deletion health_check/contrib/redis/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class RedisHealthCheck(BaseHealthCheckBackend):
"""Health check for Redis."""

redis_url = getattr(settings, "REDIS_URL", 'redis://localhost/1')
redis_url_options = getattr(settings, "HEALTHCHECK_REDIS_URL_OPTIONS", {})

def check_status(self):
"""Check Redis service by pinging the redis instance with a redis connection."""
Expand All @@ -21,7 +22,7 @@ def check_status(self):
logger.debug("Attempting to connect to redis...")
try:
# conn is used as a context to release opened resources later
with from_url(self.redis_url) as conn:
with from_url(self.redis_url, **self.redis_url_options) as conn:
conn.ping() # exceptions may be raised upon ping
except ConnectionRefusedError as e:
self.add_error(ServiceUnavailable("Unable to connect to Redis: Connection was refused."), e)
Expand Down