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

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: 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
6
7 from common import appengine_util 5 from common import appengine_util
8 from common import constants 6 from common import constants
9 from model import analysis_status 7 from model import analysis_status
10 from model.flake.master_flake_analysis import MasterFlakeAnalysis 8 from model.flake.master_flake_analysis import MasterFlakeAnalysis
11 from waterfall import waterfall_config 9 from waterfall import waterfall_config
12 from waterfall.flake.recursive_flake_pipeline import RecursiveFlakePipeline 10 from waterfall.flake.recursive_flake_pipeline import RecursiveFlakePipeline
13 11
14 12
15 @ndb.transactional
16 def NeedANewAnalysis( 13 def NeedANewAnalysis(
chanli 2016/09/27 22:15:24 I think we still need to make it transactional?
lijeffrey 2016/09/28 03:12:31 The Save() call already happens in a transaction,
17 master_name, builder_name, build_number, step_name, test_name, 14 master_name, builder_name, build_number, step_name, test_name,
18 allow_new_analysis=False): 15 allow_new_analysis=False):
19 """Checks status of analysis for the test and decides if a new one is needed. 16 """Checks status of analysis for the test and decides if a new one is needed.
20 17
21 A MasterFlakeAnalysis entity for the given parameters will be created if none 18 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 19 exists. When a new analysis is needed, this function will create and
23 save a MasterFlakeAnalysis entity to the datastore. 20 save a MasterFlakeAnalysis entity to the datastore. TODO(lijeffrey): add
21 support for a force flag to rerun this analysis.
chanli 2016/09/27 22:15:24 Nit: Maybe move this TODO to a separate line?
lijeffrey 2016/09/28 03:12:31 Done.
24 22
25 Returns: 23 Returns:
26 True if an analysis is needed, otherwise False. 24 True if an analysis is needed, otherwise False.
27 """ 25 """
28 master_flake_analysis = MasterFlakeAnalysis.Get( 26 master_flake_analysis = MasterFlakeAnalysis.GetVersion(
29 master_name, builder_name, build_number, step_name, test_name) 27 master_name, builder_name, build_number, step_name, test_name)
30 28
31 if not master_flake_analysis: 29 if not master_flake_analysis:
32 if not allow_new_analysis: 30 if not allow_new_analysis:
33 return False 31 return False
34 master_flake_analysis = MasterFlakeAnalysis.Create( 32 master_flake_analysis = MasterFlakeAnalysis.Create(
35 master_name, builder_name, build_number, step_name, test_name) 33 master_name, builder_name, build_number, step_name, test_name)
36 master_flake_analysis.status = analysis_status.PENDING 34 master_flake_analysis.Reset()
stgao 2016/09/28 00:03:24 Why do we need reset here?
lijeffrey 2016/09/28 03:12:31 We need to clear the fields, especially swarming_r
stgao 2016/09/30 21:07:31 But it is newly created, there is no leftover stat
lijeffrey 2016/10/01 01:28:04 Ah yes you are correct, I was looking at the wrong
37 master_flake_analysis.put() 35 _, saved = master_flake_analysis.Save()
38 return True 36 if saved:
stgao 2016/09/28 00:03:24 Can we just return saved directly?
lijeffrey 2016/09/28 03:12:31 Done.
37 return True
38 else: # pragma: no cover.
39 # Another transaction has just triggered tihs analysis. TODO(lijeffrey):
40 # Indicate to the user to wait for the other analysis' results amd remove
41 # the no cover pragma.
chanli 2016/09/27 22:15:24 Same here
lijeffrey 2016/09/28 03:12:31 Done.
42 return False
39 elif (master_flake_analysis.status == analysis_status.COMPLETED or 43 elif (master_flake_analysis.status == analysis_status.COMPLETED or
40 master_flake_analysis.status == analysis_status.PENDING or 44 master_flake_analysis.status == analysis_status.PENDING or
41 master_flake_analysis.status == analysis_status.RUNNING): 45 master_flake_analysis.status == analysis_status.RUNNING):
42 return False 46 return False
43 else: 47 else:
44 # TODO(caiw): Reset method. 48 # The previous analysis had some error, so reset it and create a new one.
45 MasterFlakeAnalysis.Get( 49 master_flake_analysis.Reset()
46 master_name, builder_name, build_number, 50 _, saved = master_flake_analysis.Save()
47 step_name, test_name).key.delete() 51 if saved: # pragma: no branch
stgao 2016/09/28 00:03:24 same here.
lijeffrey 2016/10/01 01:28:04 Done.
48 master_flake_analysis = MasterFlakeAnalysis.Create( 52 return True
49 master_name, builder_name, build_number, step_name, test_name) 53 else: # pragma: no cover.
50 master_flake_analysis.status = analysis_status.PENDING 54 # Another transaction has just triggered tihs analysis. TODO(lijeffrey):
51 master_flake_analysis.put() 55 # Indicate to the user to wait for the other analysis' results amd remove
52 return True 56 # the no cover pragma.
57 return False
53 58
54 59
55 # Unused arguments - pylint: disable=W0612, W0613 60 # Unused arguments - pylint: disable=W0612, W0613
56 def ScheduleAnalysisIfNeeded(master_name, builder_name, build_number, step_name, 61 def ScheduleAnalysisIfNeeded(master_name, builder_name, build_number, step_name,
57 test_name, allow_new_analysis=False, force=False, 62 test_name, allow_new_analysis=False, force=False,
58 queue_name=constants.DEFAULT_QUEUE): 63 queue_name=constants.DEFAULT_QUEUE):
59 """Schedules an analysis if needed and returns the MasterFlakeAnalysis. 64 """Schedules an analysis if needed and returns the MasterFlakeAnalysis.
60 65
61 When the build failure was already analyzed and a new analysis is scheduled, 66 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. 67 the returned WfAnalysis will still have the result of last completed analysis.
63 68
64 Args: 69 Args:
65 master_name (str): The master name of the failed test 70 master_name (str): The master name of the failed test
66 builder_name (str): The builder name of the failed test 71 builder_name (str): The builder name of the failed test
67 build_number (int): The build number of the failed test 72 build_number (int): The build number of the failed test
68 step_name (str): The name of the test suite 73 step_name (str): The name of the test suite
69 test_name (str): The single test we are checking 74 test_name (str): The single test we are checking
70 allow_new_analysis (bool): Indicate whether a new analysis is allowed. 75 allow_new_analysis (bool): Indicate whether a new analysis is allowed.
71 force (bool): Indicate whether to force a rerun of current analysis. 76 force (bool): Indicate whether to force a rerun of current analysis.
72 queue_name (str): The App Engine queue to run the analysis. 77 queue_name (str): The App Engine queue to run the analysis.
73 78
74 Returns: 79 Returns:
75 A MasterFlakeAnalysis instance. 80 A MasterFlakeAnalysis instance.
76 None if no analysis was scheduled and the user has no permission to. 81 None if no analysis was scheduled and the user has no permission to.
77 """ 82 """
78 if NeedANewAnalysis( 83 if NeedANewAnalysis(
79 master_name, builder_name, build_number, step_name, test_name, 84 master_name, builder_name, build_number, step_name, test_name,
80 allow_new_analysis): 85 allow_new_analysis):
86 master_flake_analysis = MasterFlakeAnalysis.GetVersion(
87 master_name, builder_name, build_number, step_name, test_name)
81 check_flake_settings = waterfall_config.GetCheckFlakeSettings() 88 check_flake_settings = waterfall_config.GetCheckFlakeSettings()
89
90 # TODO(lijeffrey): Allow for reruns with custom parameters if the user is
91 # not satisfied with with the results generated by the default ones provided
stgao 2016/09/28 00:03:24 typo: with with
lijeffrey 2016/09/28 03:12:31 Done.
92 # by waterfall_config and record the custom ones here.
93 master_flake_analysis.algorithm_parameters = check_flake_settings
94 master_flake_analysis.put()
95
82 max_build_numbers_to_look_back = check_flake_settings.get( 96 max_build_numbers_to_look_back = check_flake_settings.get(
83 'max_build_numbers_to_look_back') 97 'max_build_numbers_to_look_back')
84 flakiness_algorithm_results_dict = { 98 flakiness_algorithm_results_dict = {
85 'flakes_in_a_row': 0, 99 'flakes_in_a_row': 0,
86 'stable_in_a_row': 0, 100 'stable_in_a_row': 0,
87 'stabled_out': False, 101 'stabled_out': False,
88 'flaked_out': False, 102 'flaked_out': False,
89 'last_build_number': max( 103 'last_build_number': max(
90 0, build_number - max_build_numbers_to_look_back), 104 0, build_number - max_build_numbers_to_look_back),
91 'lower_boundary': None, 105 'lower_boundary': None,
92 'upper_boundary': None, 106 'upper_boundary': None,
93 'lower_boundary_result': None, 107 'lower_boundary_result': None,
94 'sequential_run_index': 0 108 'sequential_run_index': 0
95 } 109 }
110
96 pipeline_job = RecursiveFlakePipeline( 111 pipeline_job = RecursiveFlakePipeline(
97 master_name, builder_name, build_number, step_name, test_name, 112 master_name, builder_name, build_number, step_name, test_name,
stgao 2016/09/28 00:03:24 Should we pass the version of the master_flake_ana
lijeffrey 2016/09/28 03:12:31 I think this is a good idea. Originally the design
stgao 2016/09/30 21:07:31 I'm against running two concurrent analysis for th
lijeffrey 2016/10/01 01:28:04 NeedANewAnalysis as is does not support running 2
98 master_build_number=build_number, 113 master_build_number=build_number,
99 flakiness_algorithm_results_dict=flakiness_algorithm_results_dict) 114 flakiness_algorithm_results_dict=flakiness_algorithm_results_dict)
100 pipeline_job.target = appengine_util.GetTargetNameForModule( 115 pipeline_job.target = appengine_util.GetTargetNameForModule(
101 constants.WATERFALL_BACKEND) 116 constants.WATERFALL_BACKEND)
102 pipeline_job.start(queue_name=queue_name) 117 pipeline_job.start(queue_name=queue_name)
103 return MasterFlakeAnalysis.Get( 118 return MasterFlakeAnalysis.GetVersion(
104 master_name, builder_name, build_number, step_name, test_name) 119 master_name, builder_name, build_number, step_name, test_name)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698