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

Side by Side Diff: appengine/findit/waterfall/process_base_swarming_task_result_pipeline.py

Issue 2130543004: Waterfall components of regression range finder. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: cleanup Created 4 years, 5 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 collections import defaultdict 5 from collections import defaultdict
6 import datetime 6 import datetime
7 import logging 7 import logging
8 import time 8 import time
9 9
10 from common.http_client_appengine import HttpClientAppengine as HttpClient 10 from common.http_client_appengine import HttpClientAppengine as HttpClient
11 from common.pipeline_wrapper import BasePipeline 11 from common.pipeline_wrapper import BasePipeline
12 from model import analysis_status 12 from model import analysis_status
13 from model.wf_swarming_task import WfSwarmingTask 13 from model.wf_swarming_task import WfSwarmingTask
14 from waterfall import swarming_util 14 from waterfall import swarming_util
15 from waterfall import waterfall_config 15 from waterfall import waterfall_config
16 16
17 17
18 def _CheckTestsRunStatuses(output_json): 18 class ProcessBaseSwarmingTaskResultPipeline(BasePipeline):
19 """Checks result status for each test run and saves the numbers accordingly.
20
21 Args:
22 output_json (dict): A dict of all test results in the swarming task.
23
24 Returns:
25 tests_statuses (dict): A dict of different statuses for each test.
26
27 Currently for each test, we are saving number of total runs,
28 number of succeeded runs and number of failed runs.
29 """
30 tests_statuses = defaultdict(lambda: defaultdict(int))
31 if output_json:
32 for iteration in output_json.get('per_iteration_data'):
33 for test_name, tests in iteration.iteritems():
34 tests_statuses[test_name]['total_run'] += len(tests)
35 for test in tests:
36 tests_statuses[test_name][test['status']] += 1
37
38 return tests_statuses
39
40
41 def _ConvertDateTime(time_string):
42 """Convert UTC time string to datetime.datetime."""
43 # Match the time convertion with swarming.py.
44 # According to swarming.py,
45 # when microseconds are 0, the '.123456' suffix is elided.
46 if not time_string:
47 return None
48 for fmt in ('%Y-%m-%dT%H:%M:%S.%f', '%Y-%m-%dT%H:%M:%S'):
49 try:
50 return datetime.datetime.strptime(time_string, fmt)
51 except ValueError:
52 pass
53 raise ValueError('Failed to parse %s' % time_string) # pragma: no cover
54
55
56 class ProcessSwarmingTaskResultPipeline(BasePipeline):
57 """A pipeline for monitoring swarming task and processing task result. 19 """A pipeline for monitoring swarming task and processing task result.
58 20
59 This pipeline waits for result for a swarming task and processes the result to 21 This pipeline waits for result for a swarming task and processes the result to
60 generate a dict for statuses for each test run. 22 generate a dict for statuses for each test run.
61 """ 23 """
62 24
63 HTTP_CLIENT = HttpClient() 25 HTTP_CLIENT = HttpClient()
26
27 def _CheckTestsRunStatuses(self, output_json):
chanli 2016/07/19 20:48:28 It seems this method will be overridden? 'raise No
28 """Checks result status for each test run and saves the numbers accordingly.
29
30 Args:
31 output_json (dict): A dict of all test results in the swarming task.
32
33 Returns:
34 tests_statuses (dict): A dict of different statuses for each test.
35
36 Currently for each test, we are saving number of total runs,
37 number of succeeded runs and number of failed runs.
38 """
39 tests_statuses = defaultdict(lambda: defaultdict(int))
40 if output_json:
41 for iteration in output_json.get('per_iteration_data'):
42 for test_name, tests in iteration.iteritems():
43 tests_statuses[test_name]['total_run'] += len(tests)
44 for test in tests:
45 tests_statuses[test_name][test['status']] += 1
46 return tests_statuses
47
48 def _ConvertDateTime(self, time_string):
49 """Convert UTC time string to datetime.datetime."""
50 # Match the time convertion with swarming.py.
51 # According to swarming.py,
52 # when microseconds are 0, the '.123456' suffix is elided.
53 if not time_string:
54 return None
55 for fmt in ('%Y-%m-%dT%H:%M:%S.%f', '%Y-%m-%dT%H:%M:%S'):
56 try:
57 return datetime.datetime.strptime(time_string, fmt)
58 except ValueError:
59 pass
60 raise ValueError('Failed to parse %s' % time_string) # pragma: no cover
61
62 def _GetSwarmingTask(self):
63 # Get the appropriate kind of Swarming Task (Wf or Flake)
64 # Should be overwritten by subclass
65 raise NotImplementedError
66
67 def _GetArgs(self):
68 # Return list of arguments to call _CheckTestsRunStatuses with - output_json
69 # Should be overwritten by subclass.
70 raise NotImplementedError
71
64 # Arguments number differs from overridden method - pylint: disable=W0221 72 # Arguments number differs from overridden method - pylint: disable=W0221
65 def run(self, master_name, builder_name, build_number, step_name, task_id): 73 def run(self, master_name, builder_name, build_number,
74 step_name, task_id, *args):
66 """ 75 """
67 Args: 76 Args:
68 master_name (str): The master name. 77 master_name (str): The master name.
69 builder_name (str): The builder name. 78 builder_name (str): The builder name.
70 build_number (str): The build number. 79 build_number (str): The build number.
71 step_name (str): The failed test step name. 80 step_name (str): The failed test step name.
72 task_id (str): Id for the swarming task which is triggered by Findit. 81 task_id (str): Id for the swarming task which is triggered by Findit.
73 82
74 Returns: 83 Returns:
75 A dict of lists for reliable/flaky tests. 84 A dict of lists for reliable/flaky tests.
76 """ 85 """
77 86 call_args = self._GetArgs(master_name, builder_name, build_number,
87 step_name, *args)
78 assert task_id 88 assert task_id
79 timeout_hours = waterfall_config.GetSwarmingSettings().get( 89 timeout_hours = waterfall_config.GetSwarmingSettings().get(
80 'task_timeout_hours') 90 'task_timeout_hours')
81 deadline = time.time() + timeout_hours * 60 * 60 91 deadline = time.time() + timeout_hours * 60 * 60
82 server_query_interval_seconds = waterfall_config.GetSwarmingSettings().get( 92 server_query_interval_seconds = waterfall_config.GetSwarmingSettings().get(
83 'server_query_interval_seconds') 93 'server_query_interval_seconds')
84
85 task_started = False 94 task_started = False
86 task_completed = False 95 task_completed = False
87 tests_statuses = {} 96 tests_statuses = {}
88 step_name_no_platform = None 97 step_name_no_platform = None
89 98
90 while not task_completed: 99 while not task_completed:
91 # Keeps monitoring the swarming task, waits for it to complete. 100 # Keeps monitoring the swarming task, waits for it to complete.
92 data = swarming_util.GetSwarmingTaskResultById( 101 data = swarming_util.GetSwarmingTaskResultById(
93 task_id, self.HTTP_CLIENT) 102 task_id, self.HTTP_CLIENT)
94 task_state = data['state'] 103 task_state = data['state']
95 step_name_no_platform = swarming_util.GetTagValue( 104 step_name_no_platform = swarming_util.GetTagValue(
96 data.get('tags', {}), 'ref_name') 105 data.get('tags', {}), 'ref_name')
97 if task_state not in swarming_util.STATES_RUNNING: 106 if task_state not in swarming_util.STATES_RUNNING:
98 task_completed = True 107 task_completed = True
99 task = WfSwarmingTask.Get( 108 task = self._GetSwarmingTask(*call_args)
100 master_name, builder_name, build_number, step_name)
101 if task_state == swarming_util.STATE_COMPLETED: 109 if task_state == swarming_util.STATE_COMPLETED:
102 outputs_ref = data.get('outputs_ref') 110 outputs_ref = data.get('outputs_ref')
103 output_json = swarming_util.GetSwarmingTaskFailureLog( 111 output_json = swarming_util.GetSwarmingTaskFailureLog(
104 outputs_ref, self.HTTP_CLIENT) 112 outputs_ref, self.HTTP_CLIENT)
105 tests_statuses = _CheckTestsRunStatuses(output_json) 113 # This following line will not be compatible!
106 114 tests_statuses = self._CheckTestsRunStatuses(
115 output_json, *call_args)
107 task.status = analysis_status.COMPLETED 116 task.status = analysis_status.COMPLETED
108 task.tests_statuses = tests_statuses 117 task.tests_statuses = tests_statuses
109 else: 118 else:
110 task.status = analysis_status.ERROR 119 task.status = analysis_status.ERROR
111 logging.error('Swarming task stopped with status: %s' % ( 120 logging.error('Swarming task stopped with status: %s' % (
112 task_state)) 121 task_state))
113 priority_str = swarming_util.GetTagValue( 122 priority_str = swarming_util.GetTagValue(
114 data.get('tags', {}), 'priority') 123 data.get('tags', {}), 'priority')
115 if priority_str: 124 if priority_str:
116 task.parameters['priority'] = int(priority_str) 125 task.parameters['priority'] = int(priority_str)
117 task.put() 126 task.put()
118 else: # pragma: no cover 127 else: # pragma: no cover
119 if task_state == 'RUNNING' and not task_started: 128 if task_state == 'RUNNING' and not task_started:
120 # swarming task just starts, update status. 129 # swarming task just starts, update status.
121 task_started = True 130 task_started = True
122 task = WfSwarmingTask.Get( 131 task = self._GetSwarmingTask(*call_args)
123 master_name, builder_name, build_number, step_name)
124 task.status = analysis_status.RUNNING 132 task.status = analysis_status.RUNNING
125 task.put() 133 task.put()
126
127 time.sleep(server_query_interval_seconds) 134 time.sleep(server_query_interval_seconds)
128
129 if time.time() > deadline: 135 if time.time() > deadline:
130 # Updates status as ERROR. 136 # Updates status as ERROR.
131 task = WfSwarmingTask.Get( 137 task = self._GetSwarmingTask(*call_args)
132 master_name, builder_name, build_number, step_name)
133 task.status = analysis_status.ERROR 138 task.status = analysis_status.ERROR
134 task.put() 139 task.put()
135 logging.error('Swarming task timed out after %d hours.' % timeout_hours) 140 logging.error('Swarming task timed out after %d hours.' % timeout_hours)
136 break # Stops the loop and return. 141 break # Stops the loop and return.
137
138 # Update swarming task metadate. 142 # Update swarming task metadate.
139 task = WfSwarmingTask.Get( 143 task = self._GetSwarmingTask(*call_args)
140 master_name, builder_name, build_number, step_name) 144 task.created_time = self._ConvertDateTime(data.get('created_ts'))
141 task.created_time = _ConvertDateTime(data.get('created_ts')) 145 task.started_time = self._ConvertDateTime(data.get('started_ts'))
142 task.started_time = _ConvertDateTime(data.get('started_ts')) 146 task.completed_time = self._ConvertDateTime(data.get('completed_ts'))
143 task.completed_time = _ConvertDateTime(data.get('completed_ts'))
144 task.put() 147 task.put()
145 148
146 return step_name, (step_name_no_platform, task.classified_tests) 149 return step_name, step_name_no_platform
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698