Skip to content

Commit

Permalink
fix(api): add extra logging to file storage operations (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
fschuch authored Aug 20, 2024
1 parent b533521 commit 4086a25
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions jobbergate-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
19 changes: 13 additions & 6 deletions jobbergate-api/jobbergate_api/apps/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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:
"""
Expand Down
6 changes: 3 additions & 3 deletions jobbergate-api/jobbergate_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4086a25

Please sign in to comment.