Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """This module is interfacas between clients-specific code and core. | |
| 6 | |
| 7 Note, fracas and cracas are almost identical and fracas is an intermidiate | |
| 8 state while transfering to cracas, so they can be handled in the same code path | |
| 9 and can be refered to as chromecrash.""" | |
|
lijeffrey
2016/09/16 16:28:56
nit: referred
Sharu Jiang
2016/09/19 21:36:00
Done.
| |
| 10 | |
| 11 import copy | |
| 12 import json | |
| 13 import logging | |
| 14 | |
| 15 from google.appengine.ext import ndb | |
| 16 | |
| 17 from common import appengine_util | |
| 18 from common import time_util | |
| 19 from crash import findit_for_chromecrash | |
| 20 from crash.type_enums import CrashClient | |
| 21 from model import analysis_status | |
| 22 from model.crash.crash_config import CrashConfig | |
| 23 from model.crash.fracas_crash_analysis import FracasCrashAnalysis | |
| 24 | |
| 25 _FINDIT_FRACAS_FEEDBACK_URL_TEMPLATE = '%s/crash/fracas-result-feedback?key=%s' | |
| 26 | |
| 27 | |
| 28 def CheckPolicyForClient(crash_identifiers, chrome_version, signature, | |
| 29 client_id, platform, stack_trace, customized_data): | |
| 30 """Checks if the args pass the client policy or not, update the parameters | |
|
lijeffrey
2016/09/16 16:28:56
nit: I'm not sure this docstring is formatted corr
Sharu Jiang
2016/09/19 21:36:00
Done.
| |
| 31 if needed.""" | |
| 32 crash_config = CrashConfig.Get() | |
| 33 | |
| 34 # Cracas and Fracas share the sampe policy. | |
| 35 if client_id == CrashClient.FRACAS or client_id == CrashClient.CRACAS: | |
| 36 if platform not in crash_config.fracas.get( | |
|
Martin Barbella
2016/09/17 23:20:35
Same concerns here that were mentioned in the othe
Sharu Jiang
2016/09/19 21:36:00
Right, this is in the TODO plans, will do this in
| |
| 37 'supported_platform_list_by_channel', {}).get( | |
| 38 customized_data.get('channel'), []): | |
|
lijeffrey
2016/09/16 16:28:56
split out customized_data.get('channel') since it'
Sharu Jiang
2016/09/19 21:35:59
Done.
| |
| 39 # Bail out if either the channel or platform is not supported yet. | |
| 40 logging.info('Ananlysis of channel %s, platform %s is not supported. ' | |
| 41 'No analysis is scheduled for %s', | |
| 42 customized_data.get('channel'), platform, | |
| 43 repr(crash_identifiers)) | |
| 44 return False, None | |
| 45 | |
| 46 # TODO(katesonia): Remove the default value after adding validity check to | |
| 47 # config. | |
| 48 for blacklist_marker in crash_config.fracas.get( | |
| 49 'signature_blacklist_markers', []): | |
| 50 if blacklist_marker in signature: | |
| 51 logging.info('%s signature is not supported. ' | |
| 52 'No analysis is scheduled for %s', blacklist_marker, | |
| 53 repr(crash_identifiers)) | |
| 54 return False, None | |
| 55 | |
| 56 # TODO(katesonia): Remove the default value after adding validity check to | |
| 57 # config. | |
| 58 platform_rename = crash_config.fracas.get('platform_rename', {}) | |
| 59 platform = platform_rename.get(platform, platform) | |
| 60 | |
| 61 # TODO(katesonia): Add clusterfuzz policy check. | |
|
lijeffrey
2016/09/16 16:28:55
nit: I would move this todo to inside the if state
Sharu Jiang
2016/09/19 21:36:00
Done.
| |
| 62 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. | |
| 63 pass | |
| 64 | |
| 65 return True, (crash_identifiers, chrome_version, signature, client_id, | |
| 66 platform, stack_trace, customized_data) | |
| 67 | |
| 68 | |
| 69 def GetAnalysisForClient(crash_identifiers, client_id): | |
| 70 analysis = None | |
| 71 if client_id == CrashClient.FRACAS: | |
| 72 analysis = FracasCrashAnalysis.Get(crash_identifiers) | |
| 73 elif client_id == CrashClient.CRACAS: # pragma: no cover. | |
| 74 # TODO(katesonia): Add CracasCrashAnalysis model. | |
| 75 pass | |
| 76 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. | |
| 77 # TODO(katesonia): Add ClusterfuzzCrashAnalysis model. | |
| 78 pass | |
| 79 | |
| 80 return analysis | |
| 81 | |
| 82 | |
| 83 def ResetAnalysis(analysis, crash_identifiers, chrome_version, signature, | |
| 84 client_id, platform, stack_trace, customized_data): | |
| 85 """Resets analysis and returns if analysis get successfully reset or not.""" | |
|
lijeffrey
2016/09/16 16:28:56
nit: """... and returns whether analysis was succe
Sharu Jiang
2016/09/19 21:35:59
Done.
| |
| 86 if not analysis: | |
|
Martin Barbella
2016/09/17 23:20:35
What's the intention of this? I don't fully unders
Sharu Jiang
2016/09/19 21:35:59
If it's the first time to analyze this crash, we n
| |
| 87 # A new analysis is needed if there is no analysis. | |
| 88 if client_id == CrashClient.FRACAS: | |
| 89 analysis = FracasCrashAnalysis.Create(crash_identifiers) | |
| 90 elif client_id == CrashClient.CRACAS: # pragma: no cover. | |
| 91 # TODO(katesonia): define CracasCrashAnalysis. | |
| 92 return False | |
| 93 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. | |
| 94 # TODO(katesonia): define ClusterfuzzCrashAnalysis. | |
| 95 return False | |
| 96 else: | |
| 97 # The client id is not supported. | |
| 98 return False | |
| 99 | |
| 100 analysis.Reset() | |
| 101 | |
| 102 # Set common properties. | |
| 103 analysis.crashed_version = chrome_version | |
| 104 analysis.stack_trace = stack_trace | |
| 105 analysis.signature = signature | |
| 106 analysis.platform = platform | |
| 107 analysis.client_id = client_id | |
| 108 | |
| 109 if client_id == CrashClient.FRACAS or client_id == CrashClient.CRACAS: | |
| 110 # Set customized properties. | |
| 111 analysis.historical_metadata = customized_data.get('historical_metadata') | |
| 112 analysis.channel = customized_data.get('channel') | |
| 113 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. | |
| 114 # TODO(katesonia): Set up clusterfuzz customized data. | |
| 115 pass | |
| 116 | |
| 117 # Set analysis progress properties. | |
| 118 analysis.status = analysis_status.PENDING | |
| 119 analysis.requested_time = time_util.GetUTCNow() | |
| 120 | |
| 121 analysis.put() | |
| 122 return True | |
| 123 | |
| 124 | |
| 125 def GetPublishResultFromAnalysis(analysis, crash_identifiers, client_id): | |
| 126 """Gets result to be published to client from datastore analysis.""" | |
| 127 analysis_result = copy.deepcopy(analysis.result) | |
| 128 | |
| 129 if (analysis.client_id == CrashClient.FRACAS or | |
|
Martin Barbella
2016/09/17 23:20:35
Seems like this pattern has come up a few times. M
Sharu Jiang
2016/09/19 21:35:59
I think we can leave it as it is, since it is very
| |
| 130 analysis.client_id == CrashClient.CRACAS): | |
| 131 analysis_result['feedback_url'] = _FINDIT_FRACAS_FEEDBACK_URL_TEMPLATE % ( | |
| 132 appengine_util.GetDefaultVersionHostname(), analysis.key.urlsafe()) | |
| 133 if analysis_result['found']: | |
| 134 for cl in analysis_result['suspected_cls']: | |
| 135 cl['confidence'] = round(cl['confidence'], 2) | |
| 136 cl.pop('reason', None) | |
| 137 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. | |
| 138 # TODO(katesonia): Post process clusterfuzz analysis result if needed. | |
| 139 pass | |
| 140 | |
| 141 return { | |
| 142 'crash_identifiers': crash_identifiers, | |
| 143 'client_id': analysis.client_id, | |
| 144 'result': analysis_result, | |
| 145 } | |
| 146 | |
| 147 | |
| 148 def FindCulprit(analysis): | |
| 149 result = {'found': False} | |
| 150 tags = {'found_suspects': False, | |
| 151 'has_regression_range': False} | |
| 152 | |
| 153 if (analysis.client_id == CrashClient.FRACAS or | |
| 154 analysis.client_id == CrashClient.CRACAS): | |
| 155 result, tags = findit_for_chromecrash.FindCulpritForChromeCrash( | |
| 156 analysis.signature, analysis.platform, analysis.stack_trace, | |
| 157 analysis.crashed_version, analysis.historical_metadata) | |
| 158 elif analysis.client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. | |
| 159 # TODO(katesonia): Implement findit_for_clusterfuzz. | |
| 160 pass | |
| 161 | |
| 162 return result, tags | |
| OLD | NEW |