Skip to content

Commit

Permalink
fix(healthz): do not warn about expected events
Browse files Browse the repository at this point in the history
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
`warn_missing=False`. Default behaviour doesn't change and will still
issue this warning.
  • Loading branch information
open-dynaMIX committed Sep 18, 2023
1 parent 1df85e2 commit f523a5d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion caluma/caluma_core/health_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, warn_missing=False)

return {"ok": True}

Expand Down
8 changes: 6 additions & 2 deletions caluma/caluma_form/storage_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, warn_missing=True):
"""
Get stat of object in bucket.
:param object_name: str
:param warn_missing: 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 warn_missing:
log.warning(
f"Minio error, cannot stat object '{object_name}': {exc.code}"
)
return None

@_retry_on_missing_bucket
Expand Down
4 changes: 4 additions & 0 deletions caluma/caluma_form/tests/test_minio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", warn_missing=False)
assert stat is None
assert len(caplog.messages) == 1

0 comments on commit f523a5d

Please sign in to comment.