From 603d9c8941055885977144dbd1864341fcfffe3a Mon Sep 17 00:00:00 2001 From: Bobby Novak <176936850+rnovak338@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:50:14 -0400 Subject: [PATCH] Remove logged warnings for maintenance mode check Every time a request hits the app, a `MAINTENANCE_MODE` S3 warning is thrown when it is off. This is going to flood the logs with a not-so-needed warning. --- backend/config/middleware.py | 4 ++-- backend/dissemination/file_downloads.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/config/middleware.py b/backend/config/middleware.py index eb60a1e425..9952da41a9 100644 --- a/backend/config/middleware.py +++ b/backend/config/middleware.py @@ -12,7 +12,7 @@ def is_maintenance_on(): Get current status of maintenance mode. """ - return file_exists(S3_FILENAME) + return file_exists(S3_FILENAME, show_warning=False) def change_maintenance(enabled): @@ -37,7 +37,7 @@ def change_maintenance(enabled): # turn off. else: - if file_exists(S3_FILENAME): + if file_exists(S3_FILENAME, show_warning=False): s3_client.delete_object( Bucket=settings.AWS_PRIVATE_STORAGE_BUCKET_NAME, Key=S3_FILENAME ) diff --git a/backend/dissemination/file_downloads.py b/backend/dissemination/file_downloads.py index 5a22472f71..121464d4fb 100644 --- a/backend/dissemination/file_downloads.py +++ b/backend/dissemination/file_downloads.py @@ -38,7 +38,7 @@ def get_filename(report_id, file_type): raise Http404() -def file_exists(filename): +def file_exists(filename, show_warning=True): # this client uses the internal endpoint url because we're making a request to S3 from within the app s3_client = boto3_client( service_name="s3", @@ -57,7 +57,8 @@ def file_exists(filename): return True except ClientError: - logger.warn(f"Unable to locate file {filename} in S3!") + if show_warning: + logger.warn(f"Unable to locate file {filename} in S3!") return False