| OLD | NEW |
| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 return ndb.Key(cls.__name__, hashlib.sha1( | 145 return ndb.Key(cls.__name__, hashlib.sha1( |
| 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 | |
| 159 def ToPublishableResult(self, crash_identifiers): | |
| 160 """Convert this datastore analysis into a publishable result. | |
| 161 | |
| 162 Args: | |
| 163 crash_identifiers (dict): ?? | |
| 164 | |
| 165 Returns: | |
| 166 A dict of the given ``crash_identifiers``, this model's | |
| 167 ``client_id``, and a publishable version of this model's ``result``. | |
| 168 """ | |
| 169 result = copy.deepcopy(self.result) | |
| 170 client_id = self.client_id | |
| 171 | |
| 172 # TODO(katesonia): move this to ChromeCrashAnalysis | |
| 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', | |
| 186 json.dumps(result, indent=4, sort_keys=True)) | |
| 187 return { | |
| 188 'crash_identifiers': crash_identifiers, | |
| 189 'client_id': client_id, | |
| 190 'result': result, | |
| 191 } | |
| OLD | NEW |