Example #1
0
def _get_chrome_infra_event(timestamp_kind, service_name=None):
  """Compute a basic event.

  Validates the inputs and returns a pre-filled ChromeInfraEvent or
  None if any check failed.

  The proto is filled using values provided in setup_monitoring() at
  initialization time, and args.

  Args:
    timestamp_kind (string): any of ('POINT', 'BEGIN', 'END').

  Returns:
    event (chrome_infra_log_pb2.ChromeInfraEvent):
  """
  # Testing for None because we want an error message when timestamp_kind == ''.
  if timestamp_kind is not None and timestamp_kind not in TIMESTAMP_KINDS:
    logging.error('Invalid value for timestamp_kind: %s', timestamp_kind)
    return None

  # We must accept unicode here.
  if service_name is not None and not isinstance(service_name, basestring):
    logging.error('Invalid type for service_name: %s', type(service_name))
    return None

  event = ChromeInfraEvent()
  event.CopyFrom(config._cache['default_event'])

  if timestamp_kind:
    event.timestamp_kind = ChromeInfraEvent.TimestampKind.Value(timestamp_kind)
  if service_name:
    event.event_source.service_name = service_name

  return event
Example #2
0
def get_default_event():
    """Returns a copy of the default event."""

    # We return a copy here to tell people not to modify the event directly.
    ret = ChromeInfraEvent()
    ret.CopyFrom(_cache['default_event'])
    return ret