| 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 base64 | 5 import base64 |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 | 8 |
| 9 from common import constants | 9 from common import constants |
| 10 from common import appengine_util | 10 from common import appengine_util |
| 11 from common.base_handler import BaseHandler | 11 from common.base_handler import BaseHandler |
| 12 from common.base_handler import Permission | 12 from common.base_handler import Permission |
| 13 from common.http_client_appengine import HttpClientAppengine | 13 from common.http_client_appengine import HttpClientAppengine |
| 14 from crash import crash_pipeline | 14 from crash import crash_pipeline |
| 15 from crash.crash_report import CrashReport | 15 from crash.crash_report import CrashReport |
| 16 from lib.gitiles.gitiles_repository import GitilesRepository | 16 from gae_libs.gitiles.cached_gitiles_repository import CachedGitilesRepository |
| 17 | 17 |
| 18 | 18 |
| 19 class CrashHandler(BaseHandler): | 19 class CrashHandler(BaseHandler): |
| 20 PERMISSION_LEVEL = Permission.ANYONE | 20 PERMISSION_LEVEL = Permission.ANYONE |
| 21 | 21 |
| 22 def HandlePost(self): | 22 def HandlePost(self): |
| 23 """Handles push delivery from Pub/Sub for crash data. | 23 """Handles push delivery from Pub/Sub for crash data. |
| 24 | 24 |
| 25 The crash data should be in the following json format: | 25 The crash data should be in the following json format: |
| 26 { | 26 { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 logging.info(self.request.body) | 112 logging.info(self.request.body) |
| 113 | 113 |
| 114 | 114 |
| 115 # TODO(http://crbug.com/659346): we don't cover anything after the | 115 # TODO(http://crbug.com/659346): we don't cover anything after the |
| 116 # call to _NeedsNewAnalysis. | 116 # call to _NeedsNewAnalysis. |
| 117 def ScheduleNewAnalysis(crash_data): | 117 def ScheduleNewAnalysis(crash_data): |
| 118 """Creates a pipeline object to perform the analysis, and start it. | 118 """Creates a pipeline object to perform the analysis, and start it. |
| 119 | 119 |
| 120 If we can detect that the analysis doesn't need to be performed | 120 If we can detect that the analysis doesn't need to be performed |
| 121 (e.g., it was already performed, or the ``crash_data`` is empty so | 121 (e.g., it was already performed, or the ``crash_data`` is empty so |
| 122 there's nothig we can do), then we will skip creating the pipeline | 122 there's nothing we can do), then we will skip creating the pipeline |
| 123 at all. | 123 at all. |
| 124 | 124 |
| 125 Args: | 125 Args: |
| 126 crash_data (JSON): ?? | 126 crash_data (JSON): ?? |
| 127 | 127 |
| 128 Returns: | 128 Returns: |
| 129 True if we started a new pipeline; False otherwise. | 129 True if we started a new pipeline; False otherwise. |
| 130 """ | 130 """ |
| 131 client_id = crash_data['client_id'] | 131 client_id = crash_data['client_id'] |
| 132 repository = GitilesRepository(HttpClientAppengine()) | 132 repository = CachedGitilesRepository(HttpClientAppengine()) |
| 133 # N.B., must call FinditForClientID indirectly, for mock testing. | 133 # N.B., must call FinditForClientID indirectly, for mock testing. |
| 134 findit_client = crash_pipeline.FinditForClientID(client_id, repository) | 134 findit_client = crash_pipeline.FinditForClientID(client_id, repository) |
| 135 | 135 |
| 136 # Check policy and modify the crash_data as needed. | 136 # Check policy and modify the crash_data as needed. |
| 137 crash_data = findit_client.CheckPolicy(crash_data) | 137 crash_data = findit_client.CheckPolicy(crash_data) |
| 138 if crash_data is None: | 138 if crash_data is None: |
| 139 return False | 139 return False |
| 140 | 140 |
| 141 # Detect the regression range, and decide if we actually need to | 141 # Detect the regression range, and decide if we actually need to |
| 142 # run a new anlaysis or not. | 142 # run a new anlaysis or not. |
| 143 if not findit_client._NeedsNewAnalysis(crash_data): | 143 if not findit_client._NeedsNewAnalysis(crash_data): |
| 144 return False | 144 return False |
| 145 | 145 |
| 146 crash_identifiers = crash_data['crash_identifiers'] | 146 crash_identifiers = crash_data['crash_identifiers'] |
| 147 # N.B., we cannot pass ``self`` directly to the _pipeline_cls, because | 147 # N.B., we cannot pass ``self`` directly to the _pipeline_cls, because |
| 148 # it is not JSON-serializable (and there's no way to make it such, | 148 # it is not JSON-serializable (and there's no way to make it such, |
| 149 # since JSON-serializability is defined by JSON-encoders rather than | 149 # since JSON-serializability is defined by JSON-encoders rather than |
| 150 # as methods on the objects being encoded). | 150 # as methods on the objects being encoded). |
| 151 pipeline = crash_pipeline.CrashWrapperPipeline(client_id, crash_identifiers) | 151 pipeline = crash_pipeline.CrashWrapperPipeline(client_id, crash_identifiers) |
| 152 # Attribute defined outside __init__ - pylint: disable=W0201 | 152 # Attribute defined outside __init__ - pylint: disable=W0201 |
| 153 pipeline.target = appengine_util.GetTargetNameForModule( | 153 pipeline.target = appengine_util.GetTargetNameForModule( |
| 154 constants.CRASH_BACKEND[client_id]) | 154 constants.CRASH_BACKEND[client_id]) |
| 155 queue_name = constants.CRASH_ANALYSIS_QUEUE[client_id] | 155 queue_name = constants.CRASH_ANALYSIS_QUEUE[client_id] |
| 156 pipeline.start(queue_name=queue_name) | 156 pipeline.start(queue_name=queue_name) |
| 157 logging.info('New %s analysis is scheduled for %s', client_id, | 157 logging.info('New %s analysis is scheduled for %s', client_id, |
| 158 repr(crash_identifiers)) | 158 repr(crash_identifiers)) |
| 159 return True | 159 return True |
| OLD | NEW |