Skip to content

Commit

Permalink
Remove labels-index feature flag (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem authored Nov 7, 2024
1 parent 0c11397 commit 9d6bdc7
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 2,529 deletions.
6 changes: 0 additions & 6 deletions rollouts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
FLAKY_TEST_DETECTION = Feature("flaky_test_detection")
FLAKY_SHADOW_MODE = Feature("flaky_shadow_mode")

# Eventually we want all repos to use this
# This flag will just help us with the rollout process
USE_LABEL_INDEX_IN_REPORT_PROCESSING_BY_REPO_ID = Feature(
"use_label_index_in_report_processing"
)

INTERMEDIATE_REPORTS_IN_REDIS = Feature("intermediate_reports_in_redis")

CARRYFORWARD_BASE_SEARCH_RANGE_BY_OWNER = Feature("carryforward_base_search_range")
Expand Down
6 changes: 1 addition & 5 deletions services/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,7 @@ def build_report_from_raw_content(
log.debug("Retrieved report for processing from url %s", archive_url)
try:
result.report = process_raw_upload(
self.current_yaml,
raw_report,
flags,
session,
upload=upload,
self.current_yaml, raw_report, flags, session
)

log.info(
Expand Down
93 changes: 20 additions & 73 deletions services/report/languages/pycoverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def matches_content(self, content: dict, first_line: str, name: str) -> bool:
def process(
self, content: dict, report_builder_session: ReportBuilderSession
) -> None:
labels_table = LabelsTable(report_builder_session, content)
labels_table = content.get("labels_table", {})

for filename, file_coverage in content["files"].items():
_file = report_builder_session.create_coverage_file(filename)
Expand All @@ -28,79 +28,26 @@ def process(
] + [(COVERAGE_MISS, ln) for ln in file_coverage["missing_lines"]]
for cov, ln in lines_and_coverage:
if ln > 0:
label_list_of_lists: list[list[str]] | list[list[int]] = []
if report_builder_session.should_use_label_index:
label_list_of_lists = [
[single_id]
for single_id in labels_table._get_list_of_label_ids(
report_builder_session.label_index,
file_coverage.get("contexts", {}).get(str(ln), []),
)
]
else:
label_list_of_lists = [
[labels_table._normalize_label(testname)]
for testname in file_coverage.get("contexts", {}).get(
str(ln), []
)
]
_file.append(
ln,
report_builder_session.create_coverage_line(
cov,
labels_list_of_lists=label_list_of_lists,
),
label_list_of_lists = [
[_normalize_label(labels_table, testname)]
for testname in file_coverage.get("contexts", {}).get(
str(ln), []
)
]
_line = report_builder_session.create_coverage_line(
cov,
labels_list_of_lists=label_list_of_lists,
)
_file.append(ln, _line)
report_builder_session.append(_file)


class LabelsTable:
def __init__(
self, report_builder_session: ReportBuilderSession, content: dict
) -> None:
self.labels_table: dict[str, str] = {}
self.reverse_table: dict[str, int] = {}
self.are_labels_already_encoded = False

# Compressed pycoverage files will include a labels_table
if "labels_table" in content:
self.labels_table = content["labels_table"]
# We can pre-populate some of the indexes that will be used
for idx, testname in self.labels_table.items():
clean_label = self._normalize_label(testname)
report_builder_session.label_index[int(idx)] = clean_label
self.are_labels_already_encoded = True

def _normalize_label(self, testname: int | float | str) -> str:
if isinstance(testname, int) or isinstance(testname, float):
# This is from a compressed report.
# Pull label from the labels_table
# But the labels_table keys are strings, because of JSON format
testname = self.labels_table[str(testname)]
if testname == "":
return SpecialLabelsEnum.CODECOV_ALL_LABELS_PLACEHOLDER.corresponding_label
return testname.split("|", 1)[0]

def _get_list_of_label_ids(
self,
current_label_idx: dict[int, str],
line_contexts: list[str | int],
) -> list[int]:
if self.are_labels_already_encoded:
# The line contexts already include indexes in the table.
# We can re-use the table and don't have to do anything with contexts.
return sorted(map(int, line_contexts))

# In this case we do need to fix the labels
label_ids_for_line = set()
for testname in line_contexts:
clean_label = self._normalize_label(testname)
if clean_label in self.reverse_table:
label_ids_for_line.add(self.reverse_table[clean_label])
else:
label_id = max([*current_label_idx.keys(), 0]) + 1
current_label_idx[label_id] = clean_label
self.reverse_table[clean_label] = label_id
label_ids_for_line.add(label_id)

return sorted(label_ids_for_line)
def _normalize_label(labels_table: dict[str, str], testname: int | float | str) -> str:
if isinstance(testname, int) or isinstance(testname, float):
# This is from a compressed report.
# Pull label from the labels_table
# But the labels_table keys are strings, because of JSON format
testname = labels_table[str(testname)]
if testname == "":
return SpecialLabelsEnum.CODECOV_ALL_LABELS_PLACEHOLDER.corresponding_label
return testname.split("|", 1)[0]
2 changes: 0 additions & 2 deletions services/report/languages/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def create_report_builder_session(
path_fixer: PathFixer | None = None,
filename: str = "filename",
current_yaml: dict | None = None,
should_use_label_index: bool = False,
) -> ReportBuilderSession:
def fixes(filename, bases_to_try=None):
return filename
Expand All @@ -16,6 +15,5 @@ def fixes(filename, bases_to_try=None):
ignored_lines={},
sessionid=0,
current_yaml=current_yaml,
should_use_label_index=should_use_label_index,
)
return report_builder.create_report_builder_session(filename)
Loading

0 comments on commit 9d6bdc7

Please sign in to comment.