S3 Storage: Use STANDARD tier for small objects (#4453)

This commit is contained in:
Shuchang Zheng
2026-01-14 15:22:01 -08:00
committed by GitHub
parent 6c9703b9f3
commit 7dcfa00508
2 changed files with 14 additions and 4 deletions

View File

@@ -113,7 +113,7 @@ class S3Storage(BaseStorage):
uri = uri.replace(f".{file_ext}", f".{file_ext}.zst")
artifact.uri = uri
sc = await self._get_storage_class_for_org(artifact.organization_id, self.bucket)
sc = await self._get_storage_class_for_org(artifact.organization_id, self.bucket, len(data))
tags = await self._get_tags_for_org(artifact.organization_id)
LOG.debug(
"Storing artifact",
@@ -125,7 +125,12 @@ class S3Storage(BaseStorage):
)
await self.async_client.upload_file(uri, data, storage_class=sc, tags=tags)
async def _get_storage_class_for_org(self, organization_id: str, bucket: str) -> S3StorageClass:
async def _get_storage_class_for_org(
self,
organization_id: str,
bucket: str,
object_size_bytes: int | None = None,
) -> S3StorageClass:
return S3StorageClass.STANDARD
async def _get_tags_for_org(self, organization_id: str) -> dict[str, str]:
@@ -147,7 +152,7 @@ class S3Storage(BaseStorage):
return await self.async_client.create_presigned_urls([artifact.uri for artifact in artifacts])
async def store_artifact_from_path(self, artifact: Artifact, path: str) -> None:
sc = await self._get_storage_class_for_org(artifact.organization_id, self.bucket)
sc = await self._get_storage_class_for_org(artifact.organization_id, self.bucket, os.path.getsize(path))
tags = await self._get_tags_for_org(artifact.organization_id)
LOG.debug(
"Storing artifact from path",

View File

@@ -36,7 +36,12 @@ class S3StorageForTests(S3Storage):
async def _get_tags_for_org(self, organization_id: str) -> dict[str, str]:
return {"dummy": f"org-{organization_id}", "test": "jerry"}
async def _get_storage_class_for_org(self, organization_id: str, bucket: str) -> S3StorageClass:
async def _get_storage_class_for_org(
self,
organization_id: str,
bucket: str,
object_size_bytes: int | None = None,
) -> S3StorageClass:
return S3StorageClass.ONEZONE_IA