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: |
| 350 event.build_event.category = { |
| 351 'cq': BuildEvent.CATEGORY_CQ, |
| 352 'cq_experimental': BuildEvent.CATEGORY_CQ_EXPERIMENTAL, |
| 353 'git_cl_try': BuildEvent.CATEGORY_GIT_CL_TRY, |
| 354 }.get(category.lower(), BuildEvent.CATEGORY_UNKNOWN) |
| 355 |
| 356 |
348 if event.build_event.step_name: | 357 if event.build_event.step_name: |
349 if event_type != 'STEP': | 358 if event_type != 'STEP': |
350 logging.error('step_name should be provided only for type "STEP", ' | 359 logging.error('step_name should be provided only for type "STEP", ' |
351 'got %s', event_type) | 360 'got %s', event_type) |
352 if not event.build_event.HasField('step_number'): | 361 if not event.build_event.HasField('step_number'): |
353 logging.error('step_number was not provided, but got a value for ' | 362 logging.error('step_number was not provided, but got a value for ' |
354 'step_name (%s). Provide either both or none', | 363 'step_name (%s). Provide either both or none', |
355 step_name) | 364 step_name) |
356 if (not event.build_event.HasField('build_number') | 365 if (not event.build_event.HasField('build_number') |
357 and not event.build_event.HasField('build_scheduling_time_ms')): | 366 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, | 441 step_text=None, |
433 step_number=None, | 442 step_number=None, |
434 result=None, | 443 result=None, |
435 extra_result_code=None, | 444 extra_result_code=None, |
436 timestamp_kind=None, | 445 timestamp_kind=None, |
437 event_timestamp=None, | 446 event_timestamp=None, |
438 goma_stats=None, | 447 goma_stats=None, |
439 goma_error=None, | 448 goma_error=None, |
440 goma_crash_report_id=None, | 449 goma_crash_report_id=None, |
441 patch_url=None, | 450 patch_url=None, |
442 bbucket_id=None): | 451 bbucket_id=None, |
| 452 category=None): |
443 """Send a ChromeInfraEvent filled with a BuildEvent | 453 """Send a ChromeInfraEvent filled with a BuildEvent |
444 | 454 |
445 Args: | 455 Args: |
446 event_type (string): any name of enum BuildEvent.BuildEventType. | 456 event_type (string): any name of enum BuildEvent.BuildEventType. |
447 (listed in infra_libs.event_mon.monitoring.BUILD_EVENT_TYPES) | 457 (listed in infra_libs.event_mon.monitoring.BUILD_EVENT_TYPES) |
448 hostname (string): fqdn of the machine that is running the build / step. | 458 hostname (string): fqdn of the machine that is running the build / step. |
449 aka the bot name. | 459 aka the bot name. |
450 build_name (string): name of the builder. | 460 build_name (string): name of the builder. |
451 | 461 |
452 Keyword args: | 462 Keyword args: |
453 build_number (int): as the name says. | 463 build_number (int): as the name says. |
454 build_scheduling_time (int): timestamp telling when the build was | 464 build_scheduling_time (int): timestamp telling when the build was |
455 scheduled. This is required when build_number is provided to make it | 465 scheduled. This is required when build_number is provided to make it |
456 possibly to distinguish two builds with the same build number. | 466 possibly to distinguish two builds with the same build number. |
457 step_name (str): name of the step. | 467 step_name (str): name of the step. |
458 step_text (str): text of the step. | 468 step_text (str): text of the step. |
459 step_number (int): rank of the step in the build. This is mandatory | 469 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 | 470 if step_name is provided, because step_name is not enough to tell the |
461 order. | 471 order. |
462 result (string): any name of enum BuildEvent.BuildResult. | 472 result (string): any name of enum BuildEvent.BuildResult. |
463 (listed in infra_libs.event_mon.monitoring.BUILD_RESULTS) | 473 (listed in infra_libs.event_mon.monitoring.BUILD_RESULTS) |
464 extra_result_code (string or list of): arbitrary strings intended to provide | 474 extra_result_code (string or list of): arbitrary strings intended to provide |
465 more fine-grained information about the result. | 475 more fine-grained information about the result. |
466 goma_stats (goma_stats_pb2.GomaStats): statistics output by the Goma proxy. | 476 goma_stats (goma_stats_pb2.GomaStats): statistics output by the Goma proxy. |
467 goma_error (string): goma error type defined as GomaErrorType. | 477 goma_error (string): goma error type defined as GomaErrorType. |
468 goma_crash_report_id (string): id of goma crash report. | 478 goma_crash_report_id (string): id of goma crash report. |
469 patch_url (string): URL of the patch that triggered build | 479 patch_url (string): URL of the patch that triggered build |
470 bbucket_id (long): Buildbucket ID of the build. | 480 bbucket_id (long): Buildbucket ID of the build. |
| 481 category (string): Build category, e.g. cq or git_cl_try. |
471 | 482 |
472 Returns: | 483 Returns: |
473 success (bool): False if some error happened. | 484 success (bool): False if some error happened. |
474 """ | 485 """ |
475 return get_build_event(event_type, | 486 return get_build_event(event_type, |
476 hostname, | 487 hostname, |
477 build_name, | 488 build_name, |
478 build_number=build_number, | 489 build_number=build_number, |
479 build_scheduling_time=build_scheduling_time, | 490 build_scheduling_time=build_scheduling_time, |
480 step_name=step_name, | 491 step_name=step_name, |
481 step_text=step_text, | 492 step_text=step_text, |
482 step_number=step_number, | 493 step_number=step_number, |
483 result=result, | 494 result=result, |
484 extra_result_code=extra_result_code, | 495 extra_result_code=extra_result_code, |
485 timestamp_kind=timestamp_kind, | 496 timestamp_kind=timestamp_kind, |
486 event_timestamp=event_timestamp, | 497 event_timestamp=event_timestamp, |
487 goma_stats=goma_stats, | 498 goma_stats=goma_stats, |
488 goma_error=goma_error, | 499 goma_error=goma_error, |
489 goma_crash_report_id=goma_crash_report_id, | 500 goma_crash_report_id=goma_crash_report_id, |
490 patch_url=patch_url, | 501 patch_url=patch_url, |
491 bbucket_id=bbucket_id).send() | 502 bbucket_id=bbucket_id, |
| 503 category=category).send() |
492 | 504 |
493 | 505 |
494 def send_events(events): | 506 def send_events(events): |
495 """Send several events at once to the endpoint. | 507 """Send several events at once to the endpoint. |
496 | 508 |
497 Args: | 509 Args: |
498 events (iterable of Event): events to send | 510 events (iterable of Event): events to send |
499 | 511 |
500 Return: | 512 Return: |
501 success (bool): True if data was successfully received by the endpoint. | 513 success (bool): True if data was successfully received by the endpoint. |
502 """ | 514 """ |
503 return config._router.push_event(tuple(e.log_event() for e in events)) | 515 return config._router.push_event(tuple(e.log_event() for e in events)) |
OLD | NEW |