OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """Log status events to a file on disk or event collection endpoint.""" | 5 """Log status events to a file on disk or event collection endpoint.""" |
6 | 6 |
7 | 7 |
8 import json | 8 import json |
9 import logging | 9 import logging |
10 import logging.handlers | 10 import logging.handlers |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 '/ ts_mon_logging: %s' % ( | 176 '/ ts_mon_logging: %s' % ( |
177 self._logging, self._event_logging, self._ts_mon_logging)) | 177 self._logging, self._event_logging, self._ts_mon_logging)) |
178 else: | 178 else: |
179 self._configure({'file_logging': False, | 179 self._configure({'file_logging': False, |
180 'event_logging': False, | 180 'event_logging': False, |
181 'ts_mon_logging': False}) # Reset to defaults. | 181 'ts_mon_logging': False}) # Reset to defaults. |
182 | 182 |
183 self._last_checked_active = now | 183 self._last_checked_active = now |
184 return self._active | 184 return self._active |
185 | 185 |
186 | |
187 def send_build_result( | 186 def send_build_result( |
188 self, scheduled, started, finished, builder_name, bot_name, result, | 187 self, scheduled, started, finished, builder_name, bot_name, result, |
189 project_id=None, subproject_tag=None, steps=None, pre_test_time_s=None): | 188 project_id=None, subproject_tag=None, steps=None, pre_test_time_s=None): |
190 """Log a build result for ts_mon. | 189 """Log a build result for ts_mon. |
191 | 190 |
192 This allows computing metrics for builds in mastermon. | 191 This allows computing metrics for builds in mastermon. |
193 """ | 192 """ |
194 d = { | 193 d = { |
195 'timestamp_ms': finished * 1000, | 194 'timestamp_ms': finished * 1000, |
196 'builder': builder_name, | 195 'builder': builder_name, |
197 'slave': bot_name, | 196 'slave': bot_name, |
198 'result': result.lower(), | 197 'result': result.lower(), |
199 'duration_s': finished - started, | 198 'duration_s': finished - started, |
200 'pending_s': started - scheduled, | 199 'pending_s': started - scheduled, |
201 'total_s': finished - scheduled, | 200 'total_s': finished - scheduled, |
202 } | 201 } |
203 if project_id: | 202 if project_id: |
204 d['project_id'] = project_id | 203 d['project_id'] = project_id |
205 if subproject_tag: | 204 if subproject_tag: |
206 d['subproject_tag'] = subproject_tag | 205 d['subproject_tag'] = subproject_tag |
207 if steps: | 206 if steps: |
208 d['steps'] = steps | 207 d['steps'] = steps |
209 if pre_test_time_s is not None: | 208 if pre_test_time_s is not None: |
210 d['pre_test_time_s'] = pre_test_time_s | 209 d['pre_test_time_s'] = pre_test_time_s |
211 self.ts_mon_logger.info(json.dumps(d)) | 210 self.ts_mon_logger.info(json.dumps(d)) |
212 | 211 |
212 def send_step_results( | |
213 self, timestamp, builder_name, bot_name, | |
214 step_result, project_id, subproject_tag): | |
215 """Log step results for ts_mon | |
216 | |
217 Args: | |
218 timestamp(int): when the event was generated (end of a step). Seconds | |
219 since the Unix epoch. | |
220 builder_name(str): name of the builder the steps are part of. | |
221 bot_name(str): name of the machine running the build. | |
222 step_result (str): result for this step. | |
223 project_id(str): 'project' as shown on the codereview. | |
224 subproject_tag(str): a mention of a subproject. Mostly used to distinguish | |
225 between chromium and blink CLs in the chromium project. | |
226 """ | |
227 # the presence of the field 'step_result' is how the collecting daemon | |
Sergey Berezin
2016/04/11 23:49:48
nit: Capitalize the first word.
| |
228 # tells the difference between this case and the one from send_build_result. | |
229 d = { | |
230 'timestamp': timestamp, | |
231 'builder': builder_name, | |
232 'step_result': step_result, | |
233 'slave': bot_name, | |
234 'project_id': project_id, | |
235 'subproject_tag': subproject_tag, | |
236 } | |
237 self.ts_mon_logger.info(json.dumps(d)) | |
238 | |
239 | |
213 def send_build_event(self, timestamp_kind, timestamp, build_event_type, | 240 def send_build_event(self, timestamp_kind, timestamp, build_event_type, |
214 bot_name, builder_name, build_number, build_scheduled_ts, | 241 bot_name, builder_name, build_number, build_scheduled_ts, |
215 step_name=None, step_number=None, result=None, | 242 step_name=None, step_number=None, result=None, |
216 extra_result_code=None, patch_url=None): | 243 extra_result_code=None, patch_url=None): |
217 """Log a build/step event for event_mon.""" | 244 """Log a build/step event for event_mon.""" |
218 | 245 |
219 if self.active and self._event_logging: | 246 if self.active and self._event_logging: |
220 # List options to pass to send_monitoring_event, without the --, to save | 247 # List options to pass to send_monitoring_event, without the --, to save |
221 # a bit of space. | 248 # a bit of space. |
222 d = {'event-mon-timestamp-kind': timestamp_kind, | 249 d = {'event-mon-timestamp-kind': timestamp_kind, |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 self.log('stepFinished', '%s, %d, %s, %r', | 510 self.log('stepFinished', '%s, %d, %s, %r', |
484 builder_name, build_number, step_name, results) | 511 builder_name, build_number, step_name, results) |
485 _, finished = step.getTimes() | 512 _, finished = step.getTimes() |
486 self.send_build_event( | 513 self.send_build_event( |
487 'END', finished * 1000, 'STEP', bot, builder_name, build_number, | 514 'END', finished * 1000, 'STEP', bot, builder_name, build_number, |
488 self._get_requested_at_millis(build), | 515 self._get_requested_at_millis(build), |
489 step_name=step_name, step_number=step.step_number, | 516 step_name=step_name, step_number=step.step_number, |
490 result=buildbot.status.results.Results[results[0]], | 517 result=buildbot.status.results.Results[results[0]], |
491 patch_url=self._get_patch_url(build.getProperties())) | 518 patch_url=self._get_patch_url(build.getProperties())) |
492 | 519 |
520 # Send step result to ts-mon | |
521 properties = build.getProperties() | |
522 project_id = properties.getProperty('patch_project') | |
523 subproject_tag = properties.getProperty('subproject_tag') | |
524 | |
525 self.send_step_results( | |
526 finished, | |
527 builder_name, | |
528 bot, | |
529 buildbot.status.results.Results[step.getResults()[0]], | |
530 project_id, | |
531 subproject_tag) | |
532 | |
493 def buildFinished(self, builderName, build, results): | 533 def buildFinished(self, builderName, build, results): |
494 build_number = build.getNumber() | 534 build_number = build.getNumber() |
495 bot = build.getSlavename() | 535 bot = build.getSlavename() |
496 self.log('buildFinished', '%s, %d, %s, %r', | 536 self.log('buildFinished', '%s, %d, %s, %r', |
497 builderName, build_number, bot, results) | 537 builderName, build_number, bot, results) |
498 started, finished = build.getTimes() | 538 started, finished = build.getTimes() |
499 | 539 |
500 # Calculate when build was scheduled if possible. Use build started | 540 # Calculate when build was scheduled if possible. Use build started |
501 # timestamp as initial approximation. | 541 # timestamp as initial approximation. |
502 scheduled = started | 542 scheduled = started |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 pre_test_time_s=pre_test_time_s) | 589 pre_test_time_s=pre_test_time_s) |
550 | 590 |
551 def builderRemoved(self, builderName): | 591 def builderRemoved(self, builderName): |
552 self.log('builderRemoved', '%s', builderName) | 592 self.log('builderRemoved', '%s', builderName) |
553 | 593 |
554 def slaveConnected(self, slaveName): | 594 def slaveConnected(self, slaveName): |
555 self.log('slaveConnected', '%s', slaveName) | 595 self.log('slaveConnected', '%s', slaveName) |
556 | 596 |
557 def slaveDisconnected(self, slaveName): | 597 def slaveDisconnected(self, slaveName): |
558 self.log('slaveDisconnected', '%s', slaveName) | 598 self.log('slaveDisconnected', '%s', slaveName) |
OLD | NEW |