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

Commit bde3364

Browse files
committed
Remove uploads in Redis code
I changed the code in API to store uploads into GCS directly instead of redis in codecov/codecov-api#960. Since then, the code to download from redis and write to GCS in worker became obsolete, so lets remove it.
1 parent 8d10492 commit bde3364

File tree

4 files changed

+14
-74
lines changed

4 files changed

+14
-74
lines changed

services/archive.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ def write_file(
8686
) -> None:
8787
"""
8888
Writes a generic file to the archive -- it's typically recommended to
89-
not use this in lieu of the convenience methods write_raw_upload and
90-
write_chunks
89+
not use this in lieu of the convenience method `write_chunks`
9190
"""
9291
self.storage.write_file(
9392
self.root,
@@ -97,29 +96,6 @@ def write_file(
9796
is_already_gzipped=is_already_gzipped,
9897
)
9998

100-
def write_raw_upload(
101-
self, commit_sha, report_id, data, *, is_already_gzipped=False
102-
) -> str:
103-
"""
104-
Convenience write method, writes a raw upload to a destination.
105-
Returns the path it writes.
106-
"""
107-
# create a custom report path for a raw upload.
108-
# write the file.
109-
path = "/".join(
110-
(
111-
"v4/raw",
112-
self.get_now().strftime("%Y-%m-%d"),
113-
self.storage_hash,
114-
commit_sha,
115-
"%s.txt" % report_id,
116-
)
117-
)
118-
119-
self.write_file(path, data, is_already_gzipped=is_already_gzipped)
120-
121-
return path
122-
12399
def write_computed_comparison(self, comparison, data) -> str:
124100
path = MinioEndpoints.computed_comparison.get_path(
125101
version="v4", repo_hash=self.storage_hash, comparison_id=comparison.id

services/redis.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import logging
2-
import zlib
3-
from typing import Optional
42

53
from redis import Redis
64
from shared.config import get_config
@@ -24,15 +22,3 @@ def get_redis_connection() -> Redis:
2422

2523
def _get_redis_instance_from_url(url) -> Redis:
2624
return Redis.from_url(url)
27-
28-
29-
def download_archive_from_redis(
30-
redis_connection: Redis, redis_key: str
31-
) -> Optional[str]:
32-
raw_uploaded_report = redis_connection.get(redis_key)
33-
gzipped = redis_key.endswith("/gzip")
34-
if gzipped:
35-
raw_uploaded_report = zlib.decompress(raw_uploaded_report, zlib.MAX_WBITS | 16)
36-
if raw_uploaded_report is not None:
37-
return raw_uploaded_report.decode()
38-
return None

tasks/tests/integration/test_upload_e2e.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def write_raw_upload(
3333
upload_json: dict | None = None,
3434
):
3535
report_id = uuid4().hex
36-
written_path = archive_service.write_raw_upload(commitid, report_id, contents)
36+
written_path = f"upload/{report_id}.txt"
37+
archive_service.write_file(written_path, contents)
3738

3839
upload_json = upload_json or {}
3940
upload_json.update({"reportid": report_id, "url": written_path})

tasks/upload.py

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@
3232
from helpers.github_installation import get_installation_name_for_owner_for_task
3333
from helpers.save_commit_error import save_commit_error
3434
from rollouts import NEW_TA_TASKS
35-
from services.archive import ArchiveService
3635
from services.bundle_analysis.report import BundleAnalysisReportService
3736
from services.processing.state import ProcessingState
3837
from services.processing.types import UploadArguments
39-
from services.redis import download_archive_from_redis, get_redis_connection
38+
from services.redis import get_redis_connection
4039
from services.report import (
4140
BaseReportService,
4241
NotReadyToBuildReportYetError,
@@ -164,38 +163,14 @@ def arguments_list(self):
164163
for arg in arguments:
165164
yield orjson.loads(arg)
166165

167-
def normalize_arguments(self, commit: Commit, arguments: UploadArguments):
168-
"""
169-
Normalizes and validates the argument list from the user.
170166

171-
Does things like:
172-
173-
- replacing a redis-stored value with a storage one (by doing an upload)
174-
- Removing unnecessary sensitive information for the arguments
175-
"""
176-
commit_sha = commit.commitid
177-
reportid = arguments.get("reportid")
178-
if redis_key := arguments.pop("redis_key", None):
179-
archive_service = ArchiveService(commit.repository)
180-
content = download_archive_from_redis(self.redis_connection, redis_key)
181-
written_path = archive_service.write_raw_upload(
182-
commit_sha, reportid, content
183-
)
184-
log.info(
185-
"Writing report content from redis to storage",
186-
extra=dict(path=written_path),
187-
)
188-
arguments["url"] = written_path
189-
arguments.pop("token", None)
190-
191-
flags: list | str | None = arguments.get("flags")
192-
if not flags:
193-
flags = []
194-
elif isinstance(flags, str):
195-
flags = [flag.strip() for flag in flags.split(",")]
196-
arguments["flags"] = flags
197-
198-
return arguments
167+
def normalize_flags(arguments: UploadArguments):
168+
flags: list | str | None = arguments.get("flags")
169+
if not flags:
170+
flags = []
171+
elif isinstance(flags, str):
172+
flags = [flag.strip() for flag in flags.split(",")]
173+
arguments["flags"] = flags
199174

200175

201176
def _should_debounce_processing(upload_context: UploadContext) -> Optional[float]:
@@ -605,7 +580,9 @@ def _possibly_create_uploads_to_insert(
605580
upload_flag_map: dict[Upload, list | str | None] = {}
606581

607582
for arguments in upload_context.arguments_list():
608-
arguments = upload_context.normalize_arguments(commit, arguments)
583+
arguments.pop("token", None)
584+
normalize_flags(arguments)
585+
609586
if "upload_id" not in arguments:
610587
upload = report_service.create_report_upload(arguments, commit_report)
611588
arguments["upload_id"] = upload.id_

0 commit comments

Comments
 (0)