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

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

Issue 2243673002: [Findit] Added algorithm to analysis (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: addressed comments Created 4 years, 4 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 datetime import datetime 5 from datetime import datetime
6 6
7 from google.appengine.ext import ndb 7 from google.appengine.ext import ndb
8 8
9 from common import appengine_util 9 from common import appengine_util
10 from common import constants 10 from common import constants
11 from model import analysis_status 11 from model import analysis_status
12 from model.flake.flake_swarming_task import FlakeSwarmingTask
13 from model.flake.master_flake_analysis import MasterFlakeAnalysis 12 from model.flake.master_flake_analysis import MasterFlakeAnalysis
14 from waterfall.flake.recursive_flake_pipeline import RecursiveFlakePipeline 13 from waterfall.flake.recursive_flake_pipeline import RecursiveFlakePipeline
15 14
15 # TODO(lijeffrey): Move to config.
16 BUILD_NUMBERS_BACK = 1000
lijeffrey 2016/08/15 04:14:07 nit: Rename this MAX_BUILD_NUMBERS_TO_LOOK_BACK or
caiw 2016/08/17 08:36:18 Done.
17
16 18
17 @ndb.transactional 19 @ndb.transactional
18 def NeedANewAnalysis( 20 def NeedANewAnalysis(
19 master_name, builder_name, build_number, step_name, test_name): 21 master_name, builder_name, build_number, step_name, test_name):
20 """Checks status of analysis for the test and decides if a new one is needed. 22 """Checks status of analysis for the test and decides if a new one is needed.
21 23
22 A MasterFlakeAnalysis entity for the given parameters will be created if none 24 A MasterFlakeAnalysis entity for the given parameters will be created if none
23 exists. When a new analysis is needed, this function will create and 25 exists. When a new analysis is needed, this function will create and
24 save a MasterFlakeAnalysis entity to the datastore. 26 save a MasterFlakeAnalysis entity to the datastore.
25 27
26 Returns: 28 Returns:
27 True if an analysis is needed, otherwise False. 29 True if an analysis is needed, otherwise False.
28 """ 30 """
29 master_flake_analysis = MasterFlakeAnalysis.Get( 31 master_flake_analysis = MasterFlakeAnalysis.Get(
30 master_name, builder_name, build_number,step_name, test_name) 32 master_name, builder_name, build_number, step_name, test_name)
31 33
32 if not master_flake_analysis: 34 if not master_flake_analysis:
33 master_flake_analysis = MasterFlakeAnalysis.Create( 35 master_flake_analysis = MasterFlakeAnalysis.Create(
34 master_name, builder_name, build_number, step_name, test_name) 36 master_name, builder_name, build_number, step_name, test_name)
35 master_flake_analysis.status = analysis_status.PENDING 37 master_flake_analysis.status = analysis_status.PENDING
36 master_flake_analysis.put() 38 master_flake_analysis.put()
37 return True 39 return True
38 elif (master_flake_analysis.status == analysis_status.COMPLETED or 40 elif (master_flake_analysis.status == analysis_status.COMPLETED or
39 master_flake_analysis.status == analysis_status.PENDING or 41 master_flake_analysis.status == analysis_status.PENDING or
40 master_flake_analysis.status == analysis_status.RUNNING): 42 master_flake_analysis.status == analysis_status.RUNNING):
41 return False 43 return False
42 else: 44 else:
43 # TODO(caiw): Reset method. 45 # TODO(caiw): Reset method.
44 MasterFlakeAnalysis.Get( 46 MasterFlakeAnalysis.Get(
45 master_name, builder_name, build_number, 47 master_name, builder_name, build_number,
46 step_name, test_name).key.delete() 48 step_name, test_name).key.delete()
47 master_flake_analysis = MasterFlakeAnalysis.Create( 49 master_flake_analysis = MasterFlakeAnalysis.Create(
48 master_name, builder_name, build_number, step_name, test_name) 50 master_name, builder_name, build_number, step_name, test_name)
49 master_flake_analysis.status = analysis_status.PENDING 51 master_flake_analysis.status = analysis_status.PENDING
50 master_flake_analysis.put() 52 master_flake_analysis.put()
51 return True 53 return True
52 54
55
53 # Unused arguments - pylint: disable=W0612, W0613 56 # Unused arguments - pylint: disable=W0612, W0613
54 def ScheduleAnalysisIfNeeded(master_name, builder_name, build_number, step_name, 57 def ScheduleAnalysisIfNeeded(master_name, builder_name, build_number, step_name,
55 test_name, force=False, 58 test_name, force=False,
56 queue_name=constants.DEFAULT_QUEUE): 59 queue_name=constants.DEFAULT_QUEUE):
57 """Schedules an analysis if needed and returns the MasterFlakeAnalysis. 60 """Schedules an analysis if needed and returns the MasterFlakeAnalysis.
58 61
59 When the build failure was already analyzed and a new analysis is scheduled, 62 When the build failure was already analyzed and a new analysis is scheduled,
60 the returned WfAnalysis will still have the result of last completed analysis. 63 the returned WfAnalysis will still have the result of last completed analysis.
61 64
62 Args: 65 Args:
63 master_name (str): The master name of the failed test 66 master_name (str): The master name of the failed test
64 builder_name (str): The builder name of the failed test 67 builder_name (str): The builder name of the failed test
65 build_number (int): The build number of the failed test 68 build_number (int): The build number of the failed test
66 step_name (str): The name of the test suite 69 step_name (str): The name of the test suite
67 test_name (str): The single test we are checking 70 test_name (str): The single test we are checking
68 71
69 Returns: 72 Returns:
70 A MasterFlakeAnalysis instance. 73 A MasterFlakeAnalysis instance.
71 """ 74 """
72 if NeedANewAnalysis( 75 if NeedANewAnalysis(
73 master_name, builder_name, build_number, step_name, test_name): 76 master_name, builder_name, build_number, step_name, test_name):
77 algo_dict = {
lijeffrey 2016/08/15 04:14:07 nit: In general avoid abbreviating variable names
caiw 2016/08/17 08:36:18 Done.
78 'flakes_in_a_row': 0,
79 'stable_in_a_row': 0,
80 'stabled_out': False,
81 'flaked_out': False,
82 'last_build_number': max(0, build_number - BUILD_NUMBERS_BACK)
83 }
74 pipeline_job = RecursiveFlakePipeline( 84 pipeline_job = RecursiveFlakePipeline(
75 master_name, builder_name, build_number, step_name, test_name, 85 master_name, builder_name, build_number, step_name, test_name,
76 master_build_number=build_number) 86 master_build_number=build_number, algo_dict=algo_dict)
77 pipeline_job.target = appengine_util.GetTargetNameForModule( 87 pipeline_job.target = appengine_util.GetTargetNameForModule(
78 constants.WATERFALL_BACKEND) 88 constants.WATERFALL_BACKEND)
79 pipeline_job.start(queue_name=queue_name) 89 pipeline_job.start(queue_name=queue_name)
80 return MasterFlakeAnalysis.Get( 90 return MasterFlakeAnalysis.Get(
81 master_name, builder_name, build_number, step_name, test_name) 91 master_name, builder_name, build_number, step_name, test_name)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698