OLD | NEW |
---|---|
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 import logging | 5 import logging |
6 | 6 |
7 from google.protobuf.message import DecodeError | 7 from google.protobuf.message import DecodeError |
8 from infra_libs.event_mon.protos.chrome_infra_log_pb2 import ( | 8 from infra_libs.event_mon.protos.chrome_infra_log_pb2 import ( |
9 ChromeInfraEvent, ServiceEvent, BuildEvent) | 9 ChromeInfraEvent, ServiceEvent, BuildEvent) |
10 from infra_libs.event_mon.protos.goma_stats_pb2 import GomaStats | 10 from infra_libs.event_mon.protos.goma_stats_pb2 import GomaStats |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 step_number=None, | 265 step_number=None, |
266 result=None, | 266 result=None, |
267 extra_result_code=None, | 267 extra_result_code=None, |
268 timestamp_kind=None, | 268 timestamp_kind=None, |
269 event_timestamp=None, | 269 event_timestamp=None, |
270 service_name=None, | 270 service_name=None, |
271 goma_stats=None, | 271 goma_stats=None, |
272 goma_error=None, | 272 goma_error=None, |
273 goma_crash_report_id=None, | 273 goma_crash_report_id=None, |
274 patch_url=None, | 274 patch_url=None, |
275 bbucket_id=None): | 275 bbucket_id=None, |
276 category=None): | |
276 """Compute a ChromeInfraEvent filled with a BuildEvent. | 277 """Compute a ChromeInfraEvent filled with a BuildEvent. |
277 | 278 |
278 Arguments are identical to those in send_build_event(), please refer | 279 Arguments are identical to those in send_build_event(), please refer |
279 to this docstring. | 280 to this docstring. |
280 | 281 |
281 Returns: | 282 Returns: |
282 event (log_request_lite_pb2.LogRequestLite.LogEventLite): can be None | 283 event (log_request_lite_pb2.LogRequestLite.LogEventLite): can be None |
283 if there is a major processing issue. | 284 if there is a major processing issue. |
284 """ | 285 """ |
285 if event_type not in BUILD_EVENT_TYPES: | 286 if event_type not in BUILD_EVENT_TYPES: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 if step_number is not None: | 339 if step_number is not None: |
339 event.build_event.step_number = step_number | 340 event.build_event.step_number = step_number |
340 if patch_url is not None: | 341 if patch_url is not None: |
341 event.build_event.patch_url = patch_url | 342 event.build_event.patch_url = patch_url |
342 if bbucket_id is not None: | 343 if bbucket_id is not None: |
343 try: | 344 try: |
344 event.build_event.bbucket_id = int(bbucket_id) | 345 event.build_event.bbucket_id = int(bbucket_id) |
345 except (ValueError, TypeError): | 346 except (ValueError, TypeError): |
346 pass | 347 pass |
347 | 348 |
349 if category: | |
Sergey Berezin (google)
2016/06/30 02:07:53
nit: as an option, you can write this as:
categ
Sergiy Byelozyorov
2016/07/06 08:55:30
Thanks. I've made it even shorter.
| |
350 if category.lower() == 'cq': | |
351 event.build_event.category = BuildEvent.CATEGORY_CQ | |
352 elif category.lower() == 'cq_experimental': | |
353 event.build_event.category = BuildEvent.CATEGORY_CQ_EXPERIMENTAL | |
354 elif category.lower() == 'git_cl_try': | |
355 event.build_event.category = BuildEvent.CATEGORY_GIT_CL_TRY | |
356 else: | |
357 event.build_event.category = BuildEvent.CATEGORY_UNKNOWN | |
358 | |
348 if event.build_event.step_name: | 359 if event.build_event.step_name: |
349 if event_type != 'STEP': | 360 if event_type != 'STEP': |
350 logging.error('step_name should be provided only for type "STEP", ' | 361 logging.error('step_name should be provided only for type "STEP", ' |
351 'got %s', event_type) | 362 'got %s', event_type) |
352 if not event.build_event.HasField('step_number'): | 363 if not event.build_event.HasField('step_number'): |
353 logging.error('step_number was not provided, but got a value for ' | 364 logging.error('step_number was not provided, but got a value for ' |
354 'step_name (%s). Provide either both or none', | 365 'step_name (%s). Provide either both or none', |
355 step_name) | 366 step_name) |
356 if (not event.build_event.HasField('build_number') | 367 if (not event.build_event.HasField('build_number') |
357 and not event.build_event.HasField('build_scheduling_time_ms')): | 368 and not event.build_event.HasField('build_scheduling_time_ms')): |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 step_text=None, | 443 step_text=None, |
433 step_number=None, | 444 step_number=None, |
434 result=None, | 445 result=None, |
435 extra_result_code=None, | 446 extra_result_code=None, |
436 timestamp_kind=None, | 447 timestamp_kind=None, |
437 event_timestamp=None, | 448 event_timestamp=None, |
438 goma_stats=None, | 449 goma_stats=None, |
439 goma_error=None, | 450 goma_error=None, |
440 goma_crash_report_id=None, | 451 goma_crash_report_id=None, |
441 patch_url=None, | 452 patch_url=None, |
442 bbucket_id=None): | 453 bbucket_id=None, |
454 category=None): | |
443 """Send a ChromeInfraEvent filled with a BuildEvent | 455 """Send a ChromeInfraEvent filled with a BuildEvent |
444 | 456 |
445 Args: | 457 Args: |
446 event_type (string): any name of enum BuildEvent.BuildEventType. | 458 event_type (string): any name of enum BuildEvent.BuildEventType. |
447 (listed in infra_libs.event_mon.monitoring.BUILD_EVENT_TYPES) | 459 (listed in infra_libs.event_mon.monitoring.BUILD_EVENT_TYPES) |
448 hostname (string): fqdn of the machine that is running the build / step. | 460 hostname (string): fqdn of the machine that is running the build / step. |
449 aka the bot name. | 461 aka the bot name. |
450 build_name (string): name of the builder. | 462 build_name (string): name of the builder. |
451 | 463 |
452 Keyword args: | 464 Keyword args: |
453 build_number (int): as the name says. | 465 build_number (int): as the name says. |
454 build_scheduling_time (int): timestamp telling when the build was | 466 build_scheduling_time (int): timestamp telling when the build was |
455 scheduled. This is required when build_number is provided to make it | 467 scheduled. This is required when build_number is provided to make it |
456 possibly to distinguish two builds with the same build number. | 468 possibly to distinguish two builds with the same build number. |
457 step_name (str): name of the step. | 469 step_name (str): name of the step. |
458 step_text (str): text of the step. | 470 step_text (str): text of the step. |
459 step_number (int): rank of the step in the build. This is mandatory | 471 step_number (int): rank of the step in the build. This is mandatory |
460 if step_name is provided, because step_name is not enough to tell the | 472 if step_name is provided, because step_name is not enough to tell the |
461 order. | 473 order. |
462 result (string): any name of enum BuildEvent.BuildResult. | 474 result (string): any name of enum BuildEvent.BuildResult. |
463 (listed in infra_libs.event_mon.monitoring.BUILD_RESULTS) | 475 (listed in infra_libs.event_mon.monitoring.BUILD_RESULTS) |
464 extra_result_code (string or list of): arbitrary strings intended to provide | 476 extra_result_code (string or list of): arbitrary strings intended to provide |
465 more fine-grained information about the result. | 477 more fine-grained information about the result. |
466 goma_stats (goma_stats_pb2.GomaStats): statistics output by the Goma proxy. | 478 goma_stats (goma_stats_pb2.GomaStats): statistics output by the Goma proxy. |
467 goma_error (string): goma error type defined as GomaErrorType. | 479 goma_error (string): goma error type defined as GomaErrorType. |
468 goma_crash_report_id (string): id of goma crash report. | 480 goma_crash_report_id (string): id of goma crash report. |
469 patch_url (string): URL of the patch that triggered build | 481 patch_url (string): URL of the patch that triggered build |
470 bbucket_id (long): Buildbucket ID of the build. | 482 bbucket_id (long): Buildbucket ID of the build. |
483 category (string): Build category, e.g. cq or git_cl_try. | |
471 | 484 |
472 Returns: | 485 Returns: |
473 success (bool): False if some error happened. | 486 success (bool): False if some error happened. |
474 """ | 487 """ |
475 return get_build_event(event_type, | 488 return get_build_event(event_type, |
476 hostname, | 489 hostname, |
477 build_name, | 490 build_name, |
478 build_number=build_number, | 491 build_number=build_number, |
479 build_scheduling_time=build_scheduling_time, | 492 build_scheduling_time=build_scheduling_time, |
480 step_name=step_name, | 493 step_name=step_name, |
481 step_text=step_text, | 494 step_text=step_text, |
482 step_number=step_number, | 495 step_number=step_number, |
483 result=result, | 496 result=result, |
484 extra_result_code=extra_result_code, | 497 extra_result_code=extra_result_code, |
485 timestamp_kind=timestamp_kind, | 498 timestamp_kind=timestamp_kind, |
486 event_timestamp=event_timestamp, | 499 event_timestamp=event_timestamp, |
487 goma_stats=goma_stats, | 500 goma_stats=goma_stats, |
488 goma_error=goma_error, | 501 goma_error=goma_error, |
489 goma_crash_report_id=goma_crash_report_id, | 502 goma_crash_report_id=goma_crash_report_id, |
490 patch_url=patch_url, | 503 patch_url=patch_url, |
491 bbucket_id=bbucket_id).send() | 504 bbucket_id=bbucket_id, |
505 category=category).send() | |
492 | 506 |
493 | 507 |
494 def send_events(events): | 508 def send_events(events): |
495 """Send several events at once to the endpoint. | 509 """Send several events at once to the endpoint. |
496 | 510 |
497 Args: | 511 Args: |
498 events (iterable of Event): events to send | 512 events (iterable of Event): events to send |
499 | 513 |
500 Return: | 514 Return: |
501 success (bool): True if data was successfully received by the endpoint. | 515 success (bool): True if data was successfully received by the endpoint. |
502 """ | 516 """ |
503 return config._router.push_event(tuple(e.log_event() for e in events)) | 517 return config._router.push_event(tuple(e.log_event() for e in events)) |
OLD | NEW |