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

Side by Side Diff: appengine/findit/handlers/triage_analysis.py

Issue 2086113004: [Findit] Show build analysis references in UI for Findit Cross-platform auto-triage (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@build-matching
Patch Set: Merged with build-matching Created 4 years, 5 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
OLDNEW
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
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.
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
116 triage_record = { 125 triage_record = {
117 'triage_timestamp': calendar.timegm(datetime.utcnow().timetuple()), 126 'triage_timestamp': calendar.timegm(datetime.utcnow().timetuple()),
118 'user_name': user_name, 127 'user_name': user_name,
119 'result_status': analysis.result_status, 128 'result_status': analysis.result_status,
120 'version': analysis.version, 129 'version': analysis.version,
121 } 130 }
122 if not analysis.triage_history: 131 if not analysis.triage_history:
123 analysis.triage_history = [] 132 analysis.triage_history = []
124 analysis.triage_history.append(triage_record) 133 analysis.triage_history.append(triage_record)
125 134
126 analysis.put() 135 analysis.put()
127 136
128 137
129 @ndb.transactional 138 @ndb.transactional
130 def _UpdateAnalysisResultStatus( 139 def _UpdateAnalysisResultStatus(
131 master_name, builder_name, build_number, is_correct, user_name=None): 140 master_name, builder_name, build_number, is_correct, user_name=None):
132 analysis = WfAnalysis.Get(master_name, builder_name, build_number) 141 analysis = WfAnalysis.Get(master_name, builder_name, build_number)
133 if not analysis or not analysis.completed: 142 if not analysis or not analysis.completed:
134 return False, None 143 return False, None
135 144
145 analysis.triage_reference_analysis_master_name = None
146 analysis.triage_reference_analysis_builder_name = None
147 analysis.triage_reference_analysis_build_number = None
148
136 _AppendTriageHistoryRecord(analysis, is_correct, user_name) 149 _AppendTriageHistoryRecord(analysis, is_correct, user_name)
137 150
138 return True, analysis 151 return True, analysis
139 152
140 153
141 def _GetDuplicateAnalyses(original_analysis): 154 def _GetDuplicateAnalyses(original_analysis):
142 start_time = (original_analysis.build_start_time - 155 start_time = (original_analysis.build_start_time -
143 timedelta(hours=MATCHING_ANALYSIS_HOURS_AGO_START)) 156 timedelta(hours=MATCHING_ANALYSIS_HOURS_AGO_START))
144 end_time = (original_analysis.build_start_time + 157 end_time = (original_analysis.build_start_time +
145 timedelta(hours=MATCHING_ANALYSIS_HOURS_AGO_END)) 158 timedelta(hours=MATCHING_ANALYSIS_HOURS_AGO_END))
(...skipping 10 matching lines...) Expand all
156 # Set hours and minutes to 0 to get midnight. 169 # Set hours and minutes to 0 to get midnight.
157 local_midnight_as_local = current_time_as_local.replace( 170 local_midnight_as_local = current_time_as_local.replace(
158 hour=0, minute=0, second=0, microsecond=0) 171 hour=0, minute=0, second=0, microsecond=0)
159 172
160 # Convert back to UTC time. 173 # Convert back to UTC time.
161 local_midnight_as_utc = local_midnight_as_local.astimezone(pytz.utc) 174 local_midnight_as_utc = local_midnight_as_local.astimezone(pytz.utc)
162 175
163 # Strip timezone. 176 # Strip timezone.
164 local_midnight = local_midnight_as_utc.replace(tzinfo=None) 177 local_midnight = local_midnight_as_utc.replace(tzinfo=None)
165 178
166 if end_time > local_midnight: # pragma: no branch 179 if end_time > local_midnight:
167 end_time = local_midnight 180 end_time = local_midnight
168 181
169 # Retrieve potential duplicate build analyses. 182 # Retrieve potential duplicate build analyses.
170 analysis_results = WfAnalysis.query(ndb.AND( 183 analysis_results = WfAnalysis.query(ndb.AND(
171 WfAnalysis.build_start_time >= start_time, 184 WfAnalysis.build_start_time >= start_time,
172 WfAnalysis.build_start_time <= end_time, 185 WfAnalysis.build_start_time <= end_time,
173 WfAnalysis.result_status == result_status.FOUND_UNTRIAGED 186 WfAnalysis.result_status == result_status.FOUND_UNTRIAGED
174 )).fetch() 187 )).fetch()
175 188
176 # Further filter potential duplicates and return them. 189 # Further filter potential duplicates and return them.
177 return [analysis for analysis in analysis_results if 190 return [analysis for analysis in analysis_results if
191 analysis.completed and
192 analysis.result and
178 _DoAnalysesMatch(original_analysis, analysis) and 193 _DoAnalysesMatch(original_analysis, analysis) and
179 original_analysis.key is not analysis.key and 194 original_analysis.key is not analysis.key]
180 analysis.completed]
181 195
182 196
183 def _TriageDuplicateResults(original_analysis, is_correct, user_name=None): 197 def _TriageAndCountDuplicateResults(original_analysis, is_correct,
198 user_name=None):
184 matching_analyses = _GetDuplicateAnalyses(original_analysis) 199 matching_analyses = _GetDuplicateAnalyses(original_analysis)
185 200
186 for analysis in matching_analyses: 201 for analysis in matching_analyses:
187 _AppendTriageHistoryRecord(analysis, is_correct, user_name) 202 analysis.triage_reference_analysis_master_name = (
203 original_analysis.master_name)
204 analysis.triage_reference_analysis_builder_name = (
205 original_analysis.builder_name)
206 analysis.triage_reference_analysis_build_number = (
207 original_analysis.build_number)
208 _AppendTriageHistoryRecord(analysis, is_correct, user_name,
209 is_duplicate=True)
210
211 return len(matching_analyses)
188 212
189 213
190 class TriageAnalysis(BaseHandler): 214 class TriageAnalysis(BaseHandler):
191 PERMISSION_LEVEL = Permission.CORP_USER 215 PERMISSION_LEVEL = Permission.CORP_USER
192 216
193 def HandleGet(self): # pragma: no cover 217 def HandleGet(self): # pragma: no cover
194 return self.HandlePost() 218 return self.HandlePost()
195 219
196 def HandlePost(self): 220 def HandlePost(self):
197 """Sets the manual triage result for the analysis. 221 """Sets the manual triage result for the analysis.
198 222
199 Mark the analysis result as correct/wrong/etc. 223 Mark the analysis result as correct/wrong/etc.
200 TODO: make it possible to set the real culprit CLs. 224 TODO: make it possible to set the real culprit CLs.
201 """ 225 """
202 url = self.request.get('url').strip() 226 url = self.request.get('url').strip()
203 build_info = buildbot.ParseBuildUrl(url) 227 build_info = buildbot.ParseBuildUrl(url)
204 if not build_info: 228 if not build_info:
205 return {'data': {'success': False}} 229 return {'data': {'success': False}}
206 master_name, builder_name, build_number = build_info 230 master_name, builder_name, build_number = build_info
207 231
208 is_correct = self.request.get('correct').lower() == 'true' 232 is_correct = self.request.get('correct').lower() == 'true'
209 # As the permission level is CORP_USER, we could assume the current user 233 # As the permission level is CORP_USER, we could assume the current user
210 # already logged in. 234 # already logged in.
211 user_name = users.get_current_user().email().split('@')[0] 235 user_name = users.get_current_user().email().split('@')[0]
212 success, original_analysis = _UpdateAnalysisResultStatus( 236 success, original_analysis = _UpdateAnalysisResultStatus(
213 master_name, builder_name, build_number, is_correct, user_name) 237 master_name, builder_name, build_number, is_correct, user_name)
238 num_duplicate_analyses = 0
214 if success: 239 if success:
215 _TriageDuplicateResults(original_analysis, is_correct, user_name) 240 num_duplicate_analyses = _TriageAndCountDuplicateResults(
216 return {'data': {'success': success}} 241 original_analysis, is_correct, user_name)
242 return {'data': {'success': success,
243 'num_duplicate_analyses': num_duplicate_analyses}}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698