Exemplo n.º 1
0
  def test_send_events_smoke(self):
    self.assertIsInstance(config._router, router._Router)
    self.assertIsInstance(config.cache.get('default_event'), ChromeInfraEvent)

    log_events = [
      event_mon.get_build_event(
        'BUILD',
        'bot.host.name',
        'build_name',
        build_number=1,
        build_scheduling_time=123456789,
        result='FAILURE',
        timestamp_kind='POINT',
        event_timestamp=None),
      event_mon.get_build_event(
        'BUILD',
        'bot2.host.name',
        'build_name2',
        build_number=1,
        build_scheduling_time=123456789,
        result='FAILURE',
        timestamp_kind='POINT',
        event_timestamp=None),
    ]
    self.assertTrue(monitoring.send_events(log_events))
Exemplo n.º 2
0
def read_events_from_file(filename):
  """Read a list of ChromeInfraEvent from a file.

  Each line of the file is expected to contain options in the shape of a dict:

  Example:
  {"build-event-type": "BUILD", "build-event-hostname": "hostname",
   "build-event-build-name": "fake builder"}

  There may be several lines, but each dict should be one its own line.

  Caveat: only build events options are supported so far.
  See send_monitoring_event --help for the full list of flags.

  Args:
    filename(str): path to the file to read.

  Return:
    events (iterable of event_mon.Event): events read from the file.
  """
  events = []
  with open(filename, 'r') as f:
    lineno = 0
    for line in f:
      lineno += 1
      if not line.strip():
        continue
      try:
        args = json.loads(line)
      except ValueError:
        LOGGER.error("Unparseable line in %s: %s", filename, line)
        continue

      if 'build-event-type' in args:
        events.append(
          event_mon.get_build_event(
            args.get('build-event-type'),
            args.get('build-event-hostname'),
            args.get('build-event-build-name'),
            build_number=args.get('build-event-build-number'),
            build_scheduling_time=args.get('build-event-build-scheduling-time'),
            step_name=args.get('build-event-step-name'),
            step_number=args.get('build-event-step-number'),
            result=args.get('build-event-result'),
            extra_result_code=args.get('build-event-extra-result-code'),
            timestamp_kind=args.get('event-mon-timestamp-kind'),
            event_timestamp=args.get('event-mon-event-timestamp'),
            service_name=args.get('event-mon-service-name'),
            patch_url=args.get('build-event-patch-url')))
      else:
        LOGGER.warning('build-event-type field not found, skipping line '
                       '%d in %s', lineno, filename)
  return events
Exemplo n.º 3
0
def read_events_from_file(filename):
    """Read a list of ChromeInfraEvent from a file.

  Each line of the file is expected to contain options in the shape of a dict:

  Example:
  {"build-event-type": "BUILD", "build-event-hostname": "hostname",
   "build-event-build-name": "fake builder"}

  There may be several lines, but each dict should be one its own line.

  Caveat: only build events options are supported so far.
  See send_monitoring_event --help for the full list of flags.

  Args:
    filename(str): path to the file to read.

  Return:
    log_events (iterable of LogRequestLite): events read from the file.
  """
    log_events = []
    with open(filename, "r") as f:
        for line in f:
            if not line.strip():
                continue
            try:
                args = json.loads(line)
            except ValueError:
                LOGGER.error("Unparseable line in %s: %s", filename, line)
                continue

            if "build-event-type" in args:
                log_events.append(
                    event_mon.get_build_event(
                        args.get("build-event-type"),
                        args.get("build-event-hostname"),
                        args.get("build-event-build-name"),
                        build_number=args.get("build-event-build-number"),
                        build_scheduling_time=args.get("build-event-build-scheduling-time"),
                        step_name=args.get("build-event-step-name"),
                        step_number=args.get("build-event-step-number"),
                        result=args.get("build-event-result"),
                        timestamp_kind=args.get("event-mon-timestamp-kind"),
                        event_timestamp=args.get("event-mon-event-timestamp"),
                        service_name=args.get("event-mon-service-name"),
                    )
                )

    return log_events
Exemplo n.º 4
0
def read_events_from_file(filename):
    """Read a list of ChromeInfraEvent from a file.

  Each line of the file is expected to contain options in the shape of a dict:

  Example:
  {"build-event-type": "BUILD", "build-event-hostname": "hostname",
   "build-event-build-name": "fake builder"}

  There may be several lines, but each dict should be one its own line.

  Caveat: only build events options are supported so far.
  See send_monitoring_event --help for the full list of flags.

  Args:
    filename(str): path to the file to read.

  Return:
    log_events (iterable of LogRequestLite): events read from the file.
  """
    log_events = []
    with open(filename, 'r') as f:
        for line in f:
            if not line.strip():
                continue
            try:
                args = json.loads(line)
            except ValueError:
                LOGGER.error("Unparseable line in %s: %s", filename, line)
                continue

            if 'build-event-type' in args:
                log_events.append(
                    event_mon.get_build_event(
                        args.get('build-event-type'),
                        args.get('build-event-hostname'),
                        args.get('build-event-build-name'),
                        build_number=args.get('build-event-build-number'),
                        build_scheduling_time=args.get(
                            'build-event-build-scheduling-time'),
                        step_name=args.get('build-event-step-name'),
                        step_number=args.get('build-event-step-number'),
                        result=args.get('build-event-result'),
                        timestamp_kind=args.get('event-mon-timestamp-kind'),
                        event_timestamp=args.get('event-mon-event-timestamp'),
                        service_name=args.get('event-mon-service-name')))

    return log_events
Exemplo n.º 5
0
def read_events_from_file(filename):
    """Read a list of ChromeInfraEvent from a file.

  Each line of the file is expected to contain options in the shape of a dict:

  Example:
  {"build-event-type": "BUILD", "build-event-hostname": "hostname",
   "build-event-build-name": "fake builder"}

  There may be several lines, but each dict should be one its own line.

  Caveat: only build events options are supported so far.
  See send_monitoring_event --help for the full list of flags.

  Args:
    filename(str): path to the file to read.

  Return:
    events (iterable of event_mon.Event): events read from the file.
  """
    events = []
    with open(filename, 'r') as f:
        lineno = 0
        for line in f:
            lineno += 1
            if not line.strip():
                continue
            try:
                args = json.loads(line)
            except ValueError:
                LOGGER.error("Unparseable line in %s: %s", filename, line)
                continue

            if 'build-event-type' in args:
                events.append(
                    event_mon.get_build_event(
                        args.get('build-event-type'),
                        args.get('build-event-hostname'),
                        args.get('build-event-build-name'),
                        build_number=args.get('build-event-build-number'),
                        build_scheduling_time=args.get(
                            'build-event-build-scheduling-time'),
                        step_name=args.get('build-event-step-name'),
                        step_text=args.get('build-event-step-text'),
                        step_number=args.get('build-event-step-number'),
                        result=args.get('build-event-result'),
                        extra_result_code=args.get(
                            'build-event-extra-result-code'),
                        timestamp_kind=args.get('event-mon-timestamp-kind'),
                        event_timestamp=args.get('event-mon-event-timestamp'),
                        service_name=args.get('event-mon-service-name'),
                        patch_url=args.get('build-event-patch-url'),
                        bbucket_id=args.get('build-event-bbucket-id'),
                        category=args.get('build-event-category'),
                        head_revision_git_hash=args.get(
                            'build-event-head-revision-git-hash')))
            else:
                LOGGER.warning(
                    'build-event-type field not found, skipping line '
                    '%d in %s', lineno, filename)
    return events