Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine node search and regression generation (alternative) #447

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 62 additions & 34 deletions src/regression_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import sys

import json

import kernelci
import kernelci.config
import kernelci.db
Expand All @@ -19,7 +21,6 @@ class RegressionTracker(Service):

def __init__(self, configs, args):
super().__init__(configs, args, 'regression_tracker')
self._regression_fields = ['group', 'name', 'path']

def _setup(self, args):
return self._api_helper.subscribe_filters({
Expand All @@ -30,44 +31,71 @@ def _stop(self, sub_id):
if sub_id:
self._api_helper.unsubscribe_filters(sub_id)

def _create_regression(self, failed_node, last_successful_node):
def _create_regression(self, failed_node, last_pass_node):
"""Method to create a regression"""
regression = {}
for field in self._regression_fields:
regression[field] = failed_node[field]

regression['kind'] = 'regression'
regression['name'] = failed_node['name']
regression['path'] = failed_node['path']
regression['group'] = failed_node['group']
regression['state'] = 'done'
regression['data'] = {
'fail_node': failed_node['id'],
'pass_node': last_successful_node['id'],
'pass_node': last_pass_node['id'],
'arch': failed_node['data'].get('arch'),
'defconfig': failed_node['data'].get('defconfig'),
'compiler': failed_node['data'].get('compiler'),
'platform': failed_node['data'].get('platform'),
'failed_kernel_version': failed_node['data'].get('kernel_revision'), # noqa
}
reg = self._api_helper.submit_regression(regression)
resp = self._api_helper.submit_regression(regression)
reg = json.loads(resp.text)
self.log.info(f"Regression submitted: {reg['id']}")

def _detect_regression(self, node):
"""Method to check and detect regression"""
def _detect_regression(self, fail_node):
"""Detects if <fail_node> (a failed job) produces a regression,
ie. if the previous job run with the same parameters passed"""
previous_nodes = self._api.node.find({
'name': node['name'],
'group': node['group'],
'path': node['path'],
'name': fail_node['name'],
'group': fail_node['group'],
'path': fail_node['path'],
'data.kernel_revision.tree':
node['data']['kernel_revision']['tree'],
fail_node['data']['kernel_revision']['tree'],
'data.kernel_revision.branch':
node['data']['kernel_revision']['branch'],
'data.kernel_revision.url': node['data']['kernel_revision']['url'],
'created__lt': node['created'],
fail_node['data']['kernel_revision']['branch'],
'data.kernel_revision.url':
fail_node['data']['kernel_revision']['url'],
'data.arch': fail_node['data']['arch'],
'data.defconfig': fail_node['data']['defconfig'],
'data.compiler': fail_node['data']['compiler'],
'data.platform': fail_node['data']['platform'],
'created__lt': fail_node['created'],
'state': 'done'
})

if previous_nodes:
previous_nodes = sorted(
previous_nodes,
key=lambda node: node['created'],
reverse=True
)

if previous_nodes[0]['result'] == 'pass':
self.log.info(f"Detected regression for node id: \
{node['id']}")
self._create_regression(node, previous_nodes[0])
if not previous_nodes:
return
previous_node = sorted(
previous_nodes,
key=lambda node: node['created'],
reverse=True
)[0]
if previous_node['result'] == 'pass':
self.log.info("Detected regression for node id: "
f"{fail_node['id']}")
# Skip the regression generation if it was already in the
# DB. This may happen if a job was detected to generate a
# regression when it failed and then the same job was
# checked again after its parent job finished running and
# was updated.
existing_regression = self._api.node.find({
'kind': 'regression',
'data.fail_node': fail_node['id'],
'data.pass_node': previous_node['id']
})
if not existing_regression:
self._create_regression(fail_node, previous_node)
else:
self.log.info(f"Skipping regression: already exists")

def _get_all_failed_child_nodes(self, failures, root_node):
"""Method to get all failed nodes recursively from top-level node"""
Expand All @@ -78,23 +106,23 @@ def _get_all_failed_child_nodes(self, failures, root_node):
self._get_all_failed_child_nodes(failures, node)

def _run(self, sub_id):
"""Method to run regression tracking"""
"""Method to run regression detection and generation"""
self.log.info("Tracking regressions... ")
self.log.info("Press Ctrl-C to stop.")
sys.stdout.flush()

while True:
node = self._api_helper.receive_event_node(sub_id)

if node['kind'] == 'checkout':
continue

if node['result'] == 'fail':
self._detect_regression(node)
# When a node hierarchy is submitted on a single operation,
# an event is generated only for the root node. Walk the
# children node tree to check for event-less failed jobs
failures = []
self._get_all_failed_child_nodes(failures, node)

for node in failures:
self._detect_regression(node)

sys.stdout.flush()
return True

Expand Down
Loading