From b747c1f6d89932f16d65a495bf213156982e4542 Mon Sep 17 00:00:00 2001 From: Fabio Ambauen Date: Mon, 18 Sep 2023 08:30:05 +0200 Subject: [PATCH] fix(healthz): do not warn about expected events As part of the health-check routines, a file is removed in minio and afterwards it's asserted that the file is gone. This call to `Minio.stat_object()` led to a warning being issued during every health-check iteration like the following: ``` Minio error, cannot stat object 'healthz_tmp-object_{UUID}': NoSuchKey ``` This commit extends `Minio.stat_object()`, so that issuing of the log-warning can be suppressed by profiding the argument `suppress_warning=True`. Default behaviour doesn't change and will still issue this warning. --- caluma/caluma_core/health_checks.py | 2 +- caluma/caluma_form/storage_clients.py | 8 ++++++-- caluma/caluma_form/tests/test_minio.py | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/caluma/caluma_core/health_checks.py b/caluma/caluma_core/health_checks.py index 9d36547b2..c8e13d8e4 100644 --- a/caluma/caluma_core/health_checks.py +++ b/caluma/caluma_core/health_checks.py @@ -58,7 +58,7 @@ def _check_media_storage_service(): # remove object storage_client.remove_object(object_name) - assert not storage_client.stat_object(object_name) + assert not storage_client.stat_object(object_name, suppress_warning=True) return {"ok": True} diff --git a/caluma/caluma_form/storage_clients.py b/caluma/caluma_form/storage_clients.py index d6400a015..541cdc0f9 100644 --- a/caluma/caluma_form/storage_clients.py +++ b/caluma/caluma_form/storage_clients.py @@ -71,17 +71,21 @@ def __init__(self): self.bucket = settings.MINIO_STORAGE_MEDIA_BUCKET_NAME @_retry_on_missing_bucket - def stat_object(self, object_name): + def stat_object(self, object_name, suppress_warning=False): """ Get stat of object in bucket. :param object_name: str + :param suppress_warning: bool :return: stat response if successful, otherwise None """ try: return self.client.stat_object(self.bucket, object_name) except S3Error as exc: - log.warning(f"Minio error, cannot stat object '{object_name}': {exc.code}") + if not suppress_warning: + log.warning( + f"Minio error, cannot stat object '{object_name}': {exc.code}" + ) return None @_retry_on_missing_bucket diff --git a/caluma/caluma_form/tests/test_minio.py b/caluma/caluma_form/tests/test_minio.py index 530f9968f..1dda0bb97 100644 --- a/caluma/caluma_form/tests/test_minio.py +++ b/caluma/caluma_form/tests/test_minio.py @@ -104,3 +104,7 @@ def test_minio_handle_exceptions(exc_code, caplog, mocker): assert caplog.messages == [ f"Minio error, cannot stat object 'test_object': {exc_code}" ] + assert len(caplog.messages) == 1 + stat = client.stat_object("test_object", suppress_warning=True) + assert stat is None + assert len(caplog.messages) == 1