Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: appengine/findit/waterfall/identify_try_job_culprit_pipeline.py

Issue 1622813003: [Findit] Adding support for extracting revisions from dict instead of list (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Addressing code review comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | appengine/findit/waterfall/test/identify_try_job_culprit_pipeline_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from common.git_repository import GitRepository 5 from common.git_repository import GitRepository
6 from common.http_client_appengine import HttpClientAppengine as HttpClient 6 from common.http_client_appengine import HttpClientAppengine as HttpClient
7 from model import wf_analysis_status 7 from model import wf_analysis_status
8 from model.wf_try_job import WfTryJob 8 from model.wf_try_job import WfTryJob
9 from pipeline_wrapper import BasePipeline 9 from pipeline_wrapper import BasePipeline
10 10
11 11
12 class IdentifyTryJobCulpritPipeline(BasePipeline): 12 class IdentifyTryJobCulpritPipeline(BasePipeline):
13 """A pipeline to identify culprit CL info based on try job compile results.""" 13 """A pipeline to identify culprit CL info based on try job compile results."""
14 14
15 # Arguments number differs from overridden method - pylint: disable=W0221 15 @staticmethod
16 def run( 16 def _GetFailedRevisionFromResultsDict(results_dict):
17 self, master_name, builder_name, build_number, try_job_id, 17 """Finds the failed revision from the given dict of revisions.
18 compile_result):
19 culprit = None
20 18
21 if compile_result and len(compile_result.get('result', [])) > 0: 19 Args:
20 results_dict: (dict) A dict that maps revisions to their results. For
21 example:
22
23 {
24 'rev1': 'passed',
25 'rev2': 'passed',
26 'rev3': 'failed',
27 }
28
29 Note results_dict is expected only to have one failed revision which
30 will be the one to be returned.
31
32 Returns:
33 The revision corresponding to a failed result, if any.
34 """
35 for revision, result in results_dict.iteritems():
36 if result.lower() == 'failed':
37 return revision
38 return None
39
40 @staticmethod
41 def _FindFailedRevisionFromCompileResult(compile_result):
42 """Returns the failed revision (string) from compile_result if any."""
43 if not compile_result:
44 return None
45
46 failed_revision = None
47 result_list = compile_result.get('result')
48
49 if result_list and isinstance(result_list, list):
50 # TODO(lijeffrey): The format for the result of the compile will change
51 # from a list to a dict. This branch is for backwards compatibility and
52 # should be removed once result is returned as a dict from the compile
53 # recipe. The test recipe may need to be considered as well.
54
22 # For compile failures, the try job will stop if one revision fails, so 55 # For compile failures, the try job will stop if one revision fails, so
23 # the culprit will be the last revision in the result. 56 # the culprit will be the last revision in the result.
24 result_for_last_checked_revision = compile_result['result'][-1] 57 result_for_last_checked_revision = compile_result['result'][-1]
stgao 2016/01/26 01:22:33 result -> report. Need to update buildbucket_clie
lijeffrey 2016/01/27 01:06:00 Done.
25 failed_revision = ( 58 failed_revision = (
26 result_for_last_checked_revision[0] if 59 result_for_last_checked_revision[0] if
27 result_for_last_checked_revision[1].lower() == 'failed' else None) 60 result_for_last_checked_revision[1].lower() == 'failed' else None)
61 elif isinstance(compile_result.get('analysis_info'), dict):
stgao 2016/01/26 01:22:33 compile_result.get('analysis_info') -> report.get(
chanli 2016/01/26 18:15:28 Is this format finalized?
stgao 2016/01/26 18:32:26 Jeff and I had a discussion on the new format to m
chanli 2016/01/26 18:52:19 Should the format like what Jeff mentioned in the
stgao 2016/01/26 19:03:35 Yes, very similar to that, expect no root node "an
lijeffrey 2016/01/27 01:06:00 Done.
62 revision_results = compile_result.get(
63 'analysis_info', {}).get('result', {})
64 failed_revision = (
65 IdentifyTryJobCulpritPipeline._GetFailedRevisionFromResultsDict(
66 revision_results))
28 67
29 if failed_revision: 68 return failed_revision
30 git_repo = GitRepository( 69
31 'https://chromium.googlesource.com/chromium/src.git', HttpClient()) 70 @staticmethod
32 change_log = git_repo.GetChangeLog(failed_revision) 71 def _GetCulpritFromFailedRevision(failed_revision):
33 if change_log: 72 """Returns a culprit (dict) using failed_revision, or None."""
34 culprit = { 73 if not failed_revision:
35 'revision': failed_revision, 74 return None
36 'commit_position': change_log.commit_position, 75
37 'review_url': change_log.code_review_url 76 culprit = None
38 } 77 git_repo = GitRepository(
39 compile_result['culprit'] = culprit 78 'https://chromium.googlesource.com/chromium/src.git', HttpClient())
79 change_log = git_repo.GetChangeLog(failed_revision)
80
81 if change_log:
82 culprit = {
83 'revision': failed_revision,
84 'commit_position': change_log.commit_position,
85 'review_url': change_log.code_review_url
86 }
87
88 return culprit
qyearsley 2016/01/26 00:40:04 Slightly different way to write the same thing:
lijeffrey 2016/01/27 01:06:00 Done.
89
90 # Arguments number differs from overridden method - pylint: disable=W0221
91 def run(self, master_name, builder_name, build_number, try_job_id,
92 compile_result):
93 culprit = None
94 failed_revision = self._FindFailedRevisionFromCompileResult(compile_result)
95 culprit = self._GetCulpritFromFailedRevision(failed_revision)
40 96
41 # Store try job results. 97 # Store try job results.
42 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) 98 try_job_result = WfTryJob.Get(master_name, builder_name, build_number)
43 if culprit: 99 if culprit:
100 compile_result['culprit'] = culprit
44 if (try_job_result.compile_results and 101 if (try_job_result.compile_results and
45 try_job_result.compile_results[-1]['try_job_id'] == try_job_id): 102 try_job_result.compile_results[-1]['try_job_id'] == try_job_id):
46 try_job_result.compile_results[-1].update(compile_result) 103 try_job_result.compile_results[-1].update(compile_result)
47 else: # pragma: no cover 104 else: # pragma: no cover
48 try_job_result.compile_results.append(compile_result) 105 try_job_result.compile_results.append(compile_result)
49 106
50 try_job_result.status = wf_analysis_status.ANALYZED 107 try_job_result.status = wf_analysis_status.ANALYZED
51 try_job_result.put() 108 try_job_result.put()
52 109
53 return culprit 110 return culprit
OLDNEW
« no previous file with comments | « no previous file | appengine/findit/waterfall/test/identify_try_job_culprit_pipeline_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698