Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 1d40dfa

Browse files
fix: improve new minio implementation (#546)
* feat: remove usage of use_minio feature flag this rollout is done and we are 100% enabled on prod so we are safe to remove this and simplify the logic starting off by removing all references to use_minio in shared * fix: improve new minio implementation The team mentioned wanting to ship the new read implementation first then the new write implementation so this commit enables that. i'm folding the NewMinioStorageService functionality back into the MinioStorageService and creating 2 new feature flags one for read and one for write. Based on the values of those feature flags the MinioStorageService will choose an implementation of read/write. I also removed the old USE_NEW_MINIO feature flag, and modified the get_appropriate_storage_service function to make it so it no longer caches the MinioStorageService and instead the MinioStorageService is caching its internal minio_client since that is the expensive part of creating a new MinioStorageService instance. I also moved some code around * fix: address feedback
1 parent e46c3ca commit 1d40dfa

File tree

10 files changed

+453
-729
lines changed

10 files changed

+453
-729
lines changed

shared/rollouts/features.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
BUNDLE_THRESHOLD_FLAG = Feature("bundle_threshold_flag")
44
INCLUDE_GITHUB_COMMENT_ACTIONS_BY_OWNER = Feature("include_github_comment_actions")
5-
USE_NEW_MINIO = Feature("use_new_minio")
6-
USE_MINIO = Feature("use_minio")
5+
NEW_MINIO = Feature("new_minio")

shared/storage/__init__.py

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,24 @@
1+
from typing import Literal, cast
2+
13
from shared.config import get_config
2-
from shared.rollouts.features import USE_MINIO, USE_NEW_MINIO
3-
from shared.storage.aws import AWSStorageService
4+
from shared.rollouts.features import NEW_MINIO
45
from shared.storage.base import BaseStorageService
5-
from shared.storage.fallback import StorageWithFallbackService
6-
from shared.storage.gcp import GCPStorageService
76
from shared.storage.minio import MinioStorageService
8-
from shared.storage.new_minio import NewMinioStorageService
9-
10-
_storage_service_cache: dict[str, BaseStorageService] = {}
117

128

139
def get_appropriate_storage_service(
1410
repoid: int | None = None,
1511
force_minio=False,
1612
) -> BaseStorageService:
17-
chosen_storage: str = get_config("services", "chosen_storage", default="minio") # type: ignore
18-
if force_minio:
19-
chosen_storage = "minio"
20-
13+
minio_config = get_config("services", "minio", default={})
2114
if repoid:
22-
if USE_MINIO.check_value(repoid, default=False):
23-
chosen_storage = "minio"
24-
25-
if USE_NEW_MINIO.check_value(repoid, default=False):
26-
chosen_storage = "new_minio"
27-
28-
if chosen_storage not in _storage_service_cache:
29-
_storage_service_cache[chosen_storage] = (
30-
_get_appropriate_storage_service_given_storage(chosen_storage)
15+
new_minio_mode = cast(
16+
Literal["read", "write"] | None,
17+
NEW_MINIO.check_value(repoid, default=None), # type: ignore
18+
)
19+
return MinioStorageService(
20+
minio_config,
21+
new_mode=new_minio_mode,
3122
)
32-
33-
return _storage_service_cache[chosen_storage]
34-
35-
36-
def _get_appropriate_storage_service_given_storage(
37-
chosen_storage: str,
38-
) -> BaseStorageService:
39-
if chosen_storage == "gcp":
40-
gcp_config = get_config("services", "gcp", default={})
41-
return GCPStorageService(gcp_config)
42-
elif chosen_storage == "aws":
43-
aws_config = get_config("services", "aws", default={})
44-
return AWSStorageService(aws_config)
45-
elif chosen_storage == "gcp_with_fallback":
46-
gcp_config = get_config("services", "gcp", default={})
47-
gcp_service = GCPStorageService(gcp_config)
48-
aws_config = get_config("services", "aws", default={})
49-
aws_service = AWSStorageService(aws_config)
50-
return StorageWithFallbackService(gcp_service, aws_service)
51-
elif chosen_storage == "new_minio":
52-
minio_config = get_config("services", "minio", default={})
53-
return NewMinioStorageService(minio_config)
5423
else:
55-
minio_config = get_config("services", "minio", default={})
5624
return MinioStorageService(minio_config)

shared/storage/compression.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import gzip
2+
import importlib.metadata
3+
from typing import IO
4+
5+
6+
class GZipStreamReader:
7+
def __init__(self, fileobj: IO[bytes]):
8+
self.data = fileobj
9+
10+
def read(self, size: int = -1, /) -> bytes:
11+
curr_data = self.data.read(size)
12+
13+
if not curr_data:
14+
return b""
15+
16+
return gzip.compress(curr_data)
17+
18+
19+
def zstd_decoded_by_default() -> bool:
20+
try:
21+
version = importlib.metadata.version("urllib3")
22+
except importlib.metadata.PackageNotFoundError:
23+
return False
24+
25+
if version < "2.0.0":
26+
return False
27+
28+
distribution = importlib.metadata.metadata("urllib3")
29+
if requires_dist := distribution.get_all("Requires-Dist"):
30+
for req in requires_dist:
31+
if "[zstd]" in req:
32+
return True
33+
34+
return False

0 commit comments

Comments
 (0)