| 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 build_scheduling_time=None, | 262 build_scheduling_time=None, |
| 263 step_name=None, | 263 step_name=None, |
| 264 step_number=None, | 264 step_number=None, |
| 265 result=None, | 265 result=None, |
| 266 extra_result_code=None, | 266 extra_result_code=None, |
| 267 timestamp_kind=None, | 267 timestamp_kind=None, |
| 268 event_timestamp=None, | 268 event_timestamp=None, |
| 269 service_name=None, | 269 service_name=None, |
| 270 goma_stats=None, | 270 goma_stats=None, |
| 271 goma_error=None, | 271 goma_error=None, |
| 272 goma_crash_report_id=None): | 272 goma_crash_report_id=None, |
| 273 patch_url=None): |
| 273 """Compute a ChromeInfraEvent filled with a BuildEvent. | 274 """Compute a ChromeInfraEvent filled with a BuildEvent. |
| 274 | 275 |
| 275 Arguments are identical to those in send_build_event(), please refer | 276 Arguments are identical to those in send_build_event(), please refer |
| 276 to this docstring. | 277 to this docstring. |
| 277 | 278 |
| 278 Returns: | 279 Returns: |
| 279 event (log_request_lite_pb2.LogRequestLite.LogEventLite): can be None | 280 event (log_request_lite_pb2.LogRequestLite.LogEventLite): can be None |
| 280 if there is a major processing issue. | 281 if there is a major processing issue. |
| 281 """ | 282 """ |
| 282 if event_type not in BUILD_EVENT_TYPES: | 283 if event_type not in BUILD_EVENT_TYPES: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 if event.build_event.HasField('build_scheduling_time_ms'): | 325 if event.build_event.HasField('build_scheduling_time_ms'): |
| 325 logging.error('build_number has not been provided, ' | 326 logging.error('build_number has not been provided, ' |
| 326 'build_scheduling_time was provided (%s). ' | 327 'build_scheduling_time was provided (%s). ' |
| 327 'Both must be present or missing.', | 328 'Both must be present or missing.', |
| 328 event.build_event.build_scheduling_time_ms) | 329 event.build_event.build_scheduling_time_ms) |
| 329 | 330 |
| 330 if step_name: | 331 if step_name: |
| 331 event.build_event.step_name = step_name | 332 event.build_event.step_name = step_name |
| 332 if step_number is not None: | 333 if step_number is not None: |
| 333 event.build_event.step_number = step_number | 334 event.build_event.step_number = step_number |
| 335 if patch_url is not None: |
| 336 event.build_event.patch_url = patch_url |
| 334 | 337 |
| 335 if event.build_event.step_name: | 338 if event.build_event.step_name: |
| 336 if event_type != 'STEP': | 339 if event_type != 'STEP': |
| 337 logging.error('step_name should be provided only for type "STEP", ' | 340 logging.error('step_name should be provided only for type "STEP", ' |
| 338 'got %s', event_type) | 341 'got %s', event_type) |
| 339 if not event.build_event.HasField('step_number'): | 342 if not event.build_event.HasField('step_number'): |
| 340 logging.error('step_number was not provided, but got a value for ' | 343 logging.error('step_number was not provided, but got a value for ' |
| 341 'step_name (%s). Provide either both or none', | 344 'step_name (%s). Provide either both or none', |
| 342 step_name) | 345 step_name) |
| 343 if (not event.build_event.HasField('build_number') | 346 if (not event.build_event.HasField('build_number') |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 build_number=None, | 419 build_number=None, |
| 417 build_scheduling_time=None, | 420 build_scheduling_time=None, |
| 418 step_name=None, | 421 step_name=None, |
| 419 step_number=None, | 422 step_number=None, |
| 420 result=None, | 423 result=None, |
| 421 extra_result_code=None, | 424 extra_result_code=None, |
| 422 timestamp_kind=None, | 425 timestamp_kind=None, |
| 423 event_timestamp=None, | 426 event_timestamp=None, |
| 424 goma_stats=None, | 427 goma_stats=None, |
| 425 goma_error=None, | 428 goma_error=None, |
| 426 goma_crash_report_id=None): | 429 goma_crash_report_id=None, |
| 430 patch_url=None): |
| 427 """Send a ChromeInfraEvent filled with a BuildEvent | 431 """Send a ChromeInfraEvent filled with a BuildEvent |
| 428 | 432 |
| 429 Args: | 433 Args: |
| 430 event_type (string): any name of enum BuildEvent.BuildEventType. | 434 event_type (string): any name of enum BuildEvent.BuildEventType. |
| 431 (listed in infra_libs.event_mon.monitoring.BUILD_EVENT_TYPES) | 435 (listed in infra_libs.event_mon.monitoring.BUILD_EVENT_TYPES) |
| 432 hostname (string): fqdn of the machine that is running the build / step. | 436 hostname (string): fqdn of the machine that is running the build / step. |
| 433 aka the bot name. | 437 aka the bot name. |
| 434 build_name (string): name of the builder. | 438 build_name (string): name of the builder. |
| 435 | 439 |
| 436 Keyword args: | 440 Keyword args: |
| 437 build_number (int): as the name says. | 441 build_number (int): as the name says. |
| 438 build_scheduling_time (int): timestamp telling when the build was | 442 build_scheduling_time (int): timestamp telling when the build was |
| 439 scheduled. This is required when build_number is provided to make it | 443 scheduled. This is required when build_number is provided to make it |
| 440 possibly to distinguish two builds with the same build number. | 444 possibly to distinguish two builds with the same build number. |
| 441 step_name (str): name of the step. | 445 step_name (str): name of the step. |
| 442 step_number (int): rank of the step in the build. This is mandatory | 446 step_number (int): rank of the step in the build. This is mandatory |
| 443 if step_name is provided, because step_name is not enough to tell the | 447 if step_name is provided, because step_name is not enough to tell the |
| 444 order. | 448 order. |
| 445 result (string): any name of enum BuildEvent.BuildResult. | 449 result (string): any name of enum BuildEvent.BuildResult. |
| 446 (listed in infra_libs.event_mon.monitoring.BUILD_RESULTS) | 450 (listed in infra_libs.event_mon.monitoring.BUILD_RESULTS) |
| 447 extra_result_code (string or list of): arbitrary strings intended to provide | 451 extra_result_code (string or list of): arbitrary strings intended to provide |
| 448 more fine-grained information about the result. | 452 more fine-grained information about the result. |
| 449 goma_stats (goma_stats_pb2.GomaStats): statistics output by the Goma proxy. | 453 goma_stats (goma_stats_pb2.GomaStats): statistics output by the Goma proxy. |
| 450 goma_error (string): goma error type defined as GomaErrorType. | 454 goma_error (string): goma error type defined as GomaErrorType. |
| 451 goma_crash_report_id (string): id of goma crash report. | 455 goma_crash_report_id (string): id of goma crash report. |
| 456 patch_url (string): URL of the patch that triggered build |
| 452 | 457 |
| 453 Returns: | 458 Returns: |
| 454 success (bool): False if some error happened. | 459 success (bool): False if some error happened. |
| 455 """ | 460 """ |
| 456 return get_build_event(event_type, | 461 return get_build_event(event_type, |
| 457 hostname, | 462 hostname, |
| 458 build_name, | 463 build_name, |
| 459 build_number=build_number, | 464 build_number=build_number, |
| 460 build_scheduling_time=build_scheduling_time, | 465 build_scheduling_time=build_scheduling_time, |
| 461 step_name=step_name, | 466 step_name=step_name, |
| 462 step_number=step_number, | 467 step_number=step_number, |
| 463 result=result, | 468 result=result, |
| 464 extra_result_code=extra_result_code, | 469 extra_result_code=extra_result_code, |
| 465 timestamp_kind=timestamp_kind, | 470 timestamp_kind=timestamp_kind, |
| 466 event_timestamp=event_timestamp, | 471 event_timestamp=event_timestamp, |
| 467 goma_stats=goma_stats, | 472 goma_stats=goma_stats, |
| 468 goma_error=goma_error, | 473 goma_error=goma_error, |
| 469 goma_crash_report_id=goma_crash_report_id).send() | 474 goma_crash_report_id=goma_crash_report_id, |
| 475 patch_url=patch_url).send() |
| 470 | 476 |
| 471 | 477 |
| 472 def send_events(events): | 478 def send_events(events): |
| 473 """Send several events at once to the endpoint. | 479 """Send several events at once to the endpoint. |
| 474 | 480 |
| 475 Args: | 481 Args: |
| 476 events (iterable of Event): events to send | 482 events (iterable of Event): events to send |
| 477 | 483 |
| 478 Return: | 484 Return: |
| 479 success (bool): True if data was successfully received by the endpoint. | 485 success (bool): True if data was successfully received by the endpoint. |
| 480 """ | 486 """ |
| 481 return config._router.push_event(tuple(e.log_event() for e in events)) | 487 return config._router.push_event(tuple(e.log_event() for e in events)) |
| OLD | NEW |