Skip to content

Commit

Permalink
Revert "Make session.id == upload.id (#713)"
Browse files Browse the repository at this point in the history
This reverts commit b110b7f.
  • Loading branch information
Swatinem committed Sep 18, 2024
1 parent b110b7f commit 52dc6c2
Show file tree
Hide file tree
Showing 9 changed files with 264 additions and 123 deletions.
64 changes: 64 additions & 0 deletions helpers/parallel_upload_processing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,68 @@
import copy

import sentry_sdk
from shared.utils.sessions import SessionType

from database.models.reports import Upload


# Copied from shared/reports/resources.py Report.next_session_number()
def next_session_number(session_dict):
start_number = len(session_dict)
while start_number in session_dict or str(start_number) in session_dict:
start_number += 1

Check warning on line 13 in helpers/parallel_upload_processing.py

View check run for this annotation

Codecov Notifications / codecov/patch

helpers/parallel_upload_processing.py#L13

Added line #L13 was not covered by tests
return start_number


# Copied and cut down from worker/services/report/raw_upload_processor.py
# this version stripped out all the ATS label stuff
def _adjust_sessions(
original_sessions: dict,
to_merge_flags,
current_yaml,
):
session_ids_to_fully_delete = []
flags_under_carryforward_rules = [
f for f in to_merge_flags if current_yaml.flag_has_carryfoward(f)
]
if flags_under_carryforward_rules:
for sess_id, curr_sess in original_sessions.items():
if curr_sess.session_type == SessionType.carriedforward:
if curr_sess.flags:
if any(

Check warning on line 32 in helpers/parallel_upload_processing.py

View check run for this annotation

Codecov Notifications / codecov/patch

helpers/parallel_upload_processing.py#L29-L32

Added lines #L29 - L32 were not covered by tests
f in flags_under_carryforward_rules for f in curr_sess.flags
):
session_ids_to_fully_delete.append(sess_id)

Check warning on line 35 in helpers/parallel_upload_processing.py

View check run for this annotation

Codecov Notifications / codecov/patch

helpers/parallel_upload_processing.py#L35

Added line #L35 was not covered by tests
if session_ids_to_fully_delete:
# delete sessions from dict
for id in session_ids_to_fully_delete:
original_sessions.pop(id, None)

Check warning on line 39 in helpers/parallel_upload_processing.py

View check run for this annotation

Codecov Notifications / codecov/patch

helpers/parallel_upload_processing.py#L38-L39

Added lines #L38 - L39 were not covered by tests
return


def get_parallel_session_ids(
sessions, argument_list, db_session, report_service, commit_yaml
):
num_sessions = len(argument_list)

mock_sessions = copy.deepcopy(sessions) # the sessions already in the report
get_parallel_session_ids = []

# iterate over all uploads, get the next session id, and adjust sessions (remove CFF logic)
for i in range(num_sessions):
next_session_id = next_session_number(mock_sessions)

upload_pk = argument_list[i]["upload_pk"]
upload = db_session.query(Upload).filter_by(id_=upload_pk).first()
to_merge_session = report_service.build_session(upload)
flags = upload.flag_names

mock_sessions[next_session_id] = to_merge_session
_adjust_sessions(mock_sessions, flags, commit_yaml)

get_parallel_session_ids.append(next_session_id)

return get_parallel_session_ids


@sentry_sdk.trace
Expand Down
13 changes: 8 additions & 5 deletions services/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def has_initialized_report(self, commit: Commit) -> bool:

@sentry_sdk.trace
def initialize_and_save_report(
self, commit: Commit, report_code: str | None = None
self, commit: Commit, report_code: str = None
) -> CommitReport:
"""
Initializes the commit report
Expand Down Expand Up @@ -412,7 +412,7 @@ def build_sessions(self, commit: Commit) -> dict[int, Session]:
Does not include CF sessions if there is also an upload session with the same
flag name.
"""
sessions: dict[int, Session] = {}
sessions = {}

carryforward_sessions = {}
uploaded_flags = set()
Expand Down Expand Up @@ -873,6 +873,7 @@ def build_report_from_raw_content(
report: Report,
raw_report_info: RawReportInfo,
upload: Upload,
parallel_idx=None,
) -> ProcessingResult:
"""
Processes an upload on top of an existing report `master` and returns
Expand All @@ -892,7 +893,6 @@ def build_report_from_raw_content(
reportid = upload.external_id

session = Session(
id=upload.id,
provider=service,
build=build,
job=job,
Expand All @@ -919,6 +919,7 @@ def build_report_from_raw_content(
reportid=reportid,
commit_yaml=self.current_yaml.to_dict(),
archive_url=archive_url,
in_parallel=parallel_idx is not None,
),
)
result.error = ProcessingError(
Expand Down Expand Up @@ -954,11 +955,13 @@ def build_report_from_raw_content(
raw_report,
flags,
session,
upload,
upload=upload,
parallel_idx=parallel_idx,
)
result.report = process_result.report
log.info(
"Successfully processed report",
"Successfully processed report"
+ (" (in parallel)" if parallel_idx is not None else ""),
extra=dict(
session=session.id,
ci=f"{session.provider}:{session.build}:{session.job}",
Expand Down
Loading

0 comments on commit 52dc6c2

Please sign in to comment.