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

Side by Side Diff: appengine/findit/model/crash/crash_analysis.py

Issue 2523343002: [Predator] Refactor ToPublishResult and fix keyerror 'found' (Closed)
Patch Set: . Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 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 import copy 5 import copy
6 import hashlib 6 import hashlib
7 import json 7 import json
8 import logging 8 import logging
9 9
10 from google.appengine.ext import ndb 10 from google.appengine.ext import ndb
11 11
12 from common import appengine_util
13 from crash.type_enums import CrashClient 12 from crash.type_enums import CrashClient
14 from model import analysis_status 13 from model import analysis_status
15 from model import triage_status 14 from model import triage_status
16 15
17 # TODO(katesonia): Move this to fracas config.
18 _FINDIT_FRACAS_FEEDBACK_URL_TEMPLATE = '%s/crash/fracas-result-feedback?key=%s'
19 16
20 class CrashAnalysis(ndb.Model): 17 class CrashAnalysis(ndb.Model):
21 """Base class to represent an analysis of a Chrome/Clusterfuzz crash.""" 18 """Base class to represent an analysis of a Chrome/Clusterfuzz crash."""
22 ################### Properties for the crash itself. ################### 19 ################### Properties for the crash itself. ###################
23 # In which version or revision of Chrome the crash occurred. Either a version 20 # In which version or revision of Chrome the crash occurred. Either a version
24 # number for Chrome build or a git commit hash/position for chromium build. 21 # number for Chrome build or a git commit hash/position for chromium build.
25 crashed_version = ndb.StringProperty(indexed=False) 22 crashed_version = ndb.StringProperty(indexed=False)
26 23
27 # The stack_trace_string. 24 # The stack_trace_string.
28 stack_trace = ndb.StringProperty(indexed=False) 25 stack_trace = ndb.StringProperty(indexed=False)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 json.dumps(crash_identifiers, sort_keys=True)).hexdigest()) 146 json.dumps(crash_identifiers, sort_keys=True)).hexdigest())
150 147
151 @classmethod 148 @classmethod
152 def Get(cls, crash_identifiers): 149 def Get(cls, crash_identifiers):
153 return cls._CreateKey(crash_identifiers).get() 150 return cls._CreateKey(crash_identifiers).get()
154 151
155 @classmethod 152 @classmethod
156 def Create(cls, crash_identifiers): 153 def Create(cls, crash_identifiers):
157 return cls(key=cls._CreateKey(crash_identifiers)) 154 return cls(key=cls._CreateKey(crash_identifiers))
158 155
156 def ProcessResultForPublishing(self, result):
157 """Client specific processing of result data for publishing."""
158 raise NotImplementedError()
159
159 def ToPublishableResult(self, crash_identifiers): 160 def ToPublishableResult(self, crash_identifiers):
160 """Convert this datastore analysis into a publishable result. 161 """Convert this datastore analysis into a publishable result.
161 162
163 Note, this function must be called by concret subclass of CrashAnalysis
wrengr 2016/11/29 22:11:12 "concret" -> "a concrete"
Sharu Jiang 2016/11/30 02:37:00 Done.
stgao 2016/11/30 04:35:07 I don't think this is actually done. The misspell
Sharu Jiang 2016/11/30 18:14:07 Oops, done.
164 which implements ProcessResultForPublishing abstract function.
wrengr 2016/11/29 22:11:12 -> "which implements the ProcessResultForPublishin
Sharu Jiang 2016/11/30 02:37:00 Done.
165
162 Args: 166 Args:
163 crash_identifiers (dict): ?? 167 crash_identifiers (dict): Dict containing identifiers that can uniquely
168 identify CrashAnalysis entity.
164 169
165 Returns: 170 Returns:
166 A dict of the given ``crash_identifiers``, this model's 171 A dict of the given ``crash_identifiers``, this model's
167 ``client_id``, and a publishable version of this model's ``result``. 172 ``client_id``, and a publishable version of this model's ``result``.
168 """ 173 """
169 result = copy.deepcopy(self.result) 174 result = copy.deepcopy(self.result)
170 client_id = self.client_id 175 if result.get('found') and 'suspected_cls' in result:
176 for cl in result['suspected_cls']:
177 cl['confidence'] = round(cl['confidence'], 2)
178 cl.pop('reason', None)
171 179
172 # TODO(katesonia): move this to ChromeCrashAnalysis 180 result = self.ProcessResultForPublishing(result)
173 if (client_id == CrashClient.FRACAS or
174 client_id == CrashClient.CRACAS):
175 result['feedback_url'] = _FINDIT_FRACAS_FEEDBACK_URL_TEMPLATE % (
176 appengine_util.GetDefaultVersionHostname(), self.key.urlsafe())
177 if result['found'] and 'suspected_cls' in result:
178 for cl in result['suspected_cls']:
179 cl['confidence'] = round(cl['confidence'], 2)
180 cl.pop('reason', None)
181 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover.
182 # TODO(katesonia): Post process clusterfuzz model result if needed.
183 pass
184
185 logging.info('Publish result:\n%s', 181 logging.info('Publish result:\n%s',
186 json.dumps(result, indent=4, sort_keys=True)) 182 json.dumps(result, indent=4, sort_keys=True))
187 return { 183 return {
188 'crash_identifiers': crash_identifiers, 184 'crash_identifiers': crash_identifiers,
189 'client_id': client_id, 185 'client_id': self.client_id,
wrengr 2016/11/29 22:11:12 Since you removed the line where we initialized se
Sharu Jiang 2016/11/30 02:37:00 I think the self.client_id would always exists sin
190 'result': result, 186 'result': result,
191 } 187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698