| 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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 step_text=None, | 264 step_text=None, |
| 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 """Compute a ChromeInfraEvent filled with a BuildEvent. | 276 """Compute a ChromeInfraEvent filled with a BuildEvent. |
| 276 | 277 |
| 277 Arguments are identical to those in send_build_event(), please refer | 278 Arguments are identical to those in send_build_event(), please refer |
| 278 to this docstring. | 279 to this docstring. |
| 279 | 280 |
| 280 Returns: | 281 Returns: |
| 281 event (log_request_lite_pb2.LogRequestLite.LogEventLite): can be None | 282 event (log_request_lite_pb2.LogRequestLite.LogEventLite): can be None |
| 282 if there is a major processing issue. | 283 if there is a major processing issue. |
| 283 """ | 284 """ |
| 284 if event_type not in BUILD_EVENT_TYPES: | 285 if event_type not in BUILD_EVENT_TYPES: |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 332 |
| 332 if step_name: | 333 if step_name: |
| 333 event.build_event.step_name = str(step_name) | 334 event.build_event.step_name = str(step_name) |
| 334 if step_text: | 335 if step_text: |
| 335 event.build_event.step_text = str(step_text) | 336 event.build_event.step_text = str(step_text) |
| 336 | 337 |
| 337 if step_number is not None: | 338 if step_number is not None: |
| 338 event.build_event.step_number = step_number | 339 event.build_event.step_number = step_number |
| 339 if patch_url is not None: | 340 if patch_url is not None: |
| 340 event.build_event.patch_url = patch_url | 341 event.build_event.patch_url = patch_url |
| 342 if bbucket_id is not None: |
| 343 try: |
| 344 event.build_event.bbucket_id = int(bbucket_id) |
| 345 except (ValueError, TypeError): |
| 346 pass |
| 341 | 347 |
| 342 if event.build_event.step_name: | 348 if event.build_event.step_name: |
| 343 if event_type != 'STEP': | 349 if event_type != 'STEP': |
| 344 logging.error('step_name should be provided only for type "STEP", ' | 350 logging.error('step_name should be provided only for type "STEP", ' |
| 345 'got %s', event_type) | 351 'got %s', event_type) |
| 346 if not event.build_event.HasField('step_number'): | 352 if not event.build_event.HasField('step_number'): |
| 347 logging.error('step_number was not provided, but got a value for ' | 353 logging.error('step_number was not provided, but got a value for ' |
| 348 'step_name (%s). Provide either both or none', | 354 'step_name (%s). Provide either both or none', |
| 349 step_name) | 355 step_name) |
| 350 if (not event.build_event.HasField('build_number') | 356 if (not event.build_event.HasField('build_number') |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 step_name=None, | 431 step_name=None, |
| 426 step_text=None, | 432 step_text=None, |
| 427 step_number=None, | 433 step_number=None, |
| 428 result=None, | 434 result=None, |
| 429 extra_result_code=None, | 435 extra_result_code=None, |
| 430 timestamp_kind=None, | 436 timestamp_kind=None, |
| 431 event_timestamp=None, | 437 event_timestamp=None, |
| 432 goma_stats=None, | 438 goma_stats=None, |
| 433 goma_error=None, | 439 goma_error=None, |
| 434 goma_crash_report_id=None, | 440 goma_crash_report_id=None, |
| 435 patch_url=None): | 441 patch_url=None, |
| 442 bbucket_id=None): |
| 436 """Send a ChromeInfraEvent filled with a BuildEvent | 443 """Send a ChromeInfraEvent filled with a BuildEvent |
| 437 | 444 |
| 438 Args: | 445 Args: |
| 439 event_type (string): any name of enum BuildEvent.BuildEventType. | 446 event_type (string): any name of enum BuildEvent.BuildEventType. |
| 440 (listed in infra_libs.event_mon.monitoring.BUILD_EVENT_TYPES) | 447 (listed in infra_libs.event_mon.monitoring.BUILD_EVENT_TYPES) |
| 441 hostname (string): fqdn of the machine that is running the build / step. | 448 hostname (string): fqdn of the machine that is running the build / step. |
| 442 aka the bot name. | 449 aka the bot name. |
| 443 build_name (string): name of the builder. | 450 build_name (string): name of the builder. |
| 444 | 451 |
| 445 Keyword args: | 452 Keyword args: |
| 446 build_number (int): as the name says. | 453 build_number (int): as the name says. |
| 447 build_scheduling_time (int): timestamp telling when the build was | 454 build_scheduling_time (int): timestamp telling when the build was |
| 448 scheduled. This is required when build_number is provided to make it | 455 scheduled. This is required when build_number is provided to make it |
| 449 possibly to distinguish two builds with the same build number. | 456 possibly to distinguish two builds with the same build number. |
| 450 step_name (str): name of the step. | 457 step_name (str): name of the step. |
| 451 step_text (str): text of the step. | 458 step_text (str): text of the step. |
| 452 step_number (int): rank of the step in the build. This is mandatory | 459 step_number (int): rank of the step in the build. This is mandatory |
| 453 if step_name is provided, because step_name is not enough to tell the | 460 if step_name is provided, because step_name is not enough to tell the |
| 454 order. | 461 order. |
| 455 result (string): any name of enum BuildEvent.BuildResult. | 462 result (string): any name of enum BuildEvent.BuildResult. |
| 456 (listed in infra_libs.event_mon.monitoring.BUILD_RESULTS) | 463 (listed in infra_libs.event_mon.monitoring.BUILD_RESULTS) |
| 457 extra_result_code (string or list of): arbitrary strings intended to provide | 464 extra_result_code (string or list of): arbitrary strings intended to provide |
| 458 more fine-grained information about the result. | 465 more fine-grained information about the result. |
| 459 goma_stats (goma_stats_pb2.GomaStats): statistics output by the Goma proxy. | 466 goma_stats (goma_stats_pb2.GomaStats): statistics output by the Goma proxy. |
| 460 goma_error (string): goma error type defined as GomaErrorType. | 467 goma_error (string): goma error type defined as GomaErrorType. |
| 461 goma_crash_report_id (string): id of goma crash report. | 468 goma_crash_report_id (string): id of goma crash report. |
| 462 patch_url (string): URL of the patch that triggered build | 469 patch_url (string): URL of the patch that triggered build |
| 470 bbucket_id (long): Buildbucket ID of the build. |
| 463 | 471 |
| 464 Returns: | 472 Returns: |
| 465 success (bool): False if some error happened. | 473 success (bool): False if some error happened. |
| 466 """ | 474 """ |
| 467 return get_build_event(event_type, | 475 return get_build_event(event_type, |
| 468 hostname, | 476 hostname, |
| 469 build_name, | 477 build_name, |
| 470 build_number=build_number, | 478 build_number=build_number, |
| 471 build_scheduling_time=build_scheduling_time, | 479 build_scheduling_time=build_scheduling_time, |
| 472 step_name=step_name, | 480 step_name=step_name, |
| 473 step_text=step_text, | 481 step_text=step_text, |
| 474 step_number=step_number, | 482 step_number=step_number, |
| 475 result=result, | 483 result=result, |
| 476 extra_result_code=extra_result_code, | 484 extra_result_code=extra_result_code, |
| 477 timestamp_kind=timestamp_kind, | 485 timestamp_kind=timestamp_kind, |
| 478 event_timestamp=event_timestamp, | 486 event_timestamp=event_timestamp, |
| 479 goma_stats=goma_stats, | 487 goma_stats=goma_stats, |
| 480 goma_error=goma_error, | 488 goma_error=goma_error, |
| 481 goma_crash_report_id=goma_crash_report_id, | 489 goma_crash_report_id=goma_crash_report_id, |
| 482 patch_url=patch_url).send() | 490 patch_url=patch_url, |
| 491 bbucket_id=bbucket_id).send() |
| 483 | 492 |
| 484 | 493 |
| 485 def send_events(events): | 494 def send_events(events): |
| 486 """Send several events at once to the endpoint. | 495 """Send several events at once to the endpoint. |
| 487 | 496 |
| 488 Args: | 497 Args: |
| 489 events (iterable of Event): events to send | 498 events (iterable of Event): events to send |
| 490 | 499 |
| 491 Return: | 500 Return: |
| 492 success (bool): True if data was successfully received by the endpoint. | 501 success (bool): True if data was successfully received by the endpoint. |
| 493 """ | 502 """ |
| 494 return config._router.push_event(tuple(e.log_event() for e in events)) | 503 return config._router.push_event(tuple(e.log_event() for e in events)) |
| OLD | NEW |