Chromium Code Reviews| 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 # Get the last result. | |
| 62 last_result = master.success_rates[-1] | |
| 63 cur_run = min(master.build_numbers) | |
| 64 if (last_result < LOWER_FLAKE_THRESHOLD or | |
| 65 last_result > UPPER_FLAKE_THRESHOLD): # Stable result. | |
| 66 flakiness_algorithm_results_dict['stable_in_a_row'] += 1 | |
| 67 if (flakiness_algorithm_results_dict['stable_in_a_row'] > | |
| 68 MAX_STABLE_IN_A_ROW): #Identified a stable region. | |
| 69 flakiness_algorithm_results_dict['stabled_out'] = True | |
| 70 if (flakiness_algorithm_results_dict['stabled_out'] and | |
| 71 not flakiness_algorithm_results_dict['flaked_out']): | |
| 72 # Identified a candidate for the upper boundary. | |
|
stgao
2016/08/18 20:13:40
A reason of why this is the upper or lower boundar
| |
| 73 flakiness_algorithm_results_dict['upper_boundary'] = cur_run | |
| 74 flakiness_algorithm_results_dict['lower_boundary'] = None | |
| 75 elif (flakiness_algorithm_results_dict['flaked_out'] and | |
| 76 not flakiness_algorithm_results_dict['stabled_out'] and | |
| 77 not flakiness_algorithm_results_dict['lower_boundary']): | |
| 78 # Identified a candidate for the lower boundary. | |
| 79 flakiness_algorithm_results_dict['lower_boundary'] = cur_run | |
| 80 flakiness_algorithm_results_dict['lower_boundary_result'] = 'STABLE' | |
| 81 flakiness_algorithm_results_dict['flakes_in_a_row'] = 0 | |
| 82 step_size = flakiness_algorithm_results_dict['stable_in_a_row'] + 1 | |
| 83 else: # Flaky result. | |
| 84 flakiness_algorithm_results_dict['flakes_in_a_row'] += 1 | |
| 85 if (flakiness_algorithm_results_dict['flakes_in_a_row'] > | |
| 86 MAX_FLAKE_IN_A_ROW): #Identified a flaky region. | |
| 87 flakiness_algorithm_results_dict['flaked_out'] = True | |
| 88 if (flakiness_algorithm_results_dict['flaked_out'] and | |
| 89 not flakiness_algorithm_results_dict['stabled_out']): | |
| 90 # Identified a candidate for the upper boundary. | |
| 91 flakiness_algorithm_results_dict['upper_boundary'] = cur_run | |
| 92 flakiness_algorithm_results_dict['lower_boundary'] = None | |
| 93 elif (flakiness_algorithm_results_dict['stabled_out'] and | |
| 94 not flakiness_algorithm_results_dict['flaked_out'] and | |
| 95 not flakiness_algorithm_results_dict['lower_boundary']): | |
| 96 # Identified a candidate for the lower boundary. | |
| 97 flakiness_algorithm_results_dict['lower_boundary'] = cur_run | |
| 98 flakiness_algorithm_results_dict['lower_boundary_result'] = 'FLAKE' | |
| 99 flakiness_algorithm_results_dict['stable_in_a_row'] = 0 | |
| 100 step_size = flakiness_algorithm_results_dict['flakes_in_a_row'] + 1 | |
| 101 next_run = cur_run - step_size | |
| 102 return next_run | |
| 103 | |
| 104 | |
| 105 def sequential_next_run(master, flakiness_algorithm_results_dict): | |
| 106 last_result = master.success_rates[-1] | |
| 107 last_result_status = 'FLAKE' | |
| 108 if (last_result < LOWER_FLAKE_THRESHOLD or | |
| 109 last_result > UPPER_FLAKE_THRESHOLD): | |
| 110 last_result_status = 'STABLE' | |
| 111 if flakiness_algorithm_results_dict['sequential_run_index'] > 0: | |
| 112 if (last_result_status != | |
| 113 flakiness_algorithm_results_dict['lower_boundary_result']): | |
| 114 master.suspected_flake_build_number = ( | |
| 115 flakiness_algorithm_results_dict['lower_boundary'] + | |
| 116 flakiness_algorithm_results_dict['sequential_run_index']) | |
| 117 master.put() | |
| 118 return 0 | |
| 119 flakiness_algorithm_results_dict['sequential_run_index'] += 1 | |
| 120 return (flakiness_algorithm_results_dict['lower_boundary'] + | |
| 121 flakiness_algorithm_results_dict['sequential_run_index']) | |
| 34 | 122 |
| 35 class NextBuildNumberPipeline(BasePipeline): | 123 class NextBuildNumberPipeline(BasePipeline): |
| 124 | |
| 36 # Arguments number differs from overridden method - pylint: disable=W0221 | 125 # Arguments number differs from overridden method - pylint: disable=W0221 |
| 37 # Unused argument - pylint: disable=W0613 | 126 # Unused argument - pylint: disable=W0613 |
| 38 def run(self, master_name, builder_name, master_build_number, step_name, | 127 def run(self, master_name, builder_name, master_build_number, |
| 39 test_name, test_result_future, queue_name): | 128 run_build_number, step_name, test_name, test_result_future, |
| 129 queue_name, flakiness_algorithm_results_dict): | |
| 130 | |
| 131 | |
| 40 # Get MasterFlakeAnalysis success list corresponding to parameters. | 132 # Get MasterFlakeAnalysis success list corresponding to parameters. |
| 41 master = MasterFlakeAnalysis.Get(master_name, builder_name, | 133 master = MasterFlakeAnalysis.Get(master_name, builder_name, |
| 42 master_build_number, step_name, test_name) | 134 master_build_number, step_name, test_name) |
| 135 # Don't call another pipeline if we fail. | |
| 136 flake_swarming_task = FlakeSwarmingTask.Get( | |
| 137 master_name, builder_name, run_build_number, step_name, test_name) | |
| 138 | |
| 139 # TODO(stgao): Handle case where test doesn't exist. | |
| 140 if flake_swarming_task.status == analysis_status.ERROR: | |
| 141 master.status = analysis_status.ERROR | |
| 142 master.put() | |
| 143 return | |
| 144 | |
| 43 # Figure out what build_number we should call, if any | 145 # Figure out what build_number we should call, if any |
| 44 # This is a placeholder for testing: | 146 if (flakiness_algorithm_results_dict['stabled_out'] and |
| 45 next_run = False | 147 flakiness_algorithm_results_dict['flaked_out']): |
| 46 if len(master.build_numbers) < 10: | 148 next_run = sequential_next_run(master, flakiness_algorithm_results_dict) |
| 47 # TODO(caiw): Develop algorithm to optimize this. | 149 else: |
| 48 next_run = min(master.build_numbers) - 10 | 150 next_run = get_next_run(master, flakiness_algorithm_results_dict) |
| 151 | |
| 152 if (next_run < flakiness_algorithm_results_dict['last_build_number']): | |
| 153 next_run = 0 | |
| 154 | |
| 49 if next_run: | 155 if next_run: |
| 50 pipeline_job = RecursiveFlakePipeline( | 156 pipeline_job = RecursiveFlakePipeline( |
| 51 master_name, builder_name, next_run, step_name, test_name, | 157 master_name, builder_name, next_run, step_name, test_name, |
| 52 master_build_number) | 158 master_build_number, |
| 53 #pylint: disable=W0201 | 159 flakiness_algorithm_results_dict=flakiness_algorithm_results_dict) |
| 160 # pylint: disable=W0201 | |
| 54 pipeline_job.target = appengine_util.GetTargetNameForModule( | 161 pipeline_job.target = appengine_util.GetTargetNameForModule( |
| 55 constants.WATERFALL_BACKEND) | 162 constants.WATERFALL_BACKEND) |
| 56 pipeline_job.start(queue_name=queue_name) | 163 pipeline_job.start(queue_name=queue_name) |
| 164 else: | |
| 165 master.status = analysis_status.COMPLETED | |
| 166 master.put() | |
| OLD | NEW |