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