Chromium Code Reviews| 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 14 matching lines...) Expand all Loading... | |
| 25 top_dir = os.path.dirname(infra_dir) | 25 top_dir = os.path.dirname(infra_dir) |
| 26 build_scripts_dir = os.path.join(top_dir, 'build', 'scripts') | 26 build_scripts_dir = os.path.join(top_dir, 'build', 'scripts') |
| 27 sys.path.insert(0, build_scripts_dir) | 27 sys.path.insert(0, build_scripts_dir) |
| 28 | 28 |
| 29 from slave import gatekeeper_ng_config | 29 from slave import gatekeeper_ng_config |
| 30 | 30 |
| 31 | 31 |
| 32 CACHE_PATH = 'build_cache' | 32 CACHE_PATH = 'build_cache' |
| 33 | 33 |
| 34 | 34 |
| 35 def apply_gatekeeper_rules(alerts, gatekeeper): | 35 def apply_gatekeeper_rules(alerts, gatekeeper, gatekeeper_trees): |
| 36 filtered_alerts = [] | 36 filtered_alerts = [] |
| 37 for alert in alerts: | 37 for alert in alerts: |
| 38 master_url = alert['master_url'] | 38 master_url = alert['master_url'] |
| 39 master_name = buildbot.master_name_from_url(master_url) | |
| 40 config = gatekeeper.get(master_url) | 39 config = gatekeeper.get(master_url) |
| 41 if not config: | 40 if not config: |
| 42 # Unclear if this should be set or not? | 41 # Unclear if this should be set or not? |
| 43 # alert['would_close_tree'] = False | 42 # alert['would_close_tree'] = False |
| 44 filtered_alerts.append(alert) | 43 filtered_alerts.append(alert) |
| 45 continue | 44 continue |
| 46 excluded_builders = gatekeeper_extras.excluded_builders(config) | 45 excluded_builders = gatekeeper_extras.excluded_builders(config) |
| 47 if alert['builder_name'] in excluded_builders: | 46 if alert['builder_name'] in excluded_builders: |
| 48 continue | 47 continue |
| 49 alert['would_close_tree'] = \ | 48 alert['would_close_tree'] = gatekeeper_extras.would_close_tree( |
| 50 gatekeeper_extras.would_close_tree(config, | 49 config, alert['builder_name'], alert['step_name']) |
| 51 alert['builder_name'], alert['step_name']) | 50 tree_name = gatekeeper_extras.tree_for_master(master_url, gatekeeper_trees) |
| 51 alert['tree_name'] = tree_name or buildbot.master_name_from_url(master_url) | |
|
ojan
2014/08/28 03:34:15
Nit: can we just call this tree instead of tree_na
Sergiy Byelozyorov
2014/08/28 17:45:58
Done.
| |
| 52 filtered_alerts.append(alert) | 52 filtered_alerts.append(alert) |
| 53 alert['tree_name'] = gatekeeper_extras.tree_for_master(master_name) | |
| 54 return filtered_alerts | 53 return filtered_alerts |
| 55 | 54 |
| 56 | 55 |
| 57 def fetch_master_urls(gatekeeper, args): | 56 def fetch_master_urls(gatekeeper, args): |
| 58 # Currently using gatekeeper.json, but could use: | 57 # Currently using gatekeeper.json, but could use: |
| 59 # https://chrome-infra-stats.appspot.com/_ah/api#p/stats/v1/stats.masters.list | 58 # https://chrome-infra-stats.appspot.com/_ah/api#p/stats/v1/stats.masters.list |
| 60 master_urls = gatekeeper.keys() | 59 master_urls = gatekeeper.keys() |
| 61 if args.master_filter: | 60 if args.master_filter: |
| 62 master_urls = [url for url in master_urls if args.master_filter not in url] | 61 master_urls = [url for url in master_urls if args.master_filter not in url] |
| 63 return master_urls | 62 return master_urls |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 80 | 79 |
| 81 if args.use_cache: | 80 if args.use_cache: |
| 82 requests_cache.install_cache('failure_stats') | 81 requests_cache.install_cache('failure_stats') |
| 83 else: | 82 else: |
| 84 requests_cache.install_cache(backend='memory') | 83 requests_cache.install_cache(backend='memory') |
| 85 | 84 |
| 86 # FIXME: gatekeeper_config should find gatekeeper.json for us. | 85 # FIXME: gatekeeper_config should find gatekeeper.json for us. |
| 87 gatekeeper_path = os.path.abspath(args.gatekeeper) | 86 gatekeeper_path = os.path.abspath(args.gatekeeper) |
| 88 print "Processsing gatekeeper json: %s" % (gatekeeper_path) | 87 print "Processsing gatekeeper json: %s" % (gatekeeper_path) |
| 89 gatekeeper = gatekeeper_ng_config.load_gatekeeper_config(gatekeeper_path) | 88 gatekeeper = gatekeeper_ng_config.load_gatekeeper_config(gatekeeper_path) |
| 89 | |
| 90 gatekeeper_trees_path = os.path.join(os.path.dirname(gatekeeper_path), | |
| 91 'gatekeeper_trees.json') | |
| 92 print 'Processing gatekeeper trees json: %s' % (gatekeeper_trees_path) | |
|
ojan
2014/08/28 03:34:15
These two prints seem unneccessary to me. Lets eit
Sergiy Byelozyorov
2014/08/28 17:45:58
Done.
| |
| 93 gatekeeper_trees = gatekeeper_ng_config.load_gatekeeper_tree_config( | |
| 94 gatekeeper_trees_path) | |
| 95 | |
| 90 master_urls = fetch_master_urls(gatekeeper, args) | 96 master_urls = fetch_master_urls(gatekeeper, args) |
| 91 start_time = datetime.datetime.now() | 97 start_time = datetime.datetime.now() |
| 92 | 98 |
| 93 latest_builder_info = {} | 99 latest_builder_info = {} |
| 94 | 100 |
| 95 cache = buildbot.BuildCache(CACHE_PATH) | 101 cache = buildbot.BuildCache(CACHE_PATH) |
| 96 | 102 |
| 97 alerts = [] | 103 alerts = [] |
| 98 for master_url in master_urls: | 104 for master_url in master_urls: |
| 99 master_json = buildbot.fetch_master_json(master_url) | 105 master_json = buildbot.fetch_master_json(master_url) |
| 100 master_alerts = alert_builder.alerts_for_master(cache, | 106 master_alerts = alert_builder.alerts_for_master(cache, |
| 101 master_url, master_json, args.builder_filter) | 107 master_url, master_json, args.builder_filter) |
| 102 alerts.extend(master_alerts) | 108 alerts.extend(master_alerts) |
| 103 | 109 |
| 104 # FIXME: This doesn't really belong here. garden-o-matic wants | 110 # FIXME: This doesn't really belong here. garden-o-matic wants |
| 105 # this data and we happen to have the builder json cached at | 111 # this data and we happen to have the builder json cached at |
| 106 # this point so it's cheap to compute. | 112 # this point so it's cheap to compute. |
| 107 builder_info = buildbot.latest_builder_info_for_master(cache, | 113 builder_info = buildbot.latest_builder_info_for_master(cache, |
| 108 master_url, master_json) | 114 master_url, master_json) |
| 109 latest_builder_info.update(builder_info) | 115 latest_builder_info.update(builder_info) |
| 110 | 116 |
| 111 | 117 |
| 112 print "Fetch took: %s" % (datetime.datetime.now() - start_time) | 118 print "Fetch took: %s" % (datetime.datetime.now() - start_time) |
| 113 | 119 |
| 114 alerts = apply_gatekeeper_rules(alerts, gatekeeper) | 120 alerts = apply_gatekeeper_rules(alerts, gatekeeper, gatekeeper_trees) |
| 115 | 121 |
| 116 alerts = analysis.assign_keys(alerts) | 122 alerts = analysis.assign_keys(alerts) |
| 117 reason_groups = analysis.group_by_reason(alerts) | 123 reason_groups = analysis.group_by_reason(alerts) |
| 118 range_groups = analysis.merge_by_range(reason_groups) | 124 range_groups = analysis.merge_by_range(reason_groups) |
| 119 data = { 'content': json.dumps({ | 125 data = { 'content': json.dumps({ |
| 120 'alerts': alerts, | 126 'alerts': alerts, |
| 121 'reason_groups': reason_groups, | 127 'reason_groups': reason_groups, |
| 122 'range_groups': range_groups, | 128 'range_groups': range_groups, |
| 123 'latest_builder_info': latest_builder_info, | 129 'latest_builder_info': latest_builder_info, |
| 124 })} | 130 })} |
| 125 | 131 |
| 126 if not args.data_url: | 132 if not args.data_url: |
| 127 with open('builder_alerts.json', 'w') as f: | 133 with open('builder_alerts.json', 'w') as f: |
| 128 f.write(json.dumps(data, indent=1)) | 134 f.write(json.dumps(data, indent=1)) |
| 129 | 135 |
| 130 for url in args.data_url: | 136 for url in args.data_url: |
| 131 logging.info('POST %s alerts to %s' % (len(alerts), url)) | 137 logging.info('POST %s alerts to %s' % (len(alerts), url)) |
| 132 requests.post(url, data=data) | 138 requests.post(url, data=data) |
| 133 | 139 |
| 134 | 140 |
| 135 if __name__ == '__main__': | 141 if __name__ == '__main__': |
| 136 sys.exit(main(sys.argv[1:])) | 142 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |