OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 """Provides the web interface for a set of alerts and their graphs.""" | 5 """Provides the web interface for a set of alerts and their graphs.""" |
6 | 6 |
7 import json | 7 import json |
8 | 8 |
9 from google.appengine.ext import ndb | 9 from google.appengine.ext import ndb |
10 | 10 |
11 from dashboard import alerts | 11 from dashboard import alerts |
12 from dashboard import chart_handler | 12 from dashboard import chart_handler |
13 from dashboard import list_tests | |
14 from dashboard import update_test_suites | 13 from dashboard import update_test_suites |
15 from dashboard.common import request_handler | 14 from dashboard.common import request_handler |
16 from dashboard.common import utils | 15 from dashboard.common import utils |
17 from dashboard.models import anomaly | 16 from dashboard.models import anomaly |
18 from dashboard.models import page_state | 17 from dashboard.models import page_state |
19 from dashboard.models import stoppage_alert | 18 from dashboard.models import stoppage_alert |
20 | 19 |
21 # This is the max number of alerts to query at once. This is used in cases | 20 # This is the max number of alerts to query at once. This is used in cases |
22 # when we may want to query more many more alerts than actually get displayed. | 21 # when we may want to query more many more alerts than actually get displayed. |
23 _QUERY_LIMIT = 2000 | 22 _QUERY_LIMIT = 2000 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 bug_id: An integer bug ID. | 174 bug_id: An integer bug ID. |
176 """ | 175 """ |
177 anomaly_dicts = alerts.AnomalyDicts( | 176 anomaly_dicts = alerts.AnomalyDicts( |
178 [a for a in alert_list if a.key.kind() == 'Anomaly']) | 177 [a for a in alert_list if a.key.kind() == 'Anomaly']) |
179 stoppage_alert_dicts = alerts.StoppageAlertDicts( | 178 stoppage_alert_dicts = alerts.StoppageAlertDicts( |
180 [a for a in alert_list if a.key.kind() == 'StoppageAlert']) | 179 [a for a in alert_list if a.key.kind() == 'StoppageAlert']) |
181 alert_dicts = anomaly_dicts + stoppage_alert_dicts | 180 alert_dicts = anomaly_dicts + stoppage_alert_dicts |
182 | 181 |
183 values = { | 182 values = { |
184 'alert_list': alert_dicts[:_DISPLAY_LIMIT], | 183 'alert_list': alert_dicts[:_DISPLAY_LIMIT], |
185 # This code for getting the subtests is supposed to be used to sort out | |
186 # which metrics are "core" vs "non-core". But it's extremely slow, and | |
187 # also doesn't seem to work very well. Turn it off for now: | |
188 # https://github.com/catapult-project/catapult/issues/2877 | |
189 #'subtests': _GetSubTestsForAlerts(alert_dicts), | |
190 'bug_id': bug_id, | 184 'bug_id': bug_id, |
191 'test_suites': update_test_suites.FetchCachedTestSuites(), | 185 'test_suites': update_test_suites.FetchCachedTestSuites(), |
192 'selected_keys': selected_keys, | 186 'selected_keys': selected_keys, |
193 } | 187 } |
194 self.GetDynamicVariables(values) | 188 self.GetDynamicVariables(values) |
195 | 189 |
196 self.response.out.write(json.dumps(values)) | 190 self.response.out.write(json.dumps(values)) |
197 | 191 |
198 | 192 |
199 def _IsInt(x): | 193 def _IsInt(x): |
200 """Returns True if the input can be parsed as an int.""" | 194 """Returns True if the input can be parsed as an int.""" |
201 try: | 195 try: |
202 int(x) | 196 int(x) |
203 return True | 197 return True |
204 except ValueError: | 198 except ValueError: |
205 return False | 199 return False |
206 | 200 |
207 | 201 |
208 def _GetSubTestsForAlerts(alert_list): | |
209 """Gets subtest dict for list of alerts.""" | |
210 subtests = {} | |
211 for alert in alert_list: | |
212 bot_name = alert['master'] + '/' + alert['bot'] | |
213 testsuite = alert['testsuite'] | |
214 if bot_name not in subtests: | |
215 subtests[bot_name] = {} | |
216 if testsuite not in subtests[bot_name]: | |
217 subtests[bot_name][testsuite] = list_tests.GetSubTests( | |
218 testsuite, [bot_name]) | |
219 return subtests | |
220 | |
221 | |
222 def _GetOverlaps(anomalies, start, end): | 202 def _GetOverlaps(anomalies, start, end): |
223 """Gets the minimum range for the list of anomalies. | 203 """Gets the minimum range for the list of anomalies. |
224 | 204 |
225 Args: | 205 Args: |
226 anomalies: The list of anomalies. | 206 anomalies: The list of anomalies. |
227 start: The start revision. | 207 start: The start revision. |
228 end: The end revision. | 208 end: The end revision. |
229 | 209 |
230 Returns: | 210 Returns: |
231 A list of anomalies. | 211 A list of anomalies. |
232 """ | 212 """ |
233 return [a for a in anomalies | 213 return [a for a in anomalies |
234 if a.start_revision <= end and a.end_revision >= start] | 214 if a.start_revision <= end and a.end_revision >= start] |
OLD | NEW |