| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 import copy | |
| 6 from datetime import datetime | |
| 7 | |
| 8 from common import appengine_util | 5 from common import appengine_util |
| 9 from common import constants | 6 from common import constants |
| 10 from common.pipeline_wrapper import BasePipeline | 7 from common.pipeline_wrapper import BasePipeline |
| 11 | 8 |
| 12 from model import analysis_status | 9 from model import analysis_status |
| 10 from model.flake.flake_swarming_task import FlakeSwarmingTask |
| 13 from model.flake.master_flake_analysis import MasterFlakeAnalysis | 11 from model.flake.master_flake_analysis import MasterFlakeAnalysis |
| 14 from model.flake.flake_swarming_task import FlakeSwarmingTask | 12 from waterfall import waterfall_config |
| 13 from waterfall.process_flake_swarming_task_result_pipeline import ( |
| 14 ProcessFlakeSwarmingTaskResultPipeline) |
| 15 from waterfall.trigger_flake_swarming_task_pipeline import ( | 15 from waterfall.trigger_flake_swarming_task_pipeline import ( |
| 16 TriggerFlakeSwarmingTaskPipeline) | 16 TriggerFlakeSwarmingTaskPipeline) |
| 17 from waterfall.process_flake_swarming_task_result_pipeline import ( | |
| 18 ProcessFlakeSwarmingTaskResultPipeline) | |
| 19 | |
| 20 # TODO(lijeffrey): Move to config. | |
| 21 LOWER_FLAKE_THRESHOLD = .02 | |
| 22 UPPER_FLAKE_THRESHOLD = .98 | |
| 23 MAX_FLAKE_IN_A_ROW = 4 | |
| 24 MAX_STABLE_IN_A_ROW = 4 | |
| 25 | 17 |
| 26 | 18 |
| 27 class RecursiveFlakePipeline(BasePipeline): | 19 class RecursiveFlakePipeline(BasePipeline): |
| 20 |
| 28 # Arguments number differs from overridden method - pylint: disable=W0221 | 21 # Arguments number differs from overridden method - pylint: disable=W0221 |
| 29 def run(self, master_name, builder_name, run_build_number, step_name, | 22 def run(self, master_name, builder_name, run_build_number, step_name, |
| 30 test_name, master_build_number, flakiness_algorithm_results_dict, | 23 test_name, master_build_number, flakiness_algorithm_results_dict, |
| 31 queue_name=constants.DEFAULT_QUEUE): | 24 queue_name=constants.DEFAULT_QUEUE): |
| 32 """ | 25 """Pipeline to determine the regression range of a flaky test. |
| 26 |
| 33 Args: | 27 Args: |
| 34 master_name (str): The master name. | 28 master_name (str): The master name. |
| 35 builder_name (str): The builder name. | 29 builder_name (str): The builder name. |
| 36 run_build_number (int): The build number of the current swarming rerun. | 30 run_build_number (int): The build number of the current swarming rerun. |
| 37 step_name (str): The step name. | 31 step_name (str): The step name. |
| 38 test_name (str): The test name. | 32 test_name (str): The test name. |
| 39 master_build_number (int): The build number of the Master_Flake_analysis. | 33 master_build_number (int): The build number of the Master_Flake_analysis. |
| 40 flakiness_algorithm_results_dict (dict): A dictionary used by | 34 flakiness_algorithm_results_dict (dict): A dictionary used by |
| 41 NextBuildNumberPipeline | 35 NextBuildNumberPipeline |
| 42 queue_name (str): Which queue to run on. | 36 queue_name (str): Which queue to run on. |
| 37 |
| 43 Returns: | 38 Returns: |
| 44 A dict of lists for reliable/flaky tests. | 39 A dict of lists for reliable/flaky tests. |
| 45 """ | 40 """ |
| 46 | 41 |
| 47 # Call trigger pipeline (flake style). | 42 # Call trigger pipeline (flake style). |
| 48 task_id = yield TriggerFlakeSwarmingTaskPipeline( | 43 task_id = yield TriggerFlakeSwarmingTaskPipeline( |
| 49 master_name, builder_name, run_build_number, step_name, [test_name]) | 44 master_name, builder_name, run_build_number, step_name, [test_name]) |
| 50 # Pass the trigger pipeline into a process pipeline. | 45 # Pass the trigger pipeline into a process pipeline. |
| 51 test_result_future = yield ProcessFlakeSwarmingTaskResultPipeline( | 46 test_result_future = yield ProcessFlakeSwarmingTaskResultPipeline( |
| 52 master_name, builder_name, run_build_number, | 47 master_name, builder_name, run_build_number, |
| 53 step_name, task_id, master_build_number, test_name) | 48 step_name, task_id, master_build_number, test_name) |
| 54 yield NextBuildNumberPipeline( | 49 yield NextBuildNumberPipeline( |
| 55 master_name, builder_name, master_build_number, run_build_number, | 50 master_name, builder_name, master_build_number, run_build_number, |
| 56 step_name, test_name, test_result_future, queue_name, | 51 step_name, test_name, test_result_future, queue_name, |
| 57 flakiness_algorithm_results_dict) | 52 flakiness_algorithm_results_dict) |
| 58 | 53 |
| 59 | 54 |
| 60 def get_next_run(master, flakiness_algorithm_results_dict): | 55 def get_next_run(master, flakiness_algorithm_results_dict): |
| 61 # A description of this algorithm can be found at: | 56 # A description of this algorithm can be found at: |
| 62 # https://docs.google.com/document/d/1wPYFZ5OT998Yn7O8wGDOhgfcQ98mknoX13AesJ
aS6ig/edit | 57 # https://docs.google.com/document/d/1wPYFZ5OT998Yn7O8wGDOhgfcQ98mknoX13AesJaS
6ig/edit |
| 63 # Get the last result. | 58 # Get the last result. |
| 64 last_result = master.success_rates[-1] | 59 last_result = master.success_rates[-1] |
| 65 cur_run = min(master.build_numbers) | 60 cur_run = min(master.build_numbers) |
| 66 if (last_result < LOWER_FLAKE_THRESHOLD or | 61 flake_settings = waterfall_config.GetCheckFlakeSettings() |
| 67 last_result > UPPER_FLAKE_THRESHOLD): # Stable result. | 62 lower_flake_threshold = flake_settings.get('lower_flake_threshold') |
| 68 flakiness_algorithm_results_dict['stable_in_a_row'] += 1 | 63 upper_flake_threshold = flake_settings.get('upper_flake_threshold') |
| 69 if (flakiness_algorithm_results_dict['stable_in_a_row'] > | 64 max_stable_in_a_row = flake_settings.get('max_stable_in_a_row') |
| 70 MAX_STABLE_IN_A_ROW): #Identified a stable region. | 65 max_flake_in_a_row = flake_settings.get('max_flake_in_a_row') |
| 71 flakiness_algorithm_results_dict['stabled_out'] = True | 66 |
| 72 if (flakiness_algorithm_results_dict['stabled_out'] and | 67 if (last_result < lower_flake_threshold or |
| 73 not flakiness_algorithm_results_dict['flaked_out']): | 68 last_result > upper_flake_threshold): # Stable result. |
| 74 # Identified a candidate for the upper boundary. | 69 flakiness_algorithm_results_dict['stable_in_a_row'] += 1 |
| 75 # Earliest stable point to the right of a flaky region. | 70 if (flakiness_algorithm_results_dict['stable_in_a_row'] > |
| 76 flakiness_algorithm_results_dict['upper_boundary'] = cur_run | 71 max_stable_in_a_row): # Identified a stable region. |
| 77 flakiness_algorithm_results_dict['lower_boundary'] = None | 72 flakiness_algorithm_results_dict['stabled_out'] = True |
| 78 elif (flakiness_algorithm_results_dict['flaked_out'] and | 73 if (flakiness_algorithm_results_dict['stabled_out'] and |
| 79 not flakiness_algorithm_results_dict['stabled_out'] and | 74 not flakiness_algorithm_results_dict['flaked_out']): |
| 80 not flakiness_algorithm_results_dict['lower_boundary']): | 75 # Identified a candidate for the upper boundary. |
| 81 # Identified a candidate for the lower boundary. | 76 # Earliest stable point to the right of a flaky region. |
| 82 # Latest stable point to the left of a flaky region. | 77 flakiness_algorithm_results_dict['upper_boundary'] = cur_run |
| 83 flakiness_algorithm_results_dict['lower_boundary'] = cur_run | 78 flakiness_algorithm_results_dict['lower_boundary'] = None |
| 84 flakiness_algorithm_results_dict['lower_boundary_result'] = 'STABLE' | 79 elif (flakiness_algorithm_results_dict['flaked_out'] and |
| 85 flakiness_algorithm_results_dict['flakes_in_a_row'] = 0 | 80 not flakiness_algorithm_results_dict['stabled_out'] and |
| 86 step_size = flakiness_algorithm_results_dict['stable_in_a_row'] + 1 | 81 not flakiness_algorithm_results_dict['lower_boundary']): |
| 87 else: # Flaky result. | 82 # Identified a candidate for the lower boundary. |
| 88 flakiness_algorithm_results_dict['flakes_in_a_row'] += 1 | 83 # Latest stable point to the left of a flaky region. |
| 89 if (flakiness_algorithm_results_dict['flakes_in_a_row'] > | 84 flakiness_algorithm_results_dict['lower_boundary'] = cur_run |
| 90 MAX_FLAKE_IN_A_ROW): #Identified a flaky region. | 85 flakiness_algorithm_results_dict['lower_boundary_result'] = 'STABLE' |
| 91 flakiness_algorithm_results_dict['flaked_out'] = True | 86 flakiness_algorithm_results_dict['flakes_in_a_row'] = 0 |
| 92 if (flakiness_algorithm_results_dict['flaked_out'] and | 87 step_size = flakiness_algorithm_results_dict['stable_in_a_row'] + 1 |
| 93 not flakiness_algorithm_results_dict['stabled_out']): | 88 else: |
| 94 # Identified a candidate for the upper boundary. | 89 # Flaky result. |
| 95 # Earliest flaky point to the right of a stable region. | 90 flakiness_algorithm_results_dict['flakes_in_a_row'] += 1 |
| 96 flakiness_algorithm_results_dict['upper_boundary'] = cur_run | 91 if (flakiness_algorithm_results_dict['flakes_in_a_row'] > |
| 97 flakiness_algorithm_results_dict['lower_boundary'] = None | 92 max_flake_in_a_row): # Identified a flaky region. |
| 98 elif (flakiness_algorithm_results_dict['stabled_out'] and | 93 flakiness_algorithm_results_dict['flaked_out'] = True |
| 99 not flakiness_algorithm_results_dict['flaked_out'] and | 94 if (flakiness_algorithm_results_dict['flaked_out'] and |
| 100 not flakiness_algorithm_results_dict['lower_boundary']): | 95 not flakiness_algorithm_results_dict['stabled_out']): |
| 101 # Identified a candidate for the lower boundary. | 96 # Identified a candidate for the upper boundary. |
| 102 # Latest flaky point to the left of a stable region. | 97 # Earliest flaky point to the right of a stable region. |
| 103 flakiness_algorithm_results_dict['lower_boundary'] = cur_run | 98 flakiness_algorithm_results_dict['upper_boundary'] = cur_run |
| 104 flakiness_algorithm_results_dict['lower_boundary_result'] = 'FLAKE' | 99 flakiness_algorithm_results_dict['lower_boundary'] = None |
| 105 flakiness_algorithm_results_dict['stable_in_a_row'] = 0 | 100 elif (flakiness_algorithm_results_dict['stabled_out'] and |
| 106 step_size = flakiness_algorithm_results_dict['flakes_in_a_row'] + 1 | 101 not flakiness_algorithm_results_dict['flaked_out'] and |
| 107 next_run = cur_run - step_size | 102 not flakiness_algorithm_results_dict['lower_boundary']): |
| 108 return next_run | 103 # Identified a candidate for the lower boundary. |
| 104 # Latest flaky point to the left of a stable region. |
| 105 flakiness_algorithm_results_dict['lower_boundary'] = cur_run |
| 106 flakiness_algorithm_results_dict['lower_boundary_result'] = 'FLAKE' |
| 107 flakiness_algorithm_results_dict['stable_in_a_row'] = 0 |
| 108 step_size = flakiness_algorithm_results_dict['flakes_in_a_row'] + 1 |
| 109 next_run = cur_run - step_size |
| 110 return next_run |
| 109 | 111 |
| 110 | 112 |
| 111 def sequential_next_run(master, flakiness_algorithm_results_dict): | 113 def sequential_next_run(master, flakiness_algorithm_results_dict): |
| 112 last_result = master.success_rates[-1] | 114 last_result = master.success_rates[-1] |
| 113 last_result_status = 'FLAKE' | 115 last_result_status = 'FLAKE' |
| 114 if (last_result < LOWER_FLAKE_THRESHOLD or | 116 flake_settings = waterfall_config.GetCheckFlakeSettings() |
| 115 last_result > UPPER_FLAKE_THRESHOLD): | 117 lower_flake_threshold = flake_settings.get('lower_flake_threshold') |
| 118 upper_flake_threshold = flake_settings.get('upper_flake_threshold') |
| 119 |
| 120 if (last_result < lower_flake_threshold or |
| 121 last_result > upper_flake_threshold): |
| 116 last_result_status = 'STABLE' | 122 last_result_status = 'STABLE' |
| 117 if flakiness_algorithm_results_dict['sequential_run_index'] > 0: | 123 if flakiness_algorithm_results_dict['sequential_run_index'] > 0: |
| 118 if (last_result_status != | 124 if (last_result_status != |
| 119 flakiness_algorithm_results_dict['lower_boundary_result']): | 125 flakiness_algorithm_results_dict['lower_boundary_result']): |
| 120 master.suspected_flake_build_number = ( | 126 master.suspected_flake_build_number = ( |
| 121 flakiness_algorithm_results_dict['lower_boundary'] + | 127 flakiness_algorithm_results_dict['lower_boundary'] + |
| 122 flakiness_algorithm_results_dict['sequential_run_index']) | 128 flakiness_algorithm_results_dict['sequential_run_index']) |
| 123 master.put() | 129 master.put() |
| 124 return 0 | 130 return 0 |
| 125 flakiness_algorithm_results_dict['sequential_run_index'] += 1 | 131 flakiness_algorithm_results_dict['sequential_run_index'] += 1 |
| 126 return (flakiness_algorithm_results_dict['lower_boundary'] + | 132 return (flakiness_algorithm_results_dict['lower_boundary'] + |
| 127 flakiness_algorithm_results_dict['sequential_run_index']) | 133 flakiness_algorithm_results_dict['sequential_run_index']) |
| 128 | 134 |
| 135 |
| 129 class NextBuildNumberPipeline(BasePipeline): | 136 class NextBuildNumberPipeline(BasePipeline): |
| 130 | 137 |
| 131 # Arguments number differs from overridden method - pylint: disable=W0221 | 138 # Arguments number differs from overridden method - pylint: disable=W0221 |
| 132 # Unused argument - pylint: disable=W0613 | 139 # Unused argument - pylint: disable=W0613 |
| 133 def run(self, master_name, builder_name, master_build_number, | 140 def run(self, master_name, builder_name, master_build_number, |
| 134 run_build_number, step_name, test_name, test_result_future, | 141 run_build_number, step_name, test_name, test_result_future, |
| 135 queue_name, flakiness_algorithm_results_dict): | 142 queue_name, flakiness_algorithm_results_dict): |
| 136 | 143 |
| 137 | |
| 138 # Get MasterFlakeAnalysis success list corresponding to parameters. | 144 # Get MasterFlakeAnalysis success list corresponding to parameters. |
| 139 master = MasterFlakeAnalysis.Get(master_name, builder_name, | 145 master = MasterFlakeAnalysis.Get(master_name, builder_name, |
| 140 master_build_number, step_name, test_name) | 146 master_build_number, step_name, test_name) |
| 141 # Don't call another pipeline if we fail. | 147 # Don't call another pipeline if we fail. |
| 142 flake_swarming_task = FlakeSwarmingTask.Get( | 148 flake_swarming_task = FlakeSwarmingTask.Get( |
| 143 master_name, builder_name, run_build_number, step_name, test_name) | 149 master_name, builder_name, run_build_number, step_name, test_name) |
| 144 | 150 |
| 145 # TODO(stgao): Handle case where test doesn't exist. | 151 # TODO(stgao): Handle case where test doesn't exist. |
| 146 if flake_swarming_task.status == analysis_status.ERROR: | 152 if flake_swarming_task.status == analysis_status.ERROR: |
| 147 master.status = analysis_status.ERROR | 153 master.status = analysis_status.ERROR |
| 148 master.put() | 154 master.put() |
| 149 return | 155 return |
| 150 | 156 |
| 151 # Figure out what build_number we should call, if any | 157 # Figure out what build_number we should call, if any |
| 152 if (flakiness_algorithm_results_dict['stabled_out'] and | 158 if (flakiness_algorithm_results_dict['stabled_out'] and |
| 153 flakiness_algorithm_results_dict['flaked_out']): | 159 flakiness_algorithm_results_dict['flaked_out']): |
| 154 next_run = sequential_next_run(master, flakiness_algorithm_results_dict) | 160 next_run = sequential_next_run(master, flakiness_algorithm_results_dict) |
| 155 else: | 161 else: |
| 156 next_run = get_next_run(master, flakiness_algorithm_results_dict) | 162 next_run = get_next_run(master, flakiness_algorithm_results_dict) |
| 157 | 163 |
| 158 if (next_run < flakiness_algorithm_results_dict['last_build_number']): | 164 if next_run < flakiness_algorithm_results_dict['last_build_number']: |
| 159 next_run = 0 | 165 next_run = 0 |
| 160 | 166 |
| 161 if next_run: | 167 if next_run: |
| 162 pipeline_job = RecursiveFlakePipeline( | 168 pipeline_job = RecursiveFlakePipeline( |
| 163 master_name, builder_name, next_run, step_name, test_name, | 169 master_name, builder_name, next_run, step_name, test_name, |
| 164 master_build_number, | 170 master_build_number, |
| 165 flakiness_algorithm_results_dict=flakiness_algorithm_results_dict) | 171 flakiness_algorithm_results_dict=flakiness_algorithm_results_dict) |
| 166 # pylint: disable=W0201 | 172 # pylint: disable=W0201 |
| 167 pipeline_job.target = appengine_util.GetTargetNameForModule( | 173 pipeline_job.target = appengine_util.GetTargetNameForModule( |
| 168 constants.WATERFALL_BACKEND) | 174 constants.WATERFALL_BACKEND) |
| 169 pipeline_job.start(queue_name=queue_name) | 175 pipeline_job.start(queue_name=queue_name) |
| 170 else: | 176 else: |
| 171 master.status = analysis_status.COMPLETED | 177 master.status = analysis_status.COMPLETED |
| 172 master.put() | 178 master.put() |
| OLD | NEW |