From 4086a2515d59382ec7e37377ad36d4bb21dfe192 Mon Sep 17 00:00:00 2001 From: "Felipe N. Schuch" Date: Tue, 20 Aug 2024 14:55:20 -0300 Subject: [PATCH] fix(api): add extra logging to file storage operations (#600) --- jobbergate-api/CHANGELOG.md | 1 + .../jobbergate_api/apps/services.py | 19 +++++++++++++------ jobbergate-api/jobbergate_api/config.py | 6 +++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/jobbergate-api/CHANGELOG.md b/jobbergate-api/CHANGELOG.md index 76eebc60..7b2572fb 100644 --- a/jobbergate-api/CHANGELOG.md +++ b/jobbergate-api/CHANGELOG.md @@ -3,6 +3,7 @@ This file keeps track of all notable changes to jobbergate-api ## Unreleased +- Enhance logging for file storage operations ## 5.3.0a1 -- 2024-08-15 - Implemented an endpoint to fetch a cluster status by its client id [[PENG-2348](https://sharing.clickup.com/t/h/c/18022949/PENG-2348/QWZFBKV72ZNL293)] diff --git a/jobbergate-api/jobbergate_api/apps/services.py b/jobbergate-api/jobbergate_api/apps/services.py index 0b864033..b2aac003 100644 --- a/jobbergate-api/jobbergate_api/apps/services.py +++ b/jobbergate-api/jobbergate_api/apps/services.py @@ -597,7 +597,9 @@ async def upload_file_content( # Mypy doesn't like aioboto3 much await self.bucket.upload_fileobj(Fileobj=file_obj, Key=instance.file_key) # type: ignore except Exception as e: - message = f"Error uploading file {instance.filename} to {instance.file_key} -- {str(e)}" + message = "Error uploading file {} to {} on bucket {} -- {}".format( + instance.filename, instance.file_key, self.bucket.name, str(e) + ) logger.error(message) raise ServiceError( f"Error uploading file {instance.filename} to the file storage", @@ -637,12 +639,17 @@ async def copy_file_content(self, source_instance: FileModel, destination_instan Copy the content of a file from one instance to another. """ copy_source = {"Bucket": self.bucket.name, "Key": source_instance.file_key} - with handle_errors( - f"{self.model_type.__tablename__} file={source_instance.file_key} could not be copied", - raise_exc_class=ServiceError, - raise_kwargs=dict(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR), - ): + try: await self.bucket.copy(copy_source, destination_instance.file_key) + except Exception as e: + message = "Error copying file {} to {} on bucket {} -- {}".format( + source_instance.file_key, destination_instance.file_key, self.bucket.name, str(e) + ) + logger.error(message) + raise ServiceError( + f"Error copying file {source_instance.file_key} to the file storage", + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, + ) async def delete(self, instance: FileModel) -> None: """ diff --git a/jobbergate-api/jobbergate_api/config.py b/jobbergate-api/jobbergate_api/config.py index 20aa9f17..1e1e4b69 100644 --- a/jobbergate-api/jobbergate_api/config.py +++ b/jobbergate-api/jobbergate_api/config.py @@ -71,9 +71,9 @@ class Settings(BaseSettings): TEST_S3_ENDPOINT_URL: str = Field("http://localhost:9000") # RabbitMQ configuration - RABBITMQ_HOST: Optional[str] - RABBITMQ_USERNAME: Optional[str] - RABBITMQ_PASSWORD: Optional[str] + RABBITMQ_HOST: Optional[str] = None + RABBITMQ_USERNAME: Optional[str] = None + RABBITMQ_PASSWORD: Optional[str] = None RABBITMQ_DEFAULT_EXCHANGE: str = "default" # Security Settings. For details, see https://github.com/omnivector-solutions/armasec