Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """This module is to handle manual triage of analysis result. | 5 """This module is to handle manual triage of analysis result. |
| 6 | 6 |
| 7 This handler will flag the analysis result as correct or incorrect. | 7 This handler will flag the analysis result as correct or incorrect. |
| 8 TODO: work on an automatic or semi-automatic way to triage analysis result. | 8 TODO: work on an automatic or semi-automatic way to triage analysis result. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 | 83 |
| 84 # Both analyses must have non-empty potential culprit lists. | 84 # Both analyses must have non-empty potential culprit lists. |
| 85 if not potential_culprit_tuple_list_1 or not potential_culprit_tuple_list_2: | 85 if not potential_culprit_tuple_list_1 or not potential_culprit_tuple_list_2: |
| 86 return False | 86 return False |
| 87 | 87 |
| 88 # Both analyses must have matching potential culprit lists. | 88 # Both analyses must have matching potential culprit lists. |
| 89 return (sorted(potential_culprit_tuple_list_1) == | 89 return (sorted(potential_culprit_tuple_list_1) == |
| 90 sorted(potential_culprit_tuple_list_2)) | 90 sorted(potential_culprit_tuple_list_2)) |
| 91 | 91 |
| 92 | 92 |
| 93 def _AppendTriageHistoryRecord(analysis, is_correct, user_name): | 93 def _AppendTriageHistoryRecord( |
| 94 analysis, is_correct, user_name, is_duplicate=False): | |
| 94 """Appends a triage history record to the given analysis. | 95 """Appends a triage history record to the given analysis. |
| 95 | 96 |
| 96 Args: | 97 Args: |
| 97 analysis: The analysis to which to append the history record. | 98 analysis: The analysis to which to append the history record. |
| 98 is_correct: True if the history record should indicate a correct judgement, | 99 is_correct: True if the history record should indicate a correct judgement, |
| 99 otherwise False. | 100 otherwise False. |
| 100 user_name: The user_name of the person to include in the triage record. | 101 user_name: The user_name of the person to include in the triage record. |
| 102 is_duplicate: True if the history record should indicate that this triage is | |
| 103 a duplicate, otherwise False. | |
|
chanli
2016/06/30 23:52:25
After the discussion, is_duplicate is not determin
josiahk
2016/07/01 21:45:27
Thanks! I have changed the docstring.
| |
| 101 """ | 104 """ |
| 102 if is_correct: | 105 if is_correct: |
| 103 if analysis.suspected_cls: | 106 if analysis.suspected_cls: |
| 104 analysis.result_status = result_status.FOUND_CORRECT | 107 if is_duplicate: |
| 108 analysis.result_status = result_status.FOUND_CORRECT_DUPLICATE | |
| 109 else: | |
| 110 analysis.result_status = result_status.FOUND_CORRECT | |
| 105 analysis.culprit_cls = analysis.suspected_cls | 111 analysis.culprit_cls = analysis.suspected_cls |
| 106 else: | 112 else: |
| 107 analysis.result_status = result_status.NOT_FOUND_CORRECT | 113 analysis.result_status = result_status.NOT_FOUND_CORRECT |
| 108 analysis.culprit_cls = None | 114 analysis.culprit_cls = None |
| 109 else: | 115 else: |
| 110 analysis.culprit_cls = None | 116 analysis.culprit_cls = None |
| 111 if analysis.suspected_cls: | 117 if analysis.suspected_cls: |
| 112 analysis.result_status = result_status.FOUND_INCORRECT | 118 if is_duplicate: |
| 119 analysis.result_status = result_status.FOUND_INCORRECT_DUPLICATE | |
| 120 else: | |
| 121 analysis.result_status = result_status.FOUND_INCORRECT | |
| 113 else: | 122 else: |
| 114 analysis.result_status = result_status.NOT_FOUND_INCORRECT | 123 analysis.result_status = result_status.NOT_FOUND_INCORRECT |
| 115 | 124 |
| 125 if not is_duplicate: | |
| 126 # Resets the reference to the "duplicator" triage analysis. | |
|
chanli
2016/06/30 23:46:37
This comment is a little confusing...
How about a
josiahk
2016/07/01 21:45:27
Done.
| |
| 127 analysis.triage_reference_analysis_master_name = None | |
| 128 analysis.triage_reference_analysis_builder_name = None | |
| 129 analysis.triage_reference_analysis_build_number = None | |
| 130 | |
| 116 triage_record = { | 131 triage_record = { |
| 117 'triage_timestamp': calendar.timegm(datetime.utcnow().timetuple()), | 132 'triage_timestamp': calendar.timegm(datetime.utcnow().timetuple()), |
| 118 'user_name': user_name, | 133 'user_name': user_name, |
| 119 'result_status': analysis.result_status, | 134 'result_status': analysis.result_status, |
| 120 'version': analysis.version, | 135 'version': analysis.version, |
| 121 } | 136 } |
| 122 if not analysis.triage_history: | 137 if not analysis.triage_history: |
| 123 analysis.triage_history = [] | 138 analysis.triage_history = [] |
| 124 analysis.triage_history.append(triage_record) | 139 analysis.triage_history.append(triage_record) |
| 125 | 140 |
| 126 analysis.put() | 141 analysis.put() |
| 127 | 142 |
| 128 | 143 |
| 129 @ndb.transactional | 144 @ndb.transactional |
| 130 def _UpdateAnalysisResultStatus( | 145 def _UpdateAnalysisResultStatus( |
| 131 master_name, builder_name, build_number, is_correct, user_name=None): | 146 master_name, builder_name, build_number, is_correct, user_name=None): |
| 132 analysis = WfAnalysis.Get(master_name, builder_name, build_number) | 147 analysis = WfAnalysis.Get(master_name, builder_name, build_number) |
| 133 if not analysis or not analysis.completed: | 148 if not analysis or not analysis.completed: |
| 134 return False, None | 149 return False, None |
| 135 | 150 |
| 136 _AppendTriageHistoryRecord(analysis, is_correct, user_name) | 151 _AppendTriageHistoryRecord(analysis, is_correct, user_name, |
| 152 is_duplicate=False) | |
| 137 | 153 |
| 138 return True, analysis | 154 return True, analysis |
| 139 | 155 |
| 140 | 156 |
| 141 def _GetDuplicateAnalyses(original_analysis): | 157 def _GetDuplicateAnalyses(original_analysis): |
| 142 start_time = (original_analysis.build_start_time - | 158 start_time = (original_analysis.build_start_time - |
| 143 timedelta(hours=MATCHING_ANALYSIS_HOURS_AGO_START)) | 159 timedelta(hours=MATCHING_ANALYSIS_HOURS_AGO_START)) |
| 144 end_time = (original_analysis.build_start_time + | 160 end_time = (original_analysis.build_start_time + |
| 145 timedelta(hours=MATCHING_ANALYSIS_HOURS_AGO_END)) | 161 timedelta(hours=MATCHING_ANALYSIS_HOURS_AGO_END)) |
| 146 | 162 |
| 147 # Don't count any analyses from today (except for exactly at midnight local | 163 # Don't count any analyses from today (except for exactly at midnight local |
| 148 # time). | 164 # time). |
| 149 # Get current time (UTC). | 165 # Get current time (UTC). |
| 150 current_time_as_utc = pytz.utc.localize(datetime.utcnow()) | 166 current_time_as_utc = pytz.utc.localize(datetime.utcnow()) |
| 151 | 167 |
| 152 # Convert to local time. | 168 # Convert to local time. |
| 153 current_time_as_local = current_time_as_utc.astimezone( | 169 current_time_as_local = current_time_as_utc.astimezone( |
| 154 pytz.timezone(MATCHING_ANALYSIS_END_BOUND_TIME_ZONE)) | 170 pytz.timezone(MATCHING_ANALYSIS_END_BOUND_TIME_ZONE)) |
| 155 | 171 |
| 156 # Set hours and minutes to 0 to get midnight. | 172 # Set hours and minutes to 0 to get midnight. |
| 157 local_midnight_as_local = current_time_as_local.replace( | 173 local_midnight_as_local = current_time_as_local.replace( |
| 158 hour=0, minute=0, second=0, microsecond=0) | 174 hour=0, minute=0, second=0, microsecond=0) |
| 159 | 175 |
| 160 # Convert back to UTC time. | 176 # Convert back to UTC time. |
| 161 local_midnight_as_utc = local_midnight_as_local.astimezone(pytz.utc) | 177 local_midnight_as_utc = local_midnight_as_local.astimezone(pytz.utc) |
| 162 | 178 |
| 163 # Strip timezone. | 179 # Strip timezone. |
| 164 local_midnight = local_midnight_as_utc.replace(tzinfo=None) | 180 local_midnight = local_midnight_as_utc.replace(tzinfo=None) |
| 165 | 181 |
| 166 if end_time > local_midnight: # pragma: no branch | 182 if end_time > local_midnight: |
| 167 end_time = local_midnight | 183 end_time = local_midnight |
| 168 | 184 |
| 169 # Retrieve potential duplicate build analyses. | 185 # Retrieve potential duplicate build analyses. |
| 170 analysis_results = WfAnalysis.query(ndb.AND( | 186 analysis_results = WfAnalysis.query(ndb.AND( |
| 171 WfAnalysis.build_start_time >= start_time, | 187 WfAnalysis.build_start_time >= start_time, |
| 172 WfAnalysis.build_start_time <= end_time, | 188 WfAnalysis.build_start_time <= end_time, |
| 173 WfAnalysis.result_status == result_status.FOUND_UNTRIAGED | 189 WfAnalysis.result_status == result_status.FOUND_UNTRIAGED |
| 174 )).fetch() | 190 )).fetch() |
| 175 | 191 |
| 176 # Further filter potential duplicates and return them. | 192 # Further filter potential duplicates and return them. |
| 177 return [analysis for analysis in analysis_results if | 193 return [analysis for analysis in analysis_results if |
| 194 analysis.completed and | |
| 195 analysis.result and | |
| 178 _DoAnalysesMatch(original_analysis, analysis) and | 196 _DoAnalysesMatch(original_analysis, analysis) and |
| 179 original_analysis.key is not analysis.key and | 197 original_analysis.key is not analysis.key] |
| 180 analysis.completed] | |
| 181 | 198 |
| 182 | 199 |
| 183 def _TriageDuplicateResults(original_analysis, is_correct, user_name=None): | 200 def _TriageAndCountDuplicateResults(original_analysis, is_correct, |
| 201 user_name=None): | |
| 184 matching_analyses = _GetDuplicateAnalyses(original_analysis) | 202 matching_analyses = _GetDuplicateAnalyses(original_analysis) |
| 185 | 203 |
| 186 for analysis in matching_analyses: | 204 for analysis in matching_analyses: |
| 187 _AppendTriageHistoryRecord(analysis, is_correct, user_name) | 205 analysis.triage_reference_analysis_master_name = ( |
| 206 original_analysis.master_name) | |
| 207 analysis.triage_reference_analysis_builder_name = ( | |
| 208 original_analysis.builder_name) | |
| 209 analysis.triage_reference_analysis_build_number = ( | |
| 210 original_analysis.build_number) | |
| 211 _AppendTriageHistoryRecord(analysis, is_correct, user_name, | |
| 212 is_duplicate=True) | |
| 213 | |
| 214 return len(matching_analyses) | |
| 188 | 215 |
| 189 | 216 |
| 190 class TriageAnalysis(BaseHandler): | 217 class TriageAnalysis(BaseHandler): |
| 191 PERMISSION_LEVEL = Permission.CORP_USER | 218 PERMISSION_LEVEL = Permission.CORP_USER |
| 192 | 219 |
| 193 def HandleGet(self): # pragma: no cover | 220 def HandleGet(self): # pragma: no cover |
| 194 return self.HandlePost() | 221 return self.HandlePost() |
| 195 | 222 |
| 196 def HandlePost(self): | 223 def HandlePost(self): |
| 197 """Sets the manual triage result for the analysis. | 224 """Sets the manual triage result for the analysis. |
| 198 | 225 |
| 199 Mark the analysis result as correct/wrong/etc. | 226 Mark the analysis result as correct/wrong/etc. |
| 200 TODO: make it possible to set the real culprit CLs. | 227 TODO: make it possible to set the real culprit CLs. |
| 201 """ | 228 """ |
| 202 url = self.request.get('url').strip() | 229 url = self.request.get('url').strip() |
| 203 build_info = buildbot.ParseBuildUrl(url) | 230 build_info = buildbot.ParseBuildUrl(url) |
| 204 if not build_info: | 231 if not build_info: |
| 205 return {'data': {'success': False}} | 232 return {'data': {'success': False}} |
| 206 master_name, builder_name, build_number = build_info | 233 master_name, builder_name, build_number = build_info |
| 207 | 234 |
| 208 is_correct = self.request.get('correct').lower() == 'true' | 235 is_correct = self.request.get('correct').lower() == 'true' |
| 209 # As the permission level is CORP_USER, we could assume the current user | 236 # As the permission level is CORP_USER, we could assume the current user |
| 210 # already logged in. | 237 # already logged in. |
| 211 user_name = users.get_current_user().email().split('@')[0] | 238 user_name = users.get_current_user().email().split('@')[0] |
| 212 success, original_analysis = _UpdateAnalysisResultStatus( | 239 success, original_analysis = _UpdateAnalysisResultStatus( |
| 213 master_name, builder_name, build_number, is_correct, user_name) | 240 master_name, builder_name, build_number, is_correct, user_name) |
| 241 num_duplicate_analyses = 0 | |
| 214 if success: | 242 if success: |
| 215 _TriageDuplicateResults(original_analysis, is_correct, user_name) | 243 num_duplicate_analyses = _TriageAndCountDuplicateResults( |
| 216 return {'data': {'success': success}} | 244 original_analysis, is_correct, user_name) |
| 245 return {'data': {'success': success, | |
| 246 'num_duplicate_analyses': num_duplicate_analyses}} | |
| OLD | NEW |