OLD | NEW |
---|---|
1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 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 report on benchmark alert health.""" | 5 """Provides the web interface for a report on benchmark alert health.""" |
6 | 6 |
7 import datetime | 7 import datetime |
8 import json | 8 import json |
9 | 9 |
10 from dashboard import alerts | 10 from dashboard import alerts |
11 from dashboard import list_tests | |
12 from dashboard import update_test_suites | 11 from dashboard import update_test_suites |
13 from dashboard.common import request_handler | 12 from dashboard.common import request_handler |
14 from dashboard.common import utils | |
15 from dashboard.models import anomaly | 13 from dashboard.models import anomaly |
16 | 14 |
17 | 15 |
18 class BenchmarkHealthReportHandler(request_handler.RequestHandler): | 16 class BenchmarkHealthReportHandler(request_handler.RequestHandler): |
19 | 17 |
20 def get(self): | 18 def get(self): |
21 """Renders the UI for the group report page.""" | 19 """Renders the UI for the group report page.""" |
22 self.RenderStaticHtml('benchmark_health_report.html') | 20 self.RenderStaticHtml('benchmark_health_report.html') |
23 | 21 |
24 def post(self): | 22 def post(self): |
(...skipping 19 matching lines...) Expand all Loading... | |
44 benchmark, num_days, master) | 42 benchmark, num_days, master) |
45 else: | 43 else: |
46 response_values = self._GetResponseValuesForMaster(master) | 44 response_values = self._GetResponseValuesForMaster(master) |
47 | 45 |
48 self.response.out.write(json.dumps(response_values)) | 46 self.response.out.write(json.dumps(response_values)) |
49 | 47 |
50 def _GetResponseValuesForBenchmark(self, benchmark, num_days, master): | 48 def _GetResponseValuesForBenchmark(self, benchmark, num_days, master): |
51 values = {} | 49 values = {} |
52 | 50 |
53 # The cached test suite info contains info about monitoring and bots. | 51 # The cached test suite info contains info about monitoring and bots. |
52 query = anomaly.Anomaly.query( | |
53 anomaly.Anomaly.benchmark_name == benchmark, | |
54 anomaly.Anomaly.master_name == master, | |
55 anomaly.Anomaly.is_improvement == False, | |
56 anomaly.Anomaly.timestamp > | |
57 datetime.datetime.now() - datetime.timedelta(days=num_days)) | |
58 query = query.order(-anomaly.Anomaly.timestamp) | |
59 anomalies = query.fetch() | |
60 values['alerts'] = alerts.AnomalyDicts(anomalies) | |
54 benchmarks = update_test_suites.FetchCachedTestSuites() | 61 benchmarks = update_test_suites.FetchCachedTestSuites() |
55 sheriff = self._GetSheriffForBenchmark(benchmark, master, benchmarks) | 62 if benchmarks[benchmark].get('mon'): |
shatch
2017/02/23 15:58:30
nit: Is it possible to have alerts and not be moni
sullivan
2017/02/23 16:11:42
It is possible to have alerts and not be monitored
| |
56 if sheriff: | |
57 query = anomaly.Anomaly.query(anomaly.Anomaly.sheriff == sheriff) | |
58 query = query.filter(anomaly.Anomaly.is_improvement == False) | |
59 query = query.filter( | |
60 anomaly.Anomaly.timestamp > | |
61 datetime.datetime.now() - datetime.timedelta(days=num_days)) | |
62 query = query.order(-anomaly.Anomaly.timestamp) | |
63 anomalies = query.fetch() | |
64 anomalies = [a for a in anomalies if self._BenchmarkName(a) == benchmark] | |
65 values['monitored'] = True | 63 values['monitored'] = True |
66 values['alerts'] = alerts.AnomalyDicts(anomalies) | |
67 else: | 64 else: |
68 values['monitored'] = False | 65 values['monitored'] = False |
69 | |
70 values['bots'] = benchmarks[benchmark]['mas'][master].keys() | 66 values['bots'] = benchmarks[benchmark]['mas'][master].keys() |
71 return values | 67 return values |
72 | 68 |
73 def _GetSheriffForBenchmark(self, benchmark, master, benchmarks): | |
74 # TODO(sullivan): There can be multiple sheriffs; implement this. | |
75 if not benchmarks[benchmark]['mon']: | |
76 return None | |
77 monitored_test_path = benchmarks[benchmark]['mon'][0] | |
78 pattern = '%s/*/%s/%s' % (master, benchmark, monitored_test_path) | |
79 monitored_tests = list_tests.GetTestsMatchingPattern( | |
80 pattern, list_entities=True) | |
81 return monitored_tests[0].sheriff | |
82 | |
83 def _BenchmarkName(self, alert): | |
84 return utils.TestPath(alert.test).split('/')[2] | |
85 | |
86 def _GetResponseValuesForMaster(self, master): | 69 def _GetResponseValuesForMaster(self, master): |
87 benchmarks = update_test_suites.FetchCachedTestSuites() | 70 benchmarks = update_test_suites.FetchCachedTestSuites() |
88 benchmarks = [b for b in benchmarks if master in benchmarks[b]['mas']] | 71 benchmarks = [b for b in benchmarks if master in benchmarks[b]['mas']] |
89 return {'benchmarks': sorted(benchmarks)} | 72 return {'benchmarks': sorted(benchmarks)} |
OLD | NEW |