Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 common.pipeline_wrapper import BasePipeline | 7 from common.pipeline_wrapper import BasePipeline |
| 8 from model import analysis_status | 8 from model import analysis_status |
| 9 from model import result_status | |
| 10 from model.wf_analysis import WfAnalysis | |
| 9 from model.wf_try_job import WfTryJob | 11 from model.wf_try_job import WfTryJob |
| 10 from model.wf_try_job_data import WfTryJobData | 12 from model.wf_try_job_data import WfTryJobData |
| 11 from waterfall.try_job_type import TryJobType | 13 from waterfall.try_job_type import TryJobType |
| 12 | 14 |
| 13 | 15 |
| 14 GIT_REPO = GitRepository( | 16 GIT_REPO = GitRepository( |
| 15 'https://chromium.googlesource.com/chromium/src.git', HttpClient()) | 17 'https://chromium.googlesource.com/chromium/src.git', HttpClient()) |
| 16 | 18 |
| 17 | 19 |
| 20 def _GetResultAnalysisStatus(analysis, result): | |
| 21 """Returns the analysis status based on existing status and try job result. | |
| 22 | |
| 23 Args: | |
| 24 analysis: The WfAnalysis entity corresponding to this try job. | |
| 25 result: A result dict containing the result of this try job. | |
| 26 | |
| 27 Returns: | |
| 28 A result_status code. | |
| 29 """ | |
| 30 # Only return an updated analysis result status if no results were already | |
| 31 # found (by the heuristic-based approach) but were by the try job. Note it is | |
| 32 # possible the heuristic-based result was triaged before the completion of | |
| 33 # this try job. | |
| 34 old_result_status = analysis.result_status | |
| 35 try_job_found_culprit = result and result.get('culprit') | |
| 36 | |
| 37 if old_result_status is None: | |
| 38 if try_job_found_culprit: | |
| 39 return result_status.FOUND_UNTRIAGED | |
| 40 return result_status.NOT_FOUND_UNTRIAGED | |
| 41 | |
| 42 if (try_job_found_culprit and | |
| 43 (old_result_status == result_status.NOT_FOUND_UNTRIAGED or | |
| 44 old_result_status == result_status.NOT_FOUND_INCORRECT or | |
| 45 old_result_status == result_status.NOT_FOUND_CORRECT)): | |
| 46 return result_status.FOUND_UNTRIAGED | |
| 47 | |
| 48 return old_result_status | |
| 49 | |
| 50 | |
| 51 def _GetSuspectedCLs(analysis, result): | |
| 52 """Returns a list of suspected CLs. | |
| 53 | |
| 54 Args: | |
| 55 analysis: The WfAnalysis entity corresponding to this try job. | |
| 56 result: A result dict containing the culprit from the results of | |
| 57 this try job. | |
| 58 | |
| 59 Returns: | |
| 60 A combined list of suspected CLs from those already in analysis and those | |
| 61 found by this try job. | |
| 62 """ | |
| 63 | |
| 64 suspected_cls = analysis.suspected_cls[:] if analysis.suspected_cls else [] | |
| 65 | |
| 66 if not result: | |
| 67 return suspected_cls | |
| 68 | |
| 69 culprit = result.get('culprit') | |
| 70 if not culprit: | |
| 71 return suspected_cls | |
| 72 | |
| 73 compile_cl_info = culprit.get('compile') | |
| 74 if compile_cl_info: | |
| 75 # Suspected CL is from compile failure. | |
| 76 if compile_cl_info not in suspected_cls: | |
| 77 suspected_cls.append(compile_cl_info) | |
| 78 return suspected_cls | |
| 79 | |
| 80 # Suspected CLs are from test failures. | |
| 81 for results in culprit.itervalues(): | |
| 82 if results.get('revision'): | |
| 83 # Non swarming test failures, only have step level failure info. | |
| 84 cl_info = { | |
| 85 'review_url': results.get('review_url'), | |
| 86 'repo_name': results.get('repo_name'), | |
| 87 'revision': results.get('revision'), | |
| 88 'commit_position': results.get('commit_position') | |
| 89 } | |
| 90 if cl_info not in suspected_cls: | |
| 91 suspected_cls.append(cl_info) | |
| 92 else: | |
| 93 for test_cl_info in results['tests'].values(): | |
| 94 if test_cl_info not in suspected_cls: | |
| 95 suspected_cls.append(test_cl_info) | |
| 96 | |
| 97 return suspected_cls | |
| 98 | |
| 99 | |
| 18 class IdentifyTryJobCulpritPipeline(BasePipeline): | 100 class IdentifyTryJobCulpritPipeline(BasePipeline): |
| 19 """A pipeline to identify culprit CL info based on try job compile results.""" | 101 """A pipeline to identify culprit CL info based on try job compile results.""" |
| 20 | 102 |
| 21 def _GetCulpritInfo(self, failed_revisions): | 103 def _GetCulpritInfo(self, failed_revisions): |
| 22 """Gets commit_positions and review_urls for revisions.""" | 104 """Gets commit_positions and review_urls for revisions.""" |
| 23 culprits = {} | 105 culprits = {} |
| 106 # TODO(lijeffrey): remove hard-coded 'chromium' when DEPS file parsing is | |
| 107 # supported. | |
| 24 for failed_revision in failed_revisions: | 108 for failed_revision in failed_revisions: |
| 25 culprits[failed_revision] = { | 109 culprits[failed_revision] = { |
| 26 'revision': failed_revision | 110 'revision': failed_revision, |
| 111 'repo_name': 'chromium' | |
| 27 } | 112 } |
| 28 change_log = GIT_REPO.GetChangeLog(failed_revision) | 113 change_log = GIT_REPO.GetChangeLog(failed_revision) |
| 29 if change_log: | 114 if change_log: |
| 30 culprits[failed_revision]['commit_position'] = ( | 115 culprits[failed_revision]['commit_position'] = ( |
| 31 change_log.commit_position) | 116 change_log.commit_position) |
| 32 culprits[failed_revision]['review_url'] = change_log.code_review_url | 117 culprits[failed_revision]['review_url'] = change_log.code_review_url |
| 33 | 118 |
| 34 return culprits | 119 return culprits |
| 35 | 120 |
| 36 @staticmethod | 121 @staticmethod |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 | 184 |
| 100 if step not in culprit_map: | 185 if step not in culprit_map: |
| 101 culprit_map[step] = { | 186 culprit_map[step] = { |
| 102 'tests': {} | 187 'tests': {} |
| 103 } | 188 } |
| 104 | 189 |
| 105 if (not test_result['failures'] and | 190 if (not test_result['failures'] and |
| 106 not culprit_map[step].get('revision')): | 191 not culprit_map[step].get('revision')): |
| 107 # Non swarming test failures, only have step level failure info. | 192 # Non swarming test failures, only have step level failure info. |
| 108 culprit_map[step]['revision'] = revision | 193 culprit_map[step]['revision'] = revision |
| 194 culprit_map[step]['repo_name'] = 'chromium' | |
| 109 | 195 |
| 110 for failed_test in test_result['failures']: | 196 for failed_test in test_result['failures']: |
| 111 # Swarming tests, gets first failed revision for each test. | 197 # Swarming tests, gets first failed revision for each test. |
| 112 if failed_test not in culprit_map[step]['tests']: | 198 if failed_test not in culprit_map[step]['tests']: |
| 113 culprit_map[step]['tests'][failed_test] = { | 199 culprit_map[step]['tests'][failed_test] = { |
| 114 'revision': revision | 200 'revision': revision |
| 115 } | 201 } |
| 116 | 202 |
| 117 return culprit_map, failed_revisions | 203 return culprit_map, failed_revisions |
| 118 | 204 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 try_job_result.test_results) | 267 try_job_result.test_results) |
| 182 if (result_to_update and | 268 if (result_to_update and |
| 183 result_to_update[-1]['try_job_id'] == try_job_id): | 269 result_to_update[-1]['try_job_id'] == try_job_id): |
| 184 result_to_update[-1].update(result) | 270 result_to_update[-1].update(result) |
| 185 else: # pragma: no cover | 271 else: # pragma: no cover |
| 186 result_to_update.append(result) | 272 result_to_update.append(result) |
| 187 | 273 |
| 188 try_job_result.status = analysis_status.COMPLETED | 274 try_job_result.status = analysis_status.COMPLETED |
| 189 try_job_result.put() | 275 try_job_result.put() |
| 190 | 276 |
| 277 # Update analysis result and suspected CLs with results of this try job. | |
| 278 analysis = WfAnalysis.Get(master_name, builder_name, build_number) | |
|
stgao
2016/04/12 22:41:19
nit: If ``culprits`` is None or empty (which means
lijeffrey
2016/04/13 21:36:24
This is in case analysis_result was set to None by
lijeffrey
2016/04/13 22:50:17
Done. Per discussion we don't want to update even
| |
| 279 updated_result_status = _GetResultAnalysisStatus(analysis, result) | |
| 280 updated_suspected_cls = _GetSuspectedCLs(analysis, result) | |
| 281 | |
| 282 if (analysis.result_status != updated_result_status or | |
| 283 analysis.suspected_cls != updated_suspected_cls): | |
| 284 analysis.result_status = updated_result_status | |
| 285 analysis.suspected_cls = updated_suspected_cls | |
|
stgao
2016/04/12 22:41:19
A datastore write is needed as we want to update a
lijeffrey
2016/04/13 21:36:24
Done. Good catch, was accidentally deleted.
| |
| 286 | |
| 191 return result.get('culprit') if result else None | 287 return result.get('culprit') if result else None |
| OLD | NEW |