Ejemplo n.º 1
0
 def test_send_build_event_smoke(self):
     args = send_event.get_arguments([
         '--event-mon-service-name', 'thing', '--build-event-type',
         'SCHEDULER', '--build-event-hostname', 'foo.bar.dns',
         '--build-event-build-name', 'whatever'
     ])
     send_event.send_build_event(args)
Ejemplo n.º 2
0
 def test_send_build_event_smoke(self):
   args = send_event.get_arguments(
     ['--event-mon-service-name', 'thing',
      '--build-event-type', 'SCHEDULER',
      '--build-event-hostname', 'foo.bar.dns',
      '--build-event-build-name', 'whatever'])
   send_event.send_build_event(args)
Ejemplo n.º 3
0
 def test_send_build_event_smoke_missing_goma_file(self):
   args = send_event.get_arguments(
     ['--event-mon-service-name', 'thing',
      '--build-event-type', 'BUILD',
      '--build-event-hostname', 'foo.bar.dns',
      '--build-event-build-name', 'whatever',
      '--build-event-goma-stats-path',
          os.path.join(DATA_DIR, 'this-file-does-not-exist')])
   with self.assertRaises(IOError):
     send_event.send_build_event(args)
Ejemplo n.º 4
0
  def test_logrequest_path_build_type_override(self):
    # logrequest contains build event, overrid the type with an arg.
    with infra_libs.temporary_directory(prefix='send_event_test-') as tmpdir:
      outfile = os.path.join(tmpdir, 'out.bin')
      args = send_event.get_arguments(
        ['--event-mon-run-type', 'file',
         '--event-mon-output-file', outfile,
         '--event-mon-service-name', 'thing',
         '--event-logrequest-path',
             os.path.join(DATA_DIR, 'build-foo-builder.bin'),
         '--build-event-build-number', '3',
         '--build-event-type', 'STEP',
        ])
      self.assertEquals(args.event_mon_run_type, 'file')
      event_mon.process_argparse_options(args)
      send_event._process_logrequest_path(args)
      self.assertTrue(send_event.send_build_event(args))

      # Now open the resulting file and check what was written
      with open(outfile, 'rb') as f:
        request = LogRequestLite.FromString(f.read())

    self.assertEqual(len(request.log_event), 1)
    event = ChromeInfraEvent.FromString(request.log_event[0].source_extension)
    self.assertEqual(event.build_event.host_name, 'myhostname')
    self.assertEqual(event.build_event.type, BuildEvent.STEP)
    self.assertEqual(event.build_event.build_number, 3)
    self.assertEqual(event.timestamp_kind, ChromeInfraEvent.BEGIN)
Ejemplo n.º 5
0
  def test_send_build_event_with_goma_error_crashed(self):
    with infra_libs.temporary_directory(prefix='send_event_test-') as tmpdir:
      outfile = os.path.join(tmpdir, 'out.bin')
      args = send_event.get_arguments(
        ['--event-mon-run-type', 'file',
         '--event-mon-output-file', outfile,
         '--event-mon-service-name', 'thing',
         '--build-event-type', 'BUILD',
         '--build-event-hostname', 'foo.bar.dns',
         '--build-event-build-name', 'whatever',
         '--build-event-goma-error', 'GOMA_ERROR_CRASHED',
         '--build-event-goma-crash-report-id-path',
         os.path.join(DATA_DIR, 'goma_error_report.txt')])
      self.assertEquals(args.event_mon_run_type, 'file')
      event_mon.process_argparse_options(args)
      self.assertTrue(send_event.send_build_event(args))

      # Now open the resulting file and check what was written
      with open(outfile, 'rb') as f:
        request = LogRequestLite.FromString(f.read())

    self.assertEqual(len(request.log_event), 1)
    event = ChromeInfraEvent.FromString(request.log_event[0].source_extension)
    self.assertEqual(event.build_event.goma_error,
                     BuildEvent.GOMA_ERROR_CRASHED)
    self.assertEqual(event.build_event.goma_crash_report_id,
                     '0123456789abcdef0')
    self.assertEqual(event.build_event.host_name, 'foo.bar.dns')
Ejemplo n.º 6
0
  def test_send_build_event_with_goma_stats(self):
    # Write a file to avoid mocks
    with infra_libs.temporary_directory(prefix='send_event_test-') as tmpdir:
      outfile = os.path.join(tmpdir, 'out.bin')
      args = send_event.get_arguments(
        ['--event-mon-run-type', 'file',
         '--event-mon-output-file', outfile,
         '--event-mon-service-name', 'thing',
         '--build-event-type', 'BUILD',
         '--build-event-hostname', 'foo.bar.dns',
         '--build-event-build-name', 'whatever',
         '--build-event-goma-stats-path',
         os.path.join(DATA_DIR, 'goma_stats.bin')])
      self.assertEquals(args.event_mon_run_type, 'file')
      event_mon.process_argparse_options(args)
      self.assertTrue(send_event.send_build_event(args))

      # Now open the resulting file and check what was written
      with open(outfile, 'rb') as f:
        request = LogRequestLite.FromString(f.read())

    self.assertEqual(len(request.log_event), 1)
    event = ChromeInfraEvent.FromString(request.log_event[0].source_extension)
    self.assertEqual(event.build_event.goma_stats.request_stats.total, 10)
    self.assertEqual(event.build_event.goma_stats.request_stats.success, 9)
    self.assertEqual(event.build_event.goma_stats.request_stats.failure, 1)
    self.assertEqual(event.build_event.host_name, 'foo.bar.dns')
Ejemplo n.º 7
0
 def test_send_build_event_with_invalid_goma_stats(self):
   # Write a file to avoid mocks
   with infra_libs.temporary_directory(prefix='send_event_test-') as tmpdir:
     outfile = os.path.join(tmpdir, 'out.bin')
     args = send_event.get_arguments(
       ['--event-mon-run-type', 'file',
        '--event-mon-output-file', outfile,
        '--event-mon-service-name', 'thing',
        '--build-event-type', 'BUILD',
        '--build-event-hostname', 'foo.bar.dns',
        '--build-event-build-name', 'whatever',
        '--build-event-goma-stats-path',
        os.path.join(DATA_DIR, 'garbage')])
     self.assertEquals(args.event_mon_run_type, 'file')
     event_mon.process_argparse_options(args)
     with self.assertRaises(google.protobuf.message.DecodeError):
       send_event.send_build_event(args)
Ejemplo n.º 8
0
 def test_send_build_event_with_non_existing_goma_error_report(self):
   # Write a file to avoid mocks
   with infra_libs.temporary_directory(prefix='send_event_test-') as tmpdir:
     outfile = os.path.join(tmpdir, 'out.bin')
     args = send_event.get_arguments(
       ['--event-mon-run-type', 'file',
        '--event-mon-output-file', outfile,
        '--event-mon-service-name', 'thing',
        '--build-event-type', 'BUILD',
        '--build-event-hostname', 'foo.bar.dns',
        '--build-event-build-name', 'whatever',
        '--build-event-goma-error', 'GOMA_ERROR_CRASHED',
        '--build-event-goma-crash-report-id-path',
        os.path.join(DATA_DIR, 'this-file-does-not-exist')])
     self.assertEquals(args.event_mon_run_type, 'file')
     event_mon.process_argparse_options(args)
     with self.assertRaises(IOError):
       send_event.send_build_event(args)
Ejemplo n.º 9
0
def main(argv):  # pragma: no cover
    # Does nothing when no arguments are passed, to make it safe to import this
    # module (main() is executed on import, because this file is called __main__).
    status = 0

    if len(argv) == 0:
        return status

    success_metric = ts_mon.BooleanMetric('send_monitoring_event/success')

    try:
        args = send_event.get_arguments(argv)

        send_event.process_argparse_options(args)

        if args.build_event_type:
            success_metric.set(send_event.send_build_event(args))

        elif args.service_event_type:
            success_metric.set(send_event.send_service_event(args))

        elif args.events_from_file:
            success_metric.set(send_event.send_events_from_file(args))

        else:
            print >> sys.stderr, (
                'At least one of the --*-event-type options or '
                '--events-from-file should be provided. Nothing '
                'was sent.')
            status = 2
            success_metric.set(False)
    except Exception:
        success_metric.set(False)
    finally:
        event_mon.close()
        try:
            ts_mon.flush()
        except ts_mon.MonitoringNoConfiguredMonitorError:
            pass
    return status
Ejemplo n.º 10
0
def main(argv):  # pragma: no cover
  # Does nothing when no arguments are passed, to make it safe to import this
  # module (main() is executed on import, because this file is called __main__).
  status = 0

  if len(argv) == 0:
    return status

  try:
    args = send_event.get_arguments(argv)
    send_event.process_argparse_options(args)

    if args.build_event_type:
      success_metric.set(send_event.send_build_event(args))

    elif args.service_event_type:
      success_metric.set(send_event.send_service_event(args))

    elif args.events_from_file:
      success_metric.set(send_event.send_events_from_file(args))

    else:
      print >> sys.stderr, ('At least one of the --*-event-type options or '
                            '--events-from-file should be provided. Nothing '
                            'was sent.')
      status = 2
      success_metric.set(False)
  except Exception:
    success_metric.set(False)
    traceback.print_exc()  # helps with debugging locally.
  finally:
    event_mon.close()
    try:
      ts_mon.flush()
    except ts_mon.MonitoringNoConfiguredMonitorError:
      logging.error("Unable to flush ts_mon because it's not configured.")
    except Exception:
      logging.exception("Flushing ts_mon metrics failed.")
  return status
Ejemplo n.º 11
0
def main(argv):  # pragma: no cover
  # Does nothing when no arguments are passed, to make it safe to import this
  # module (main() is executed on import, because this file is called __main__).
  status = 0

  if len(argv) == 0:
    return status

  success_metric = ts_mon.BooleanMetric('send_monitoring_event/success')

  try:
    args = send_event.get_arguments(argv)

    send_event.process_argparse_options(args)

    if args.build_event_type:
      success_metric.set(send_event.send_build_event(args))

    elif args.service_event_type:
      success_metric.set(send_event.send_service_event(args))

    elif args.events_from_file:
      success_metric.set(send_event.send_events_from_file(args))

    else:
      print >> sys.stderr, ('At least one of the --*-event-type options or '
                            '--events-from-file should be provided. Nothing '
                            'was sent.')
      status = 2
      success_metric.set(False)
  except Exception:
    success_metric.set(False)
  finally:
    event_mon.close()
    try:
      ts_mon.flush()
    except ts_mon.MonitoringNoConfiguredMonitorError:
      pass
  return status