Chromium Code Reviews| Index: appengine/findit/crash/findit_for_client.py |
| diff --git a/appengine/findit/crash/findit_for_client.py b/appengine/findit/crash/findit_for_client.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2f45df79f83a7e22cd2be92109efcda99432672e |
| --- /dev/null |
| +++ b/appengine/findit/crash/findit_for_client.py |
| @@ -0,0 +1,153 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import copy |
| +import json |
| +import logging |
| + |
| +from google.appengine.api import app_identity |
| +from google.appengine.ext import ndb |
| + |
| +from common import time_util |
| +from crash import findit_for_fracas |
| +from crash.type_enums import CrashClient |
| +from model import analysis_status |
| +from model.crash.crash_config import CrashConfig |
| +from model.crash.fracas_crash_analysis import FracasCrashAnalysis |
| + |
| +_FINDIT_FRACAS_FEEDBACK_URL_TEMPLATE = '%s/crash/fracas-result-feedback?key=%s' |
| + |
| + |
| +def CheckPolicyForClient(crash_identifiers, chrome_version, signature, |
| + client_id, platform, stack_trace, customized_data): |
| + """Checks if the args pass the client policy or not, update the parameters |
| + if needed.""" |
| + crash_config = CrashConfig.Get() |
| + |
| + # Cracas and Fracas share the sampe policy. |
| + if client_id == CrashClient.FRACAS or client_id == CrashClient.CRACAS: |
| + if platform not in crash_config.fracas.get( |
| + 'supported_platform_list_by_channel', {}).get( |
| + customized_data.get('channel'), []): |
| + # Bail out if either the channel or platform is not supported yet. |
| + logging.info('Ananlysis of channel %s, platform %s is not supported. ' |
| + 'No analysis is scheduled for %s', |
| + customized_data.get('channel'), platform, |
| + repr(crash_identifiers)) |
| + return False, None |
| + |
| + # TODO(katesonia): Remove the default value after adding validity check to |
| + # config. |
| + for blacklist_marker in crash_config.fracas.get( |
|
stgao
2016/09/13 16:37:31
At top of this file, should we add a docstring tha
Sharu Jiang
2016/09/14 20:38:38
Done.
|
| + 'signature_blacklist_markers', []): |
| + if blacklist_marker in signature: |
| + logging.info('%s signature is not supported. ' |
| + 'No analysis is scheduled for %s', blacklist_marker, |
| + repr(crash_identifiers)) |
| + return False, None |
| + |
| + # TODO(katesonia): Remove the default value after adding validity check to |
| + # config. |
| + platform_rename = crash_config.fracas.get('platform_rename', {}) |
| + platform = platform_rename.get(platform, platform) |
| + |
| + # TODO(katesonia): Add clusterfuzz policy check. |
| + elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| + pass |
|
stgao
2016/09/13 16:37:31
Will this trigger a pipeline to run the analysis?
Sharu Jiang
2016/09/14 20:38:38
No, this is only for checking policy to see if ana
|
| + |
| + return True, (crash_identifiers, chrome_version, signature, client_id, |
| + platform, stack_trace, customized_data) |
| + |
| + |
| +def GetAnalysisForClient(crash_identifiers, client_id): |
| + analysis = None |
| + if client_id == CrashClient.FRACAS: |
| + analysis = FracasCrashAnalysis.Get(crash_identifiers) |
| + elif client_id == CrashClient.CRACAS: # pragma: no cover. |
| + # TODO(katesonia): Add CracasCrashAnalysis model. |
| + pass |
| + elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| + # TODO(katesonia): Add ClusterfuzzCrashAnalysis model. |
| + pass |
| + |
| + return analysis |
| + |
| + |
| +@ndb.transactional |
| +def ResetAnalysis(analysis, crash_identifiers, chrome_version, signature, |
| + client_id, platform, stack_trace, customized_data): |
| + """Resets analysis to be analyzed.""" |
| + if not analysis: |
| + # A new analysis is needed if there is no analysis. |
| + if client_id == CrashClient.FRACAS: |
| + analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| + elif client_id == CrashClient.CRACAS: # pragma: no cover. |
| + # TODO(katesonia): define CracasCrashAnalysis. |
| + pass |
|
stgao
2016/09/13 16:37:31
Will this result int error later in the code below
Sharu Jiang
2016/09/14 20:38:38
Done.
|
| + elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| + # TODO(katesonia): define ClusterfuzzCrashAnalysis. |
| + pass |
| + |
| + analysis.Reset() |
| + |
| + # Set common properties. |
| + analysis.crashed_version = chrome_version |
| + analysis.stack_trace = stack_trace |
| + analysis.signature = signature |
| + analysis.platform = platform |
| + analysis.client_id = client_id |
| + |
| + if client_id == CrashClient.FRACAS or client_id == CrashClient.CRACAS: |
| + # Set customized properties. |
| + analysis.historical_metadata = customized_data.get('historical_metadata') |
| + analysis.channel = customized_data.get('channel') |
| + elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| + # TODO(katesonia): Set up clusterfuzz customized data. |
| + pass |
| + |
| + # Set analysis progress properties. |
| + analysis.status = analysis_status.PENDING |
| + analysis.requested_time = time_util.GetUTCNow() |
| + |
| + analysis.put() |
| + |
| + |
| +def GetPublishResultFromAnalysis(analysis, crash_identifiers, client_id): |
| + """Gets result to be published to client from datastore analysis.""" |
| + analysis_result = copy.deepcopy(analysis.result) |
| + |
| + if (analysis.client_id == CrashClient.FRACAS or |
| + analysis.client_id == CrashClient.CRACAS): |
| + analysis_result['feedback_url'] = _FINDIT_FRACAS_FEEDBACK_URL_TEMPLATE % ( |
| + app_identity.get_default_version_hostname(), analysis.key.urlsafe()) |
|
stgao
2016/09/13 16:37:31
Should we move the hostname part to common/appengi
Sharu Jiang
2016/09/14 20:38:38
Done.
|
| + if analysis_result['found']: |
| + for cl in analysis_result['suspected_cls']: |
| + cl['confidence'] = round(cl['confidence'], 2) |
| + cl.pop('reason', None) |
| + elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| + # TODO(katesonia): Post process clusterfuzz analysis result if needed. |
| + pass |
| + |
| + return { |
| + 'crash_identifiers': crash_identifiers, |
| + 'client_id': analysis.client_id, |
| + 'result': analysis_result, |
| + } |
| + |
| + |
| +def FindCulprit(analysis): |
| + result = {'found': False} |
| + tags = {'found_suspects': False, |
| + 'has_regression_range': False} |
| + |
| + if (analysis.client_id == CrashClient.FRACAS or |
| + analysis.client_id == CrashClient.CRACAS): |
| + result, tags = findit_for_fracas.FindCulpritForChromeCrash( |
| + analysis.signature, analysis.platform, analysis.stack_trace, |
| + analysis.crashed_version, analysis.historical_metadata) |
| + elif analysis.client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| + # TODO(katesonia): Implement findit_for_clusterfuzz. |
| + pass |
| + |
| + return result, tags |