| Index: appengine/findit/waterfall/identify_try_job_culprit_pipeline.py
|
| diff --git a/appengine/findit/waterfall/identify_try_job_culprit_pipeline.py b/appengine/findit/waterfall/identify_try_job_culprit_pipeline.py
|
| index 556fb67f5d54bf66c34ef664951a5ec7c50a9fbd..552b04f0e776e2a881878c5a393adde3ef354243 100644
|
| --- a/appengine/findit/waterfall/identify_try_job_culprit_pipeline.py
|
| +++ b/appengine/findit/waterfall/identify_try_job_culprit_pipeline.py
|
| @@ -8,11 +8,31 @@ from model import wf_analysis_status
|
| from model.wf_try_job import WfTryJob
|
| from model.wf_try_job_data import WfTryJobData
|
| from pipeline_wrapper import BasePipeline
|
| +from waterfall.try_job_type import TryJobType
|
| +
|
| +
|
| +GIT_REPO = GitRepository(
|
| + 'https://chromium.googlesource.com/chromium/src.git', HttpClient())
|
|
|
|
|
| class IdentifyTryJobCulpritPipeline(BasePipeline):
|
| """A pipeline to identify culprit CL info based on try job compile results."""
|
|
|
| + def _GetCulpritInfo(self, failed_revisions):
|
| + """Gets commit_positions and review_urls for revisions."""
|
| + culprits = {}
|
| + for failed_revision in failed_revisions:
|
| + culprits[failed_revision] = {
|
| + 'revision': failed_revision
|
| + }
|
| + change_log = GIT_REPO.GetChangeLog(failed_revision)
|
| + if change_log:
|
| + culprits[failed_revision]['commit_position'] = (
|
| + change_log.commit_position)
|
| + culprits[failed_revision]['review_url'] = change_log.code_review_url
|
| +
|
| + return culprits
|
| +
|
| @staticmethod
|
| def _GetFailedRevisionFromResultsDict(results_dict):
|
| """Finds the failed revision from the given dict of revisions.
|
| @@ -102,50 +122,107 @@ class IdentifyTryJobCulpritPipeline(BasePipeline):
|
|
|
| return failed_revision
|
|
|
| - @staticmethod
|
| - def _GetCulpritFromFailedRevision(failed_revision):
|
| - """Returns a culprit (dict) using failed_revision, or None."""
|
| - if not failed_revision:
|
| - return None
|
| -
|
| - git_repo = GitRepository(
|
| - 'https://chromium.googlesource.com/chromium/src.git', HttpClient())
|
| - change_log = git_repo.GetChangeLog(failed_revision)
|
| -
|
| - if not change_log:
|
| - return None
|
| -
|
| - return {
|
| - 'revision': failed_revision,
|
| - 'commit_position': change_log.commit_position,
|
| - 'review_url': change_log.code_review_url
|
| - }
|
| + def _FindCulpritForEachTestFailure(self, blame_list, result):
|
| + # For test failures, the try job will run against every revision,
|
| + # so we need to traverse the result dict in chronological order to identify
|
| + # the culprits for each failed step or test.
|
| + culprit_map = {}
|
| + failed_revisions = []
|
| + for revision in blame_list:
|
| + for step, step_result in result['report'][revision].iteritems():
|
| + if (not step_result['valid'] or
|
| + not step_result['status'] == 'failed'): # pragma: no cover
|
| + continue
|
| +
|
| + if revision not in failed_revisions:
|
| + failed_revisions.append(revision)
|
| +
|
| + if step not in culprit_map:
|
| + culprit_map[step] = {
|
| + 'tests': {}
|
| + }
|
| +
|
| + if (not step_result['failures'] and
|
| + not culprit_map[step].get('revision')):
|
| + # Non swarming test failures, only have step level failure info.
|
| + culprit_map[step]['revision'] = revision
|
| +
|
| + for failed_test in step_result['failures']:
|
| + # Swarming tests, gets first failed revision for each test.
|
| + if failed_test not in culprit_map[step]['tests']:
|
| + culprit_map[step]['tests'][failed_test] = {
|
| + 'revision': revision
|
| + }
|
| + return culprit_map, failed_revisions
|
| +
|
| + def _UpdateCulpritMapWithCulpritInfo(self, culprit_map, culprits):
|
| + """Fills in commit_position and review_url for each failed rev in map."""
|
| + for step_culprit in culprit_map.values():
|
| + if step_culprit.get('revision'):
|
| + culprit = culprits[step_culprit['revision']]
|
| + step_culprit['commit_position'] = culprit['commit_position']
|
| + step_culprit['review_url'] = culprit['review_url']
|
| + for test_culprit in step_culprit.get('tests', {}).values():
|
| + test_revision = test_culprit['revision']
|
| + test_culprit.update(culprits[test_revision])
|
| +
|
| + def _GetCulpritDataForTest(self, culprit_map):
|
| + """Gets culprit revision for each failure for try job metadata."""
|
| + culprit_data = {}
|
| + for step, step_culprit in culprit_map.iteritems():
|
| + if step_culprit['tests']:
|
| + culprit_data[step] = {}
|
| + for test, test_culprit in step_culprit['tests'].iteritems():
|
| + culprit_data[step][test] = test_culprit['revision']
|
| + else:
|
| + culprit_data[step] = step_culprit['revision']
|
| + return culprit_data
|
|
|
| # Arguments number differs from overridden method - pylint: disable=W0221
|
| - def run(self, master_name, builder_name, build_number, try_job_id,
|
| - compile_result):
|
| - culprit = None
|
| - failed_revision = self._GetFailedRevisionFromCompileResult(compile_result)
|
| - culprit = self._GetCulpritFromFailedRevision(failed_revision)
|
| -
|
| - # Store try job results.
|
| - try_job_result = WfTryJob.Get(master_name, builder_name, build_number)
|
| - try_job_data = WfTryJobData.Get(try_job_id)
|
| + def run(
|
| + self, master_name, builder_name, build_number, blame_list, try_job_type,
|
| + try_job_id, result):
|
| + """Identifies the information for failed revisions.
|
|
|
| - # TODO(lijeffrey): Add support for documenting test culprits.
|
| - if failed_revision:
|
| - try_job_data.culprits = {'compile': failed_revision}
|
| + Please refer to try_job_result_format.md for format check.
|
| + """
|
| + culprits = None
|
| + if result and result.get('report'):
|
| + try_job_data = WfTryJobData.Get(try_job_id)
|
| + if try_job_type == TryJobType.COMPILE:
|
| + # For compile failures, the try job will stop if one revision fails, so
|
| + # the culprit will be the last revision in the result.
|
| + failed_revision = self._GetFailedRevisionFromCompileResult(
|
| + result)
|
| + failed_revisions = [failed_revision] if failed_revision else []
|
| + culprits = self._GetCulpritInfo(failed_revisions)
|
| + if culprits:
|
| + result['culprit'] = culprits[failed_revision]
|
| + try_job_data.culprits = {'compile': failed_revision}
|
| + else: # try_job_type is 'test'.
|
| + culprit_map, failed_revisions = self._FindCulpritForEachTestFailure(
|
| + blame_list, result)
|
| + culprits = self._GetCulpritInfo(failed_revisions)
|
| + if culprits:
|
| + self._UpdateCulpritMapWithCulpritInfo(culprit_map, culprits)
|
| + result['culprit'] = culprit_map
|
| + try_job_data.culprits = self._GetCulpritDataForTest(culprit_map)
|
| try_job_data.put()
|
|
|
| - if culprit:
|
| - compile_result['culprit'] = culprit
|
| - if (try_job_result.compile_results and
|
| - try_job_result.compile_results[-1]['try_job_id'] == try_job_id):
|
| - try_job_result.compile_results[-1].update(compile_result)
|
| + # Store try job results.
|
| + try_job_result = WfTryJob.Get(master_name, builder_name, build_number)
|
| + if culprits:
|
| + result_to_update = (
|
| + try_job_result.compile_results if
|
| + try_job_type == TryJobType.COMPILE else
|
| + try_job_result.test_results)
|
| + if (result_to_update and
|
| + result_to_update[-1]['try_job_id'] == try_job_id):
|
| + result_to_update[-1].update(result)
|
| else: # pragma: no cover
|
| - try_job_result.compile_results.append(compile_result)
|
| + result_to_update.append(result)
|
|
|
| try_job_result.status = wf_analysis_status.ANALYZED
|
| try_job_result.put()
|
|
|
| - return culprit
|
| + return result.get('culprit') if result else None
|
|
|