__init__.py (10306B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 """ 5 The objective of optimization is to remove as many tasks from the graph as 6 possible, as efficiently as possible, thereby delivering useful results as 7 quickly as possible. For example, ideally if only a test script is modified in 8 a push, then the resulting graph contains only the corresponding test suite 9 task. 10 11 See ``taskcluster/docs/optimization.rst`` for more information. 12 """ 13 14 from taskgraph.optimize.base import Alias, All, Any, Not, register_strategy 15 from taskgraph.util.python_path import import_sibling_modules 16 17 # Trigger registration in sibling modules. 18 import_sibling_modules() 19 20 21 def split_bugbug_arg(arg, substrategies): 22 """Split args for bugbug based strategies. 23 24 Many bugbug based optimizations require passing an empty dict by reference 25 to communicate to downstream strategies. This function passes the provided 26 arg to the first (non bugbug) strategies and a shared empty dict to the 27 bugbug strategy and all substrategies after it. 28 """ 29 from gecko_taskgraph.optimize.bugbug import BugBugPushSchedules 30 31 index = [ 32 i 33 for i, strategy in enumerate(substrategies) 34 if isinstance(strategy, BugBugPushSchedules) 35 ][0] 36 37 return [arg] * index + [{}] * (len(substrategies) - index) 38 39 40 # Register composite strategies. 41 register_strategy("build", args=("skip-unless-schedules",))(Alias) 42 register_strategy("test", args=("skip-unless-schedules",))(Alias) 43 register_strategy("test-inclusive", args=("skip-unless-schedules",))(Alias) 44 register_strategy("test-verify", args=("skip-unless-schedules",))(Alias) 45 register_strategy("upload-symbols", args=("never",))(Alias) 46 register_strategy("reprocess-symbols", args=("never",))(Alias) 47 register_strategy( 48 "skip-unless-missing-or-changed", 49 args=("skip-unless-missing", "skip-unless-changed"), 50 kwargs={"split_args": lambda args, _: (args[0], args[1])}, 51 )(All) 52 53 54 # Strategy overrides used to tweak the default strategies. These are referenced 55 # by the `optimize_strategies` parameter. 56 57 58 class project: 59 """Strategies that should be applied per-project.""" 60 61 autoland = { 62 "test": Any( 63 # This `Any` strategy implements bi-modal behaviour. It allows different 64 # strategies on expanded pushes vs regular pushes. 65 # This first `All` handles "expanded" pushes. 66 All( 67 # There are three substrategies in this `All`, the first two act as barriers 68 # that help determine when to apply the third: 69 # 1. On backstop pushes, `skip-unless-backstop` returns False. Therefore 70 # the overall composite strategy is False and we don't optimize. 71 # 2. On regular pushes, `Not('skip-unless-expanded')` returns False. Therefore 72 # the overall composite strategy is False and we don't optimize. 73 # 3. On expanded pushes, the third strategy will determine whether or 74 # not to optimize each individual task. 75 # The barrier strategies. 76 "skip-unless-backstop", 77 Not("skip-unless-expanded"), 78 # The actual test strategy applied to "expanded" pushes. 79 Any( 80 "skip-unless-schedules", 81 "bugbug-reduced-manifests-fallback-last-10-pushes", 82 "platform-disperse", 83 split_args=split_bugbug_arg, 84 ), 85 ), 86 # This second `All` handles regular (aka not expanded or backstop) 87 # pushes. 88 All( 89 # There are two substrategies in this `All`, the first acts as a barrier 90 # that determines when to apply the second: 91 # 1. On expanded pushes (which includes backstops), `skip-unless-expanded` 92 # returns False. Therefore the overall composite strategy is False and we 93 # don't optimize. 94 # 2. On regular pushes, the second strategy will determine whether or 95 # not to optimize each individual task. 96 # The barrier strategy. 97 "skip-unless-expanded", 98 # The actual test strategy applied to regular pushes. 99 Any( 100 "skip-unless-schedules", 101 "bugbug-reduced-manifests-fallback-low", 102 "platform-disperse", 103 split_args=split_bugbug_arg, 104 ), 105 ), 106 ), 107 "build": All( 108 "skip-unless-expanded", 109 Any( 110 "skip-unless-schedules", 111 "bugbug-reduced-fallback", 112 split_args=split_bugbug_arg, 113 ), 114 ), 115 } 116 """Strategy overrides that apply to autoland.""" 117 118 119 class experimental: 120 """Experimental strategies either under development or used as benchmarks. 121 122 These run as "shadow-schedulers" on each autoland push (tier 3) and/or can be used 123 with `./mach try auto`. E.g: 124 125 ./mach try auto --strategy relevant_tests 126 """ 127 128 bugbug_tasks_medium = { 129 "test": Any( 130 "skip-unless-schedules", "bugbug-tasks-medium", split_args=split_bugbug_arg 131 ), 132 } 133 """Doesn't limit platforms, medium confidence threshold.""" 134 135 bugbug_tasks_high = { 136 "test": Any( 137 "skip-unless-schedules", "bugbug-tasks-high", split_args=split_bugbug_arg 138 ), 139 } 140 """Doesn't limit platforms, high confidence threshold.""" 141 142 bugbug_debug_disperse = { 143 "test": Any( 144 "skip-unless-schedules", 145 "bugbug-low", 146 "platform-debug", 147 "platform-disperse", 148 split_args=split_bugbug_arg, 149 ), 150 } 151 """Restricts tests to debug platforms.""" 152 153 bugbug_disperse_low = { 154 "test": Any( 155 "skip-unless-schedules", 156 "bugbug-low", 157 "platform-disperse", 158 split_args=split_bugbug_arg, 159 ), 160 } 161 """Disperse tests across platforms, low confidence threshold.""" 162 163 bugbug_disperse_medium = { 164 "test": Any( 165 "skip-unless-schedules", 166 "bugbug-medium", 167 "platform-disperse", 168 split_args=split_bugbug_arg, 169 ), 170 } 171 """Disperse tests across platforms, medium confidence threshold.""" 172 173 bugbug_disperse_reduced_medium = { 174 "test": Any( 175 "skip-unless-schedules", 176 "bugbug-reduced-manifests", 177 "platform-disperse", 178 split_args=split_bugbug_arg, 179 ), 180 } 181 """Disperse tests across platforms, medium confidence threshold with reduced tasks.""" 182 183 bugbug_reduced_manifests_config_selection_low = { 184 "test": Any( 185 "skip-unless-schedules", 186 "bugbug-reduced-manifests-config-selection-low", 187 split_args=split_bugbug_arg, 188 ), 189 } 190 """Choose configs selected by bugbug, low confidence threshold with reduced tasks.""" 191 192 bugbug_reduced_manifests_config_selection_medium = { 193 "test": Any( 194 "skip-unless-schedules", 195 "bugbug-reduced-manifests-config-selection", 196 split_args=split_bugbug_arg, 197 ), 198 } 199 """Choose configs selected by bugbug, medium confidence threshold with reduced tasks.""" 200 201 bugbug_disperse_medium_no_unseen = { 202 "test": Any( 203 "skip-unless-schedules", 204 "bugbug-medium", 205 "platform-disperse-no-unseen", 206 split_args=split_bugbug_arg, 207 ), 208 } 209 """Disperse tests across platforms (no modified for unseen configurations), medium confidence 210 threshold.""" 211 212 bugbug_disperse_medium_only_one = { 213 "test": Any( 214 "skip-unless-schedules", 215 "bugbug-medium", 216 "platform-disperse-only-one", 217 split_args=split_bugbug_arg, 218 ), 219 } 220 """Disperse tests across platforms (one platform per group), medium confidence threshold.""" 221 222 bugbug_disperse_high = { 223 "test": Any( 224 "skip-unless-schedules", 225 "bugbug-high", 226 "platform-disperse", 227 split_args=split_bugbug_arg, 228 ), 229 } 230 """Disperse tests across platforms, high confidence threshold.""" 231 232 bugbug_reduced = { 233 "test": Any( 234 "skip-unless-schedules", "bugbug-reduced", split_args=split_bugbug_arg 235 ), 236 } 237 """Use the reduced set of tasks (and no groups) chosen by bugbug.""" 238 239 bugbug_reduced_high = { 240 "test": Any( 241 "skip-unless-schedules", "bugbug-reduced-high", split_args=split_bugbug_arg 242 ), 243 } 244 """Use the reduced set of tasks (and no groups) chosen by bugbug, high 245 confidence threshold.""" 246 247 relevant_tests = { 248 "test": Any("skip-unless-schedules", "skip-unless-has-relevant-tests"), 249 } 250 """Runs task containing tests in the same directories as modified files.""" 251 252 253 class ExperimentalOverride: 254 """Overrides dictionaries that are stored in a container with new values. 255 256 This can be used to modify all strategies in a collection the same way, 257 presumably with strategies affecting kinds of tasks tangential to the 258 current context. 259 260 Args: 261 base (object): A container class supporting attribute access. 262 overrides (dict): Values to update any accessed dictionaries with. 263 """ 264 265 def __init__(self, base, overrides): 266 self.base = base 267 self.overrides = overrides 268 269 def __getattr__(self, name): 270 val = getattr(self.base, name).copy() 271 for override_name, strategy in self.overrides.items(): 272 if isinstance(strategy, str) and strategy.startswith("base:"): 273 strategy = val[strategy[len("base:") :]] 274 275 val[override_name] = strategy 276 return val 277 278 279 tryselect = ExperimentalOverride( 280 experimental, 281 { 282 "build": Any( 283 "skip-unless-schedules", "bugbug-reduced", split_args=split_bugbug_arg 284 ), 285 "test-verify": "base:test", 286 "upload-symbols": Alias("always"), 287 "reprocess-symbols": Alias("always"), 288 }, 289 )