| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 # FIXME: Everything in this file belongs in gatekeeper_ng_config.py | 5 # FIXME: Everything in this file belongs in gatekeeper_ng_config.py |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 | 8 |
| 9 from infra.tools.builder_alerts.buildbot import master_name_from_url |
| 9 | 10 |
| 10 def excluded_builders(master_config): | 11 def excluded_builders(master_config): |
| 11 return master_config[0].get('*', {}).get('excluded_builders', set()) | 12 return master_config[0].get('*', {}).get('excluded_builders', set()) |
| 12 | 13 |
| 13 | 14 |
| 14 # pylint: disable=C0301 | 15 def tree_for_master(master_url, gatekeeper_trees_config): |
| 15 # FIXME: This is currently baked into: | 16 """Get the name of the tree for a given master url, or the master's name.""" |
| 16 # https://chromium.googlesource.com/chromium/tools/build/+/master/scripts/slave/
gatekeeper_launch.py | 17 for tree_name, tree_config in gatekeeper_trees_config.iteritems(): |
| 17 # http://crbug.com/394961 | 18 if master_url in tree_config['masters']: |
| 18 MASTER_CONFIG = { | 19 return tree_name |
| 19 'chromium-status': [ | 20 return master_name_from_url(master_url) |
| 20 'chromium', | |
| 21 'chromium.chrome', | |
| 22 'chromium.chromiumos', | |
| 23 'chromium.gpu', | |
| 24 'chromium.linux', | |
| 25 'chromium.mac', | |
| 26 'chromium.memory', | |
| 27 'chromium.win', | |
| 28 ], | |
| 29 'blink-status': [ | |
| 30 'chromium.webkit', | |
| 31 ], | |
| 32 } | |
| 33 | 21 |
| 34 | 22 |
| 35 def tree_for_master(master_name): | 23 def apply_gatekeeper_rules(alerts, gatekeeper, gatekeeper_trees): |
| 36 for tree_name, master_names in MASTER_CONFIG.items(): | 24 filtered_alerts = [] |
| 37 if master_name in master_names: | 25 for alert in alerts: |
| 38 return tree_name | 26 master_url = alert['master_url'] |
| 27 config = gatekeeper.get(master_url) |
| 28 if not config: |
| 29 # Unclear if this should be set or not? |
| 30 # alert['would_close_tree'] = False |
| 31 filtered_alerts.append(alert) |
| 32 continue |
| 33 if alert['builder_name'] in excluded_builders(config): |
| 34 continue |
| 35 alert['would_close_tree'] = would_close_tree( |
| 36 config, alert['builder_name'], alert['step_name']) |
| 37 alert['tree'] = tree_for_master(master_url, gatekeeper_trees) |
| 38 filtered_alerts.append(alert) |
| 39 return filtered_alerts |
| 40 |
| 41 |
| 42 def fetch_master_urls(gatekeeper, args): |
| 43 # Currently using gatekeeper.json, but could use: |
| 44 # https://chrome-infra-stats.appspot.com/_ah/api#p/stats/v1/stats.masters.list |
| 45 master_urls = gatekeeper.keys() |
| 46 if args.master_filter: |
| 47 master_urls = [url for url in master_urls if args.master_filter not in url] |
| 48 return master_urls |
| 39 | 49 |
| 40 | 50 |
| 41 def would_close_tree(master_config, builder_name, step_name): | 51 def would_close_tree(master_config, builder_name, step_name): |
| 42 # FIXME: Section support should be removed: | 52 # FIXME: Section support should be removed: |
| 43 master_config = master_config[0] | 53 master_config = master_config[0] |
| 44 builder_config = master_config.get(builder_name, {}) | 54 builder_config = master_config.get(builder_name, {}) |
| 45 if not builder_config: | 55 if not builder_config: |
| 46 builder_config = master_config.get('*', {}) | 56 builder_config = master_config.get('*', {}) |
| 47 | 57 |
| 48 # close_tree is currently unused in gatekeeper.json but planned to be. | 58 # close_tree is currently unused in gatekeeper.json but planned to be. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 70 | 80 |
| 71 # A '*' in any of the above types means it applies to all steps. | 81 # A '*' in any of the above types means it applies to all steps. |
| 72 if '*' in closing_steps: | 82 if '*' in closing_steps: |
| 73 return True | 83 return True |
| 74 | 84 |
| 75 if step_name in closing_steps: | 85 if step_name in closing_steps: |
| 76 return True | 86 return True |
| 77 | 87 |
| 78 logging.debug('%s not in closing_steps: %s' % (step_name, closing_steps)) | 88 logging.debug('%s not in closing_steps: %s' % (step_name, closing_steps)) |
| 79 return False | 89 return False |
| OLD | NEW |