Chromium Code Reviews| Index: appengine/findit/waterfall/flake/initialize_flake_pipeline.py |
| diff --git a/appengine/findit/waterfall/flake/initialize_flake_pipeline.py b/appengine/findit/waterfall/flake/initialize_flake_pipeline.py |
| index 797e602abe283a720790b2cf24808c3fb2928085..a9e167cd3ed272691b1b69967a2b88d8456aef57 100644 |
| --- a/appengine/findit/waterfall/flake/initialize_flake_pipeline.py |
| +++ b/appengine/findit/waterfall/flake/initialize_flake_pipeline.py |
| @@ -14,8 +14,8 @@ from waterfall.flake.recursive_flake_pipeline import RecursiveFlakePipeline |
| def _NeedANewAnalysis( |
| - master_name, builder_name, build_number, step_name, test_name, |
| - algorithm_parameters, allow_new_analysis=False, force=False): |
| + normalized_test, original_test, algorithm_parameters, |
| + bug_id=None, allow_new_analysis=False, force=False): |
| """Checks status of analysis for the test and decides if a new one is needed. |
| A MasterFlakeAnalysis entity for the given parameters will be created if none |
| @@ -23,11 +23,12 @@ def _NeedANewAnalysis( |
| save a MasterFlakeAnalysis entity to the datastore. |
| Args: |
| - master_name (str): The master name on Waterfall. |
| - builder_name (str): The builder name on Waterfall. |
| - build_number (int): The build number on Waterfall. |
| - step_name (str): The step in which the flaky test is found. |
| - test_name (str): The flaky test to be analyzed. |
| + normalized_test (TestInfo): Info of the normalized flaky test after mapping |
| + a CQ trybot step to a Waterfall buildbot step, striping prefix "PRE_" |
| + from a gtest, etc. |
| + original_test (TestInfo): Info of the original flaky test. |
| + algorithm_parameters (dict): Algorithm parameters to run the analysis. |
| + bug_id (int): The monorail bug id to update when analysis is done. |
| allow_new_analysis (bool): Indicate whether a new analysis is allowed. |
| force (bool): Indicate whether to force a rerun of current analysis. |
| @@ -37,17 +38,31 @@ def _NeedANewAnalysis( |
| analysis (MasterFlakeAnalysis): The MasterFlakeAnalysis entity. |
| """ |
| analysis = MasterFlakeAnalysis.GetVersion( |
| - master_name, builder_name, build_number, step_name, test_name) |
| + normalized_test.master_name, normalized_test.builder_name, |
| + normalized_test.build_number, normalized_test.step_name, |
| + normalized_test.test_name) |
| - if not analysis: |
| - if not allow_new_analysis: |
| - return False, None |
| - analysis = MasterFlakeAnalysis.Create( |
| - master_name, builder_name, build_number, step_name, test_name) |
| + def PopulateInfoToAnalysis(analysis): |
|
lijeffrey
2016/10/21 17:10:27
nit: How about rename this PopulateAnalysisInfo? A
stgao
2016/10/21 22:42:34
TestInfo is not a NDB model so it is not in model/
|
| + analysis.Reset() |
| analysis.request_time = time_util.GetUTCNow() |
| analysis.status = analysis_status.PENDING |
| analysis.algorithm_parameters = algorithm_parameters |
| analysis.version = appengine_util.GetCurrentVersion() |
| + analysis.original_master_name = original_test.master_name |
| + analysis.original_builder_name = original_test.builder_name |
| + analysis.original_build_number = original_test.build_number |
| + analysis.original_step_name = original_test.step_name |
| + analysis.original_test_name = original_test.test_name |
| + analysis.bug_id = bug_id |
| + |
| + if not analysis: |
| + if not allow_new_analysis: |
| + return False, None |
| + analysis = MasterFlakeAnalysis.Create( |
| + normalized_test.master_name, normalized_test.builder_name, |
| + normalized_test.build_number, normalized_test.step_name, |
| + normalized_test.test_name) |
| + PopulateInfoToAnalysis(analysis) |
| _, saved = analysis.Save() |
| return saved, analysis |
| elif (analysis.status == analysis_status.PENDING or |
| @@ -55,32 +70,28 @@ def _NeedANewAnalysis( |
| return False, analysis |
| elif allow_new_analysis and force and analysis.status in ( |
| analysis_status.ERROR, analysis_status.COMPLETED): |
| - analysis.Reset() |
| - analysis.request_time = time_util.GetUTCNow() |
| - analysis.status = analysis_status.PENDING |
| - analysis.algorithm_parameters = algorithm_parameters |
| - analysis.version = appengine_util.GetCurrentVersion() |
| + PopulateInfoToAnalysis(analysis) |
| _, saved = analysis.Save() |
| return saved, analysis |
| else: |
| return False, analysis |
| -def ScheduleAnalysisIfNeeded(master_name, builder_name, build_number, step_name, |
| - test_name, allow_new_analysis=False, force=False, |
| - manually_triggered=False, |
| - queue_name=constants.DEFAULT_QUEUE): |
| +def ScheduleAnalysisIfNeeded( |
| + normalized_test, original_test, bug_id=None, |
| + allow_new_analysis=False, force=False, manually_triggered=False, |
| + queue_name=constants.DEFAULT_QUEUE): |
| """Schedules an analysis if needed and returns the MasterFlakeAnalysis. |
| When the build failure was already analyzed and a new analysis is scheduled, |
| the returned WfAnalysis will still have the result of last completed analysis. |
| Args: |
| - master_name (str): The master name of the failed test |
| - builder_name (str): The builder name of the failed test |
| - build_number (int): The build number of the failed test |
| - step_name (str): The name of the test suite |
| - test_name (str): The single test we are checking |
| + normalized_test (TestInfo): Info of the normalized flaky test after mapping |
| + a CQ trybot step to a Waterfall buildbot step, striping prefix "PRE_" |
| + from a gtest, etc. |
| + original_test (TestInfo): Info of the original flaky test. |
| + bug_id (int): The monorail bug id to update when analysis is done. |
| allow_new_analysis (bool): Indicate whether a new analysis is allowed. |
| force (bool): Indicate whether to force a rerun of current analysis. |
| manually_triggered (bool): True if the analysis is from manual request, like |
| @@ -94,17 +105,17 @@ def ScheduleAnalysisIfNeeded(master_name, builder_name, build_number, step_name, |
| algorithm_parameters = waterfall_config.GetCheckFlakeSettings() |
| need_new_analysis, analysis = _NeedANewAnalysis( |
| - master_name, builder_name, build_number, step_name, test_name, |
| - algorithm_parameters, allow_new_analysis, force) |
| + normalized_test, original_test, algorithm_parameters, bug_id=bug_id, |
| + allow_new_analysis=allow_new_analysis, force=force) |
| if need_new_analysis: |
| # _NeedANewAnalysis just created master_flake_analysis. Use the latest |
| # version number and pass that along to the other pipelines for updating |
| # results and data. |
| logging.info( |
| - 'A new master flake analysis was successfully saved for %s/%s/%s/%s/%s ' |
| - 'and will be captured in version %s', master_name, builder_name, |
| - build_number, step_name, test_name, analysis.version_number) |
| + 'A new master flake analysis was successfully saved for %s (%s) and ' |
| + 'will be captured in version %s', repr(normalized_test), |
| + repr(original_test), analysis.version_number) |
| max_build_numbers_to_look_back = algorithm_parameters.get( |
| 'max_build_numbers_to_look_back') |
| @@ -114,7 +125,7 @@ def ScheduleAnalysisIfNeeded(master_name, builder_name, build_number, step_name, |
| 'stabled_out': False, |
| 'flaked_out': False, |
| 'last_build_number': max( |
| - 0, build_number - max_build_numbers_to_look_back), |
| + 0, normalized_test.build_number - max_build_numbers_to_look_back), |
| 'lower_boundary': None, |
| 'upper_boundary': None, |
| 'lower_boundary_result': None, |
| @@ -122,8 +133,10 @@ def ScheduleAnalysisIfNeeded(master_name, builder_name, build_number, step_name, |
| } |
| pipeline_job = RecursiveFlakePipeline( |
| - master_name, builder_name, build_number, step_name, test_name, |
| - analysis.version_number, master_build_number=build_number, |
| + normalized_test.master_name, normalized_test.builder_name, |
| + normalized_test.build_number, normalized_test.step_name, |
| + normalized_test.test_name, analysis.version_number, |
| + master_build_number=normalized_test.build_number, |
| flakiness_algorithm_results_dict=flakiness_algorithm_results_dict, |
| manually_triggered=manually_triggered) |
| pipeline_job.target = appengine_util.GetTargetNameForModule( |