Skip to content

Commit 749d70c

Browse files
committed
feat: add boot and test lab filter logic
1 parent 8181d26 commit 749d70c

File tree

8 files changed

+51
-9
lines changed

8 files changed

+51
-9
lines changed

backend/kernelCI_app/helpers/filters.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ def __init__(self, data: Dict, process_body=False) -> None:
354354
self.filter_test_origin: set[str] = set()
355355

356356
self.filter_build_lab: set[str] = set()
357+
self.filter_boot_lab: set[str] = set()
358+
self.filter_test_lab: set[str] = set()
357359

358360
self.filter_handlers: FilterHandlers = {
359361
"boot.status": self._handle_boot_status,
@@ -381,6 +383,8 @@ def __init__(self, data: Dict, process_body=False) -> None:
381383
"boot.origin": self._handle_boot_origin,
382384
"test.origin": self._handle_test_origin,
383385
"build.lab": self._handle_build_lab,
386+
"boot.lab": self._handle_boot_lab,
387+
"test.lab": self._handle_test_lab,
384388
}
385389

386390
self.filters: List[FilterParams.ParsedFilter] = []
@@ -492,6 +496,12 @@ def _handle_test_origin(self, current_filter: ParsedFilter) -> None:
492496
def _handle_build_lab(self, current_filter: ParsedFilter) -> None:
493497
self.filter_build_lab.add(current_filter["value"])
494498

499+
def _handle_boot_lab(self, current_filter: ParsedFilter) -> None:
500+
self.filter_boot_lab.add(current_filter["value"])
501+
502+
def _handle_test_lab(self, current_filter: ParsedFilter) -> None:
503+
self.filter_test_lab.add(current_filter["value"])
504+
495505
def _process_filters(self):
496506
try:
497507
for current_filter in self.filters:
@@ -705,6 +715,7 @@ def is_boot_filtered_out(
705715
incident_test_id: Optional[str] = "incident_test_id",
706716
platform: Optional[str] = None,
707717
origin: Optional[str] = None,
718+
lab: Optional[str] = None,
708719
) -> bool:
709720
if (
710721
(self.filterBootPath != "" and (self.filterBootPath not in path))
@@ -740,6 +751,7 @@ def is_boot_filtered_out(
740751
len(self.filter_boot_origin) > 0
741752
and (origin not in self.filter_boot_origin)
742753
)
754+
or (len(self.filter_boot_lab) > 0 and (lab not in self.filter_boot_lab))
743755
):
744756
return True
745757

@@ -756,6 +768,7 @@ def is_test_filtered_out(
756768
incident_test_id: Optional[str] = "incident_test_id",
757769
platform: Optional[str] = None,
758770
origin: Optional[str] = None,
771+
lab: Optional[str] = None,
759772
) -> bool:
760773
if (
761774
(self.filterTestPath != "" and (self.filterTestPath not in path))
@@ -791,6 +804,7 @@ def is_test_filtered_out(
791804
len(self.filter_test_origin) > 0
792805
and (origin not in self.filter_test_origin)
793806
)
807+
or (len(self.filter_test_lab) > 0 and (lab not in self.filter_test_lab))
794808
):
795809
return True
796810

backend/kernelCI_app/helpers/treeDetails.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ def decide_if_is_boot_filtered_out(instance, row_data):
308308
test_path = row_data["test_path"]
309309
incident_test_id = row_data["incident_test_id"]
310310
origin = row_data["test_origin"]
311+
lab = row_data["history_item"].get("lab", UNKNOWN_STRING)
311312

312313
return instance.filters.is_boot_filtered_out(
313314
duration=test_duration,
@@ -317,6 +318,7 @@ def decide_if_is_boot_filtered_out(instance, row_data):
317318
status=test_status,
318319
incident_test_id=incident_test_id,
319320
origin=origin,
321+
lab=lab,
320322
)
321323

322324

@@ -339,6 +341,7 @@ def decide_if_is_test_filtered_out(instance, row_data):
339341
test_path = row_data["test_path"]
340342
incident_test_id = row_data["incident_test_id"]
341343
origin = row_data["test_origin"]
344+
lab = row_data["history_item"].get("lab", UNKNOWN_STRING)
342345

343346
return instance.filters.is_test_filtered_out(
344347
duration=test_duration,
@@ -348,6 +351,7 @@ def decide_if_is_test_filtered_out(instance, row_data):
348351
status=test_status,
349352
incident_test_id=incident_test_id,
350353
origin=origin,
354+
lab=lab,
351355
)
352356

353357

backend/kernelCI_app/queries/tree.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ def get_tree_commit_history(
597597
t.environment_compatible,
598598
t.environment_misc,
599599
t.origin,
600+
t.misc->>'runtime' AS test_lab,
600601
b.id AS build_id,
601602
b.misc AS build_misc,
602603
t.id AS test_id,

backend/kernelCI_app/tests/unitTests/helpers/fixtures/hardware_details_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def create_test_summary(**overrides):
114114
failed_platforms={"x86_64", "arm64"},
115115
environment_compatible={"hardware1": StatusCount()},
116116
environment_misc={"x86_64": StatusCount()},
117+
labs={},
117118
)
118119

119120
for key, value in overrides.items():

backend/kernelCI_app/tests/unitTests/helpers/fixtures/tree_details_data.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ def create_summary_row_data(**overrides):
8181
"test_error": "Test error",
8282
"test_environment_compatible": "hardware1",
8383
"test_origin": "test",
84+
"history_item": {
85+
"lab": "test_runtime_lab",
86+
},
8487
}
8588
base_data.update(overrides)
8689
return base_data
@@ -103,6 +106,9 @@ def create_filter_row_data(**overrides):
103106
"build_origin": "build_origin",
104107
"test_origin": "test_origin",
105108
"build_misc": {"lab": "lab1"},
109+
"history_item": {
110+
"lab": "test_runtime_lab",
111+
},
106112
}
107113
base_data.update(overrides)
108114
return base_data

backend/kernelCI_app/tests/unitTests/helpers/hardwareDetails_helpers_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ def test_handle_test_summary(
617617
unknown_issues=0,
618618
fail_reasons={},
619619
failed_platforms=set(),
620+
labs={},
620621
)
621622

622623
issue_dict = {}
@@ -1317,6 +1318,7 @@ def test_format_issue_summary_for_response(self, mock_convert):
13171318
unknown_issues=0,
13181319
fail_reasons={},
13191320
failed_platforms=set(),
1321+
labs={},
13201322
)
13211323
tests_summary = TestSummary(
13221324
status=StatusCount(),
@@ -1327,6 +1329,7 @@ def test_format_issue_summary_for_response(self, mock_convert):
13271329
unknown_issues=0,
13281330
fail_reasons={},
13291331
failed_platforms=set(),
1332+
labs={},
13301333
)
13311334

13321335
issue_dicts = {

backend/kernelCI_app/tests/unitTests/helpers/treeDetails_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ def test_decide_if_is_boot_filtered_out(self):
583583
"test_path": "boot.test",
584584
"incident_test_id": "test123",
585585
"test_origin": "test",
586+
"history_item": {"lab": "boot_lab"},
586587
}
587588

588589
result = decide_if_is_boot_filtered_out(instance, row_data)
@@ -596,6 +597,7 @@ def test_decide_if_is_boot_filtered_out(self):
596597
status="FAIL",
597598
incident_test_id="test123",
598599
origin="test",
600+
lab="boot_lab",
599601
)
600602

601603

@@ -639,6 +641,7 @@ def test_decide_if_is_test_filtered_out(self):
639641
"test_path": "test.specific",
640642
"incident_test_id": "test123",
641643
"test_origin": "test",
644+
"history_item": {"lab": "test_lab"},
642645
}
643646

644647
result = decide_if_is_test_filtered_out(instance, row_data)
@@ -652,6 +655,7 @@ def test_decide_if_is_test_filtered_out(self):
652655
status="FAIL",
653656
incident_test_id="test123",
654657
origin="test",
658+
lab="test_lab",
655659
)
656660

657661

backend/kernelCI_app/views/treeCommitsHistory.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ def setup_filters(self):
6767
def sanitize_rows(self, rows: dict) -> list:
6868
result = []
6969
for row in rows:
70-
build_misc = row[17]
70+
build_misc = row[18]
7171
sanitized_build_misc = sanitize_dict(build_misc)
72-
build_lab = sanitized_build_misc.get("lab") if sanitized_build_misc else None
72+
build_lab = (
73+
sanitized_build_misc.get("lab") if sanitized_build_misc else None
74+
)
7375

7476
result.append(
7577
{
@@ -89,13 +91,14 @@ def sanitize_rows(self, rows: dict) -> list:
8991
"hardware_compatibles": row[13],
9092
"test_environment_misc": row[14],
9193
"test_origin": row[15],
92-
"build_id": row[16],
94+
"test_lab": row[16],
95+
"build_id": row[17],
9396
"build_misc": build_misc,
94-
"test_id": row[18],
95-
"incidents_id": row[19],
96-
"incidents_test_id": row[20],
97-
"issue_id": row[21],
98-
"issue_version": row[22],
97+
"test_id": row[19],
98+
"incidents_id": row[20],
99+
"incidents_test_id": row[21],
100+
"issue_id": row[22],
101+
"issue_version": row[23],
99102
"build_lab": build_lab,
100103
}
101104
)
@@ -162,6 +165,7 @@ def _process_boots_count(
162165
issue_version: int,
163166
incident_test_id: str,
164167
test_origin: str,
168+
lab: str,
165169
) -> None:
166170
is_boot_filter_out = self.filterParams.is_boot_filtered_out(
167171
duration=test_duration,
@@ -171,6 +175,7 @@ def _process_boots_count(
171175
status=test_status,
172176
incident_test_id=incident_test_id,
173177
origin=test_origin,
178+
lab=lab,
174179
)
175180

176181
is_boot_processed = test_id in self.processed_tests
@@ -194,6 +199,7 @@ def _process_nonboots_count(
194199
issue_version: int,
195200
incident_test_id: str,
196201
test_origin: str,
202+
lab: str,
197203
) -> None:
198204
is_nonboot_filter_out = self.filterParams.is_test_filtered_out(
199205
duration=test_duration,
@@ -203,6 +209,7 @@ def _process_nonboots_count(
203209
status=test_status,
204210
incident_test_id=incident_test_id,
205211
origin=test_origin,
212+
lab=lab,
206213
)
207214

208215
is_test_processed = test_id in self.processed_tests
@@ -261,8 +268,8 @@ def _process_tests(self, row: dict) -> None:
261268
incident_test_id = row["incidents_test_id"]
262269
build_status = row["build_status"]
263270
test_origin = row["test_origin"]
264-
265271
commit_hash = row["git_commit_hash"]
272+
test_lab = row["test_lab"]
266273

267274
if issue_id is None and (
268275
build_status in [FAIL_STATUS, NULL_STATUS] or test_status == FAIL_STATUS
@@ -283,6 +290,7 @@ def _process_tests(self, row: dict) -> None:
283290
issue_version=issue_version,
284291
incident_test_id=incident_test_id,
285292
test_origin=test_origin,
293+
lab=test_lab,
286294
)
287295
else:
288296
self._process_nonboots_count(
@@ -295,6 +303,7 @@ def _process_tests(self, row: dict) -> None:
295303
issue_version=issue_version,
296304
incident_test_id=incident_test_id,
297305
test_origin=test_origin,
306+
lab=test_lab,
298307
)
299308

300309
def _process_builds(self, row: dict) -> None:

0 commit comments

Comments
 (0)