Skip to content

Commit 93cd3b5

Browse files
Jeny Sadadiagctucker
Jeny Sadadia
authored andcommitted
src/regression_tracker: check for regression in all child nodes
When runner submits a hierarchy of nodes at a single shot, the API will publish event just for parent node. In that case, the parent node can have "pass" result, even if one of its child has failed. Tweak regression tracker to listen to events when "checkout" node reaches to "done" state instead of getting nodes with just "fail" result. That way we can traverse through all the child nodes using the checkout node and check for regressions. Signed-off-by: Jeny Sadadia <[email protected]>
1 parent 56ea565 commit 93cd3b5

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

Diff for: src/regression_tracker.py

+37-22
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def __init__(self, configs, args):
2727
def _setup(self, args):
2828
return self._api_helper.subscribe_filters({
2929
'state': 'done',
30-
'result': 'fail',
3130
})
3231

3332
def _stop(self, sub_id):
@@ -43,6 +42,38 @@ def _create_regression(self, failed_node, last_successful_node):
4342
regression['regression_data'] = [last_successful_node, failed_node]
4443
self._api_helper.submit_regression(regression)
4544

45+
def _detect_regression(self, node):
46+
"""Method to check and detect regression"""
47+
previous_nodes = self._api.get_nodes({
48+
'name': node['name'],
49+
'group': node['group'],
50+
'path': node['path'],
51+
'revision.tree': node['revision']['tree'],
52+
'revision.branch': node['revision']['branch'],
53+
'revision.url': node['revision']['url'],
54+
'created__lt': node['created'],
55+
})
56+
57+
if previous_nodes:
58+
previous_nodes = sorted(
59+
previous_nodes,
60+
key=lambda node: node['created'],
61+
reverse=True
62+
)
63+
64+
if previous_nodes[0]['result'] == 'pass':
65+
self.log.info(f"Detected regression for node id: \
66+
{node['id']}")
67+
self._create_regression(node, previous_nodes[0])
68+
69+
def _get_all_failed_child_nodes(self, failures, root_node):
70+
"""Method to get all failed nodes recursively from top-level node"""
71+
child_nodes = self._api.get_nodes({'parent': root_node['id']})
72+
for node in child_nodes:
73+
if node['result'] == 'fail':
74+
failures.append(node)
75+
self._get_all_failed_child_nodes(failures, node)
76+
4677
def _run(self, sub_id):
4778
"""Method to run regression tracking"""
4879
self.log.info("Tracking regressions... ")
@@ -51,31 +82,15 @@ def _run(self, sub_id):
5182

5283
while True:
5384
node = self._api_helper.receive_event_node(sub_id)
54-
if not node['group']:
55-
continue
56-
57-
previous_nodes = self._api.get_nodes({
58-
'name': node['name'],
59-
'group': node['group'],
60-
'revision.tree': node['revision']['tree'],
61-
'revision.branch': node['revision']['branch'],
62-
'revision.url': node['revision']['url'],
63-
'created__lt': node['created'],
64-
})
6585

66-
if not previous_nodes:
86+
if node['name'] == 'checkout':
6787
continue
6888

69-
previous_nodes = sorted(
70-
previous_nodes,
71-
key=lambda node: node['created'],
72-
reverse=True
73-
)
89+
failures = []
90+
self._get_all_failed_child_nodes(failures, node)
7491

75-
if previous_nodes[0]['result'] == 'pass':
76-
self.log.info(f"Detected regression for node id: \
77-
{node['id']}")
78-
self._create_regression(node, previous_nodes[0])
92+
for node in failures:
93+
self._detect_regression(node)
7994

8095
sys.stdout.flush()
8196
return True

0 commit comments

Comments
 (0)