OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import argparse | 6 import argparse |
7 import datetime | 7 import datetime |
8 import json | 8 import json |
9 import logging | 9 import logging |
10 import sys | 10 import sys |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 requests_cache.install_cache('failure_stats') | 80 requests_cache.install_cache('failure_stats') |
81 else: | 81 else: |
82 requests_cache.install_cache(backend='memory') | 82 requests_cache.install_cache(backend='memory') |
83 | 83 |
84 # FIXME: gatekeeper_config should find gatekeeper.json for us. | 84 # FIXME: gatekeeper_config should find gatekeeper.json for us. |
85 gatekeeper_path = os.path.join(build_scripts_dir, 'slave', 'gatekeeper.json') | 85 gatekeeper_path = os.path.join(build_scripts_dir, 'slave', 'gatekeeper.json') |
86 gatekeeper = gatekeeper_ng_config.load_gatekeeper_config(gatekeeper_path) | 86 gatekeeper = gatekeeper_ng_config.load_gatekeeper_config(gatekeeper_path) |
87 master_urls = fetch_master_urls(gatekeeper, args) | 87 master_urls = fetch_master_urls(gatekeeper, args) |
88 start_time = datetime.datetime.now() | 88 start_time = datetime.datetime.now() |
89 | 89 |
90 latest_revisions = {} | 90 latest_builder_info = {} |
91 | 91 |
92 cache = buildbot.BuildCache(CACHE_PATH) | 92 cache = buildbot.BuildCache(CACHE_PATH) |
93 | 93 |
94 alerts = [] | 94 alerts = [] |
95 for master_url in master_urls: | 95 for master_url in master_urls: |
96 master_json = buildbot.fetch_master_json(master_url) | 96 master_json = buildbot.fetch_master_json(master_url) |
97 master_alerts = alert_builder.alerts_for_master(cache, | 97 master_alerts = alert_builder.alerts_for_master(cache, |
98 master_url, master_json, args.builder_filter) | 98 master_url, master_json, args.builder_filter) |
99 alerts.extend(master_alerts) | 99 alerts.extend(master_alerts) |
100 | 100 |
101 # FIXME: This doesn't really belong here. garden-o-matic wants | 101 # FIXME: This doesn't really belong here. garden-o-matic wants |
102 # this data and we happen to have the builder json cached at | 102 # this data and we happen to have the builder json cached at |
103 # this point so it's cheap to compute. | 103 # this point so it's cheap to compute. |
104 revisions = buildbot.latest_revisions_for_master(cache, | 104 builder_info = buildbot.latest_builder_info_for_master(cache, |
105 master_url, master_json) | 105 master_url, master_json) |
106 latest_revisions.update(revisions) | 106 latest_builder_info.update(builder_info) |
107 | 107 |
108 | 108 |
109 print "Fetch took: %s" % (datetime.datetime.now() - start_time) | 109 print "Fetch took: %s" % (datetime.datetime.now() - start_time) |
110 | 110 |
111 alerts = apply_gatekeeper_rules(alerts, gatekeeper) | 111 alerts = apply_gatekeeper_rules(alerts, gatekeeper) |
112 | 112 |
113 alerts = analysis.assign_keys(alerts) | 113 alerts = analysis.assign_keys(alerts) |
114 reason_groups = analysis.group_by_reason(alerts) | 114 reason_groups = analysis.group_by_reason(alerts) |
115 range_groups = analysis.merge_by_range(reason_groups) | 115 range_groups = analysis.merge_by_range(reason_groups) |
116 data = { 'content': json.dumps({ | 116 data = { 'content': json.dumps({ |
117 'alerts': alerts, | 117 'alerts': alerts, |
118 'reason_groups': reason_groups, | 118 'reason_groups': reason_groups, |
119 'range_groups': range_groups, | 119 'range_groups': range_groups, |
120 'latest_revisions': latest_revisions, | 120 'latest_builder_info': latest_builder_info, |
121 })} | 121 })} |
122 | 122 |
123 if not args.data_url: | 123 if not args.data_url: |
124 with open('builder_alerts.json', 'w') as f: | 124 with open('builder_alerts.json', 'w') as f: |
125 f.write(json.dumps(data, indent=1)) | 125 f.write(json.dumps(data, indent=1)) |
126 | 126 |
127 for url in args.data_url: | 127 for url in args.data_url: |
128 logging.info('POST %s alerts to %s' % (len(alerts), url)) | 128 logging.info('POST %s alerts to %s' % (len(alerts), url)) |
129 requests.post(url, data=data) | 129 requests.post(url, data=data) |
130 | 130 |
131 | 131 |
132 if __name__ == '__main__': | 132 if __name__ == '__main__': |
133 sys.exit(main(sys.argv[1:])) | 133 sys.exit(main(sys.argv[1:])) |
OLD | NEW |