Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: appengine/findit/waterfall/flake/initialize_flake_pipeline.py

Issue 2369333002: [Findit] Capture versionized metadata for master_flake_analysis (Closed)
Patch Set: Fixing nits Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 from google.appengine.ext import ndb 5 import logging
6 6
7 from common import appengine_util 7 from common import appengine_util
8 from common import constants 8 from common import constants
9 from common import time_util
9 from model import analysis_status 10 from model import analysis_status
10 from model.flake.master_flake_analysis import MasterFlakeAnalysis 11 from model.flake.master_flake_analysis import MasterFlakeAnalysis
11 from waterfall import waterfall_config 12 from waterfall import waterfall_config
12 from waterfall.flake.recursive_flake_pipeline import RecursiveFlakePipeline 13 from waterfall.flake.recursive_flake_pipeline import RecursiveFlakePipeline
13 14
14 15
15 @ndb.transactional
16 def NeedANewAnalysis( 16 def NeedANewAnalysis(
17 master_name, builder_name, build_number, step_name, test_name, 17 master_name, builder_name, build_number, step_name, test_name,
18 allow_new_analysis=False): 18 allow_new_analysis=False):
19 """Checks status of analysis for the test and decides if a new one is needed. 19 """Checks status of analysis for the test and decides if a new one is needed.
20 20
21 A MasterFlakeAnalysis entity for the given parameters will be created if none 21 A MasterFlakeAnalysis entity for the given parameters will be created if none
22 exists. When a new analysis is needed, this function will create and 22 exists. When a new analysis is needed, this function will create and
23 save a MasterFlakeAnalysis entity to the datastore. 23 save a MasterFlakeAnalysis entity to the datastore.
24 24
25 TODO(lijeffrey): add support for a force flag to rerun this analysis.
26
25 Returns: 27 Returns:
26 True if an analysis is needed, otherwise False. 28 True if an analysis is needed, otherwise False.
27 """ 29 """
28 master_flake_analysis = MasterFlakeAnalysis.Get( 30 master_flake_analysis = MasterFlakeAnalysis.GetVersion(
29 master_name, builder_name, build_number, step_name, test_name) 31 master_name, builder_name, build_number, step_name, test_name)
30 32
31 if not master_flake_analysis: 33 if not master_flake_analysis:
32 if not allow_new_analysis: 34 if not allow_new_analysis:
33 return False 35 return False
34 master_flake_analysis = MasterFlakeAnalysis.Create( 36 master_flake_analysis = MasterFlakeAnalysis.Create(
35 master_name, builder_name, build_number, step_name, test_name) 37 master_name, builder_name, build_number, step_name, test_name)
38 master_flake_analysis.created_time = time_util.GetUTCNow()
36 master_flake_analysis.status = analysis_status.PENDING 39 master_flake_analysis.status = analysis_status.PENDING
37 master_flake_analysis.put() 40 _, saved = master_flake_analysis.Save()
38 return True 41 return saved
39 elif (master_flake_analysis.status == analysis_status.COMPLETED or 42 elif (master_flake_analysis.status == analysis_status.COMPLETED or
40 master_flake_analysis.status == analysis_status.PENDING or 43 master_flake_analysis.status == analysis_status.PENDING or
41 master_flake_analysis.status == analysis_status.RUNNING): 44 master_flake_analysis.status == analysis_status.RUNNING):
42 return False 45 return False
43 else: 46 else:
44 # TODO(caiw): Reset method. 47 # The previous analysis had some error, so reset and run as a new version.
45 MasterFlakeAnalysis.Get( 48 master_flake_analysis.Reset()
46 master_name, builder_name, build_number, 49 _, saved = master_flake_analysis.Save()
47 step_name, test_name).key.delete() 50 return saved
48 master_flake_analysis = MasterFlakeAnalysis.Create(
49 master_name, builder_name, build_number, step_name, test_name)
50 master_flake_analysis.status = analysis_status.PENDING
51 master_flake_analysis.put()
52 return True
53 51
54 52
55 # Unused arguments - pylint: disable=W0612, W0613 53 # Unused arguments - pylint: disable=W0612, W0613
56 def ScheduleAnalysisIfNeeded(master_name, builder_name, build_number, step_name, 54 def ScheduleAnalysisIfNeeded(master_name, builder_name, build_number, step_name,
57 test_name, allow_new_analysis=False, force=False, 55 test_name, allow_new_analysis=False, force=False,
58 queue_name=constants.DEFAULT_QUEUE): 56 queue_name=constants.DEFAULT_QUEUE):
59 """Schedules an analysis if needed and returns the MasterFlakeAnalysis. 57 """Schedules an analysis if needed and returns the MasterFlakeAnalysis.
60 58
61 When the build failure was already analyzed and a new analysis is scheduled, 59 When the build failure was already analyzed and a new analysis is scheduled,
62 the returned WfAnalysis will still have the result of last completed analysis. 60 the returned WfAnalysis will still have the result of last completed analysis.
63 61
64 Args: 62 Args:
65 master_name (str): The master name of the failed test 63 master_name (str): The master name of the failed test
66 builder_name (str): The builder name of the failed test 64 builder_name (str): The builder name of the failed test
67 build_number (int): The build number of the failed test 65 build_number (int): The build number of the failed test
68 step_name (str): The name of the test suite 66 step_name (str): The name of the test suite
69 test_name (str): The single test we are checking 67 test_name (str): The single test we are checking
70 allow_new_analysis (bool): Indicate whether a new analysis is allowed. 68 allow_new_analysis (bool): Indicate whether a new analysis is allowed.
71 force (bool): Indicate whether to force a rerun of current analysis. 69 force (bool): Indicate whether to force a rerun of current analysis.
72 queue_name (str): The App Engine queue to run the analysis. 70 queue_name (str): The App Engine queue to run the analysis.
73 71
74 Returns: 72 Returns:
75 A MasterFlakeAnalysis instance. 73 A MasterFlakeAnalysis instance.
76 None if no analysis was scheduled and the user has no permission to. 74 None if no analysis was scheduled and the user has no permission to.
77 """ 75 """
76
77 version_number = None
78
78 if NeedANewAnalysis( 79 if NeedANewAnalysis(
79 master_name, builder_name, build_number, step_name, test_name, 80 master_name, builder_name, build_number, step_name, test_name,
80 allow_new_analysis): 81 allow_new_analysis):
82
83 # NeedANewAnalysis just created master_flake_analysis. Use the latest
84 # version number and pass that along to the other pipelines for updating
85 # results and data.
86 master_flake_analysis = MasterFlakeAnalysis.GetVersion(
87 master_name, builder_name, build_number, step_name, test_name)
88 version_number = master_flake_analysis.version_number
89 logging.info(
90 'A new master flake analysis was successfully saved for %s/%s/%s/%s/%s '
91 'and will be captured in version %s', master_name, builder_name,
92 build_number, step_name, test_name, version_number)
93
94 # TODO(lijeffrey): Allow for reruns with custom parameters if the user is
95 # not satisfied with the results. Record the custom parameters here.
81 check_flake_settings = waterfall_config.GetCheckFlakeSettings() 96 check_flake_settings = waterfall_config.GetCheckFlakeSettings()
97 master_flake_analysis.algorithm_parameters = check_flake_settings
98 master_flake_analysis.put()
99
82 max_build_numbers_to_look_back = check_flake_settings.get( 100 max_build_numbers_to_look_back = check_flake_settings.get(
83 'max_build_numbers_to_look_back') 101 'max_build_numbers_to_look_back')
84 flakiness_algorithm_results_dict = { 102 flakiness_algorithm_results_dict = {
85 'flakes_in_a_row': 0, 103 'flakes_in_a_row': 0,
86 'stable_in_a_row': 0, 104 'stable_in_a_row': 0,
87 'stabled_out': False, 105 'stabled_out': False,
88 'flaked_out': False, 106 'flaked_out': False,
89 'last_build_number': max( 107 'last_build_number': max(
90 0, build_number - max_build_numbers_to_look_back), 108 0, build_number - max_build_numbers_to_look_back),
91 'lower_boundary': None, 109 'lower_boundary': None,
92 'upper_boundary': None, 110 'upper_boundary': None,
93 'lower_boundary_result': None, 111 'lower_boundary_result': None,
94 'sequential_run_index': 0 112 'sequential_run_index': 0
95 } 113 }
114
96 pipeline_job = RecursiveFlakePipeline( 115 pipeline_job = RecursiveFlakePipeline(
97 master_name, builder_name, build_number, step_name, test_name, 116 master_name, builder_name, build_number, step_name, test_name,
98 master_build_number=build_number, 117 version_number, master_build_number=build_number,
99 flakiness_algorithm_results_dict=flakiness_algorithm_results_dict) 118 flakiness_algorithm_results_dict=flakiness_algorithm_results_dict)
100 pipeline_job.target = appengine_util.GetTargetNameForModule( 119 pipeline_job.target = appengine_util.GetTargetNameForModule(
101 constants.WATERFALL_BACKEND) 120 constants.WATERFALL_BACKEND)
102 pipeline_job.start(queue_name=queue_name) 121 pipeline_job.start(queue_name=queue_name)
103 return MasterFlakeAnalysis.Get( 122 return MasterFlakeAnalysis.GetVersion(
104 master_name, builder_name, build_number, step_name, test_name) 123 master_name, builder_name, build_number, step_name, test_name,
124 version=version_number)
OLDNEW
« no previous file with comments | « appengine/findit/templates/flake/result.html ('k') | appengine/findit/waterfall/flake/recursive_flake_pipeline.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698