Ejemplo n.º 1
0
 def _set_up_args(self, args=None):  # pragma: no cover
   parser = argparse.ArgumentParser()
   event_mon.add_argparse_options(parser)
   args = parser.parse_args((args or []))
   self.assertEquals(args.event_mon_run_type, 'dry')
   event_mon.process_argparse_options(args)
   r = config._router
   self.assertIsInstance(r, router._Router)
   # Check that process_argparse_options is idempotent
   event_mon.process_argparse_options(args)
   self.assertIs(config._router, r)
Ejemplo n.º 2
0
 def _set_up_args(self, args=None):  # pragma: no cover
     parser = argparse.ArgumentParser()
     event_mon.add_argparse_options(parser)
     args = parser.parse_args((args or []))
     # Safety net. We really don't want to send something to a real endpoint.
     self.assertTrue((args.event_mon_run_type not in ('test', 'prod'))
                     or args.dry_run)
     event_mon.process_argparse_options(args)
     r = config._router
     self.assertIsInstance(r, router._Router)
     # Check that process_argparse_options is idempotent
     event_mon.process_argparse_options(args)
     self.assertIs(config._router, r)
Ejemplo n.º 3
0
 def _set_up_args(self, args=None):  # pragma: no cover
   parser = argparse.ArgumentParser()
   event_mon.add_argparse_options(parser)
   args = parser.parse_args((args or []))
   # Safety net. We really don't want to send something to a real endpoint.
   self.assertTrue((args.event_mon_run_type not in ('test', 'prod'))
                   or args.dry_run)
   event_mon.process_argparse_options(args)
   r = config._router
   self.assertIsInstance(r, router._Router)
   # Check that process_argparse_options is idempotent
   event_mon.process_argparse_options(args)
   self.assertIs(config._router, r)
Ejemplo n.º 4
0
def main(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('--master-name', help='Buildbot master name')
    parser.add_argument('--builder-name', help='Buildbot builder name')
    parser.add_argument('--build-id', help='Build ID (buildnumber)')
    parser.add_argument('--analyze-input',
                        help='JSON input passed to analyze',
                        type=argparse.FileType('r'))
    parser.add_argument('--analyze-output',
                        help='JSON output from analyze',
                        type=argparse.FileType('r'))
    event_mon.add_argparse_options(parser)
    args = parser.parse_args(argv)
    event_mon.process_argparse_options(args)

    try:
        return inner_main(args)
    finally:
        event_mon.close()
Ejemplo n.º 5
0
def get_arguments(argv):
    """Process command-line arguments.

  Args:
    argv (list of strings): sys.argv[1:]
  Returns:
    args (argparse.Namespace): processed command-line arguments
  """
    # This function must be testable. Put non-testable side-effects
    # in main().

    parser = argparse.ArgumentParser(
        description="""Send an event to the monitoring pipeline.

    Examples:
    run.py infra.tools.send_monitoring_event --service-event-type=START \\
                                     --service-event-revinfo <filename>

    run.py infra.tools.send_monitoring_event \\
                                     --service-event-stack-trace "<stack trace>"

    run.py infra.tools.send_monitoring_event --build-event-type=SCHEDULER \\
                                     --build-event-build-name=foo
                                     --build-event-hostname='bot.dns.name'
    """,
        formatter_class=argparse.RawTextHelpFormatter)

    # Common fields
    common_group = parser.add_argument_group('Common event options')
    common_group.add_argument(
        '--event-mon-timestamp-kind',
        choices=[kind for kind in event_mon.TIMESTAMP_KINDS if kind],
        default='POINT',
        help='General kind of event. This value is used '
        'e.g. to\nautomatically compute durations between '
        'START and STOP\nevents. Default: %(default)s')
    common_group.add_argument(
        '--event-mon-event-timestamp',
        type=int,
        help='Timestamp when the event was generated, as '
        'number of\nmilliseconds since the Unix EPOCH.'
        '\nDefaults to current time.')

    # Service event
    service_group = parser.add_argument_group('Service event options')
    type_group = service_group.add_mutually_exclusive_group()
    type_group.add_argument('--service-event-type',
                            choices=event_mon.EVENT_TYPES,
                            help='Kind of event to send.')

    type_group.add_argument(
        '--service-event-stack-trace',
        metavar='STACK_TRACE',
        help='String containing a stack trace. Sets the event'
        ' type\nto "CRASH" automatically.')

    revinfo = service_group.add_mutually_exclusive_group()
    revinfo.add_argument(
        '--service-event-revinfo',
        metavar='FILENAME',
        help='File to read revision information from, "-" means'
        '\nstandard input. The file'
        ' is supposed to contain the\noutput of'
        ' "gclient revinfo -a".')
    revinfo.add_argument('--service-event-revinfo-from-gclient',
                         action='store_true',
                         help='Calls gclient to get revision information. '
                         '\nMutually exclusive with --service-event-revinfo')

    # Build events
    build_group = parser.add_argument_group('Build event options')
    build_group.add_argument('--build-event-type',
                             choices=event_mon.BUILD_EVENT_TYPES,
                             help='Type of the build event.')
    build_group.add_argument('--build-event-hostname',
                             metavar='HOSTNAME',
                             help='Hostname of the bot running the build.')
    build_group.add_argument('--build-event-build-name',
                             metavar='BUILDER_NAME',
                             help='Builder name as known to Buildbot.')
    build_group.add_argument('--build-event-build-number',
                             type=int,
                             metavar='BUILD_NUMBER',
                             help='Build number as known to Buildbot')
    build_group.add_argument(
        '--build-event-build-scheduling-time',
        type=int,
        metavar='TIMESTAMP',
        help='Timestamp (in milliseconds since the epoch),'
        ' when the\nbuild was scheduled. Used to tell '
        'apart builds with\n identical build numbers.')
    build_group.add_argument('--build-event-step-name',
                             metavar='STEP_NAME',
                             help='Step name as known to Buildbot.')
    build_group.add_argument('--build-event-step-number',
                             type=int,
                             metavar='BUILD_NUMBER',
                             help='Step number inside the build. Zero-based.')
    build_group.add_argument('--build-event-result',
                             choices=event_mon.BUILD_RESULTS,
                             help='Result of build or step depending on '
                             'whether any \n--build-event-step-* options have '
                             'been provided or not.')

    # Read events from file
    file_group = parser.add_argument_group('Read events from file')
    file_group.add_argument(
        '--events-from-file',
        metavar='FILENAME',
        nargs='*',
        help='File containing events as json dict. This '
        'option\nis incompatible with --build-event-type and'
        '\n--service-event-type.\nSee '
        'send_event.read_events_from_file for details\n'
        'on the format. This options can be passed multiple\n'
        'times, and wildcards can be used.')
    file_group.add_argument('--delete-file-when-sent',
                            action='store_true',
                            default=False,
                            help='If all events read from a file have been '
                            'successfully\nsent to the endpoint, delete the '
                            'file. By default\nfiles are kept.')

    ts_mon.add_argparse_options(parser)
    event_mon.add_argparse_options(parser)
    infra_libs.logs.add_argparse_options(parser)

    parser.set_defaults(
        ts_mon_flush='manual',
        ts_mon_target_type='task',
        ts_mon_task_service_name='send_monitoring_event',
        ts_mon_task_job_name='manual',
    )

    args = parser.parse_args(argv)

    if args.service_event_stack_trace:
        args.service_event_type = 'CRASH'

    if args.build_event_type and args.service_event_type:
        parser.error('Only one type of event can be sent at once. '
                     'Got both --build-event-type and --service-event-type.')
    if ((args.build_event_type and args.events_from_file)
            or (args.service_event_type and args.events_from_file)):
        parser.error('--events-from-file is not compatible with either'
                     '--service-event-type or --build-event-type.')
    return args
Ejemplo n.º 6
0
def add_argparse_options(parser):
    """Add command-line arguments.

  Args:
    parser (argparse.ArgumentParser): command-line parser object.
  """
    # This function must be testable. Put non-testable side-effects
    # in process_argparse_options().
    event_mon.add_argparse_options(parser)

    # Common fields
    common_group = parser.add_argument_group('Common event options')
    common_group.add_argument(
        '--event-mon-timestamp-kind',
        choices=event_mon.TIMESTAMP_KINDS,
        help='General kind of event. This value is used '
        'e.g. to\nautomatically compute durations between '
        'START and STOP\nevents.')
    common_group.add_argument(
        '--event-mon-event-timestamp',
        type=int,
        help='Timestamp when the event was generated, as '
        'number of\nmilliseconds since the Unix EPOCH.'
        '\nDefaults to current time.')

    # Service event
    service_group = parser.add_argument_group('Service event options')
    type_group = service_group.add_mutually_exclusive_group()
    type_group.add_argument('--service-event-type',
                            choices=event_mon.EVENT_TYPES,
                            help='Kind of event to send.')

    type_group.add_argument(
        '--service-event-stack-trace',
        metavar='STACK_TRACE',
        help='String containing a stack trace. Sets the event'
        ' type\nto "CRASH" automatically.')

    revinfo = service_group.add_mutually_exclusive_group()
    revinfo.add_argument(
        '--service-event-revinfo',
        metavar='FILENAME',
        help='File to read revision information from, "-" means'
        '\nstandard input. The file'
        ' is supposed to contain the\noutput of'
        ' "gclient revinfo -a".')
    revinfo.add_argument(
        '--service-event-revinfo-from-gclient',
        action='store_true',
        help='DEPRECATED. Do not use, it will be deleted soon.')

    # Build events
    build_group = parser.add_argument_group('Build event options')
    build_group.add_argument('--build-event-type',
                             choices=event_mon.BUILD_EVENT_TYPES,
                             help='Type of the build event.')
    build_group.add_argument('--build-event-hostname',
                             metavar='HOSTNAME',
                             help='Hostname of the bot running the build.')
    build_group.add_argument('--build-event-build-name',
                             metavar='BUILDER_NAME',
                             help='Builder name as known to Buildbot.')
    build_group.add_argument('--build-event-build-number',
                             type=int,
                             metavar='BUILD_NUMBER',
                             help='Build number as known to Buildbot')
    build_group.add_argument(
        '--build-event-build-scheduling-time',
        type=int,
        metavar='TIMESTAMP',
        help='Timestamp (in milliseconds since the epoch),'
        ' when the\nbuild was scheduled. Used to tell '
        'apart builds with\n identical build numbers.')
    build_group.add_argument('--build-event-step-name',
                             metavar='STEP_NAME',
                             help='Step name as known to Buildbot.')
    build_group.add_argument('--build-event-step-text',
                             metavar='STEP_TEXT',
                             help='Step text as known to Buildbot.')
    build_group.add_argument('--build-event-step-number',
                             type=int,
                             metavar='BUILD_NUMBER',
                             help='Step number inside the build. Zero-based.')
    build_group.add_argument('--build-event-result',
                             choices=event_mon.BUILD_RESULTS,
                             help='Result of build or step depending on '
                             'whether any \n--build-event-step-* options have '
                             'been provided or not.')

    build_group.add_argument('--build-event-extra-result-code',
                             help='Extra result code. String, comma-separated '
                             'list of strings or json-encoded list of string. '
                             'Each one must be less than 20 characters long.')
    build_group.add_argument('--build-event-patch-url',
                             help='URL of the patchset that triggered build')
    build_group.add_argument('--build-event-bbucket-id',
                             help='Buildbucket ID for this build')
    build_group.add_argument('--build-event-category',
                             help='Build category, e.g. cq or git_cl_try')
    build_group.add_argument('--build-event-head-revision-git-hash',
                             help='Revision fetched from the Git repository')

    build_group.add_argument('--build-event-goma-stats-path',
                             metavar='FILENAME',
                             help='File containing a serialized GomaStats '
                             'protobuf.')
    build_group.add_argument('--build-event-goma-error',
                             choices=event_mon.GOMA_ERROR_TYPES,
                             help='Reason for no GomaStats protobuf.')
    build_group.add_argument('--build-event-goma-crash-report-id-path',
                             metavar='FILENAME',
                             help='File containing a crash report id.')

    # Read events from file
    file_group = parser.add_argument_group('Read events from file')
    file_group.add_argument(
        '--events-from-file',
        metavar='FILENAME',
        nargs='*',
        help='File containing events as json dict. This '
        'option\nis incompatible with --build-event-type and'
        '\n--service-event-type.\nSee '
        'send_event.read_events_from_file for details\n'
        'on the format. This option can be passed multiple\n'
        'times, and wildcards can be used.')
    file_group.add_argument('--delete-file-when-sent',
                            action='store_true',
                            default=False,
                            help='If all events read from a file have been '
                            'successfully\nsent to the endpoint, delete the '
                            'file. By default\nfiles are kept. This does not '
                            'affect the file pointed to by '
                            '--event-logrequest-path')

    file_group.add_argument(
        '--event-logrequest-path',
        metavar='FILENAME',
        help='File containing a serialized LogRequestLite'
        'proto, containing a single ChromeInfraEvent that '
        'will be used as the default event. Such a file can '
        'be generated by passing "file" to '
        '--event-mon-run-type.')
Ejemplo n.º 7
0
def get_arguments(argv):
    """Process command-line arguments.

  Args:
    argv (list of strings): sys.argv[1:]
  Returns:
    args (argparse.Namespace): processed command-line arguments
  """
    # This function must be testable. Put non-testable side-effects
    # in main().

    parser = argparse.ArgumentParser(
        description="""Send an event to the monitoring pipeline.

    Examples:
    run.py infra.tools.send_monitoring_event --service-event-type=START \\
                                     --service-event-revinfo <filename>

    run.py infra.tools.send_monitoring_event \\
                                     --service-event-stack-trace "<stack trace>"

    run.py infra.tools.send_monitoring_event --build-event-type=SCHEDULER \\
                                     --build-event-build-name=foo
                                     --build-event-hostname='bot.dns.name'
    """,
        formatter_class=argparse.RawTextHelpFormatter,
    )

    # Common fields
    common_group = parser.add_argument_group("Common event options")
    common_group.add_argument(
        "--event-mon-timestamp-kind",
        choices=[kind for kind in event_mon.TIMESTAMP_KINDS if kind],
        default="POINT",
        help="General kind of event. This value is used "
        "e.g. to\nautomatically compute durations between "
        "START and STOP\nevents. Default: %(default)s",
    )
    common_group.add_argument(
        "--event-mon-event-timestamp",
        type=int,
        help="Timestamp when the event was generated, as "
        "number of\nmilliseconds since the Unix EPOCH."
        "\nDefaults to current time.",
    )

    # Service event
    service_group = parser.add_argument_group("Service event options")
    type_group = service_group.add_mutually_exclusive_group()
    type_group.add_argument("--service-event-type", choices=event_mon.EVENT_TYPES, help="Kind of event to send.")

    type_group.add_argument(
        "--service-event-stack-trace",
        metavar="STACK_TRACE",
        help="String containing a stack trace. Sets the event" ' type\nto "CRASH" automatically.',
    )

    revinfo = service_group.add_mutually_exclusive_group()
    revinfo.add_argument(
        "--service-event-revinfo",
        metavar="FILENAME",
        help='File to read revision information from, "-" means'
        "\nstandard input. The file"
        " is supposed to contain the\noutput of"
        ' "gclient revinfo -a".',
    )
    revinfo.add_argument(
        "--service-event-revinfo-from-gclient",
        action="store_true",
        help="Calls gclient to get revision information. " "\nMutually exclusive with --service-event-revinfo",
    )

    # Build events
    build_group = parser.add_argument_group("Build event options")
    build_group.add_argument("--build-event-type", choices=event_mon.BUILD_EVENT_TYPES, help="Type of the build event.")
    build_group.add_argument(
        "--build-event-hostname", metavar="HOSTNAME", help="Hostname of the bot running the build."
    )
    build_group.add_argument(
        "--build-event-build-name", metavar="BUILDER_NAME", help="Builder name as known to Buildbot."
    )
    build_group.add_argument(
        "--build-event-build-number", type=int, metavar="BUILD_NUMBER", help="Build number as known to Buildbot"
    )
    build_group.add_argument(
        "--build-event-build-scheduling-time",
        type=int,
        metavar="TIMESTAMP",
        help="Timestamp (in milliseconds since the epoch),"
        " when the\nbuild was scheduled. Used to tell "
        "apart builds with\n identical build numbers.",
    )
    build_group.add_argument("--build-event-step-name", metavar="STEP_NAME", help="Step name as known to Buildbot.")
    build_group.add_argument(
        "--build-event-step-number", type=int, metavar="BUILD_NUMBER", help="Step number inside the build. Zero-based."
    )
    build_group.add_argument(
        "--build-event-result",
        choices=event_mon.BUILD_RESULTS,
        help="Result of build or step depending on "
        "whether any \n--build-event-step-* options have "
        "been provided or not.",
    )

    # Read events from file
    file_group = parser.add_argument_group("Read events from file")
    file_group.add_argument(
        "--events-from-file",
        metavar="FILENAME",
        nargs="*",
        help="File containing events as json dict. This "
        "option\nis incompatible with --build-event-type and"
        "\n--service-event-type.\nSee "
        "send_event.read_events_from_file for details\n"
        "on the format. This options can be passed multiple\n"
        "times, and wildcards can be used.",
    )
    file_group.add_argument(
        "--delete-file-when-sent",
        action="store_true",
        default=False,
        help="If all events read from a file have been "
        "successfully\nsent to the endpoint, delete the "
        "file. By default\nfiles are kept.",
    )

    ts_mon.add_argparse_options(parser)
    event_mon.add_argparse_options(parser)
    infra_libs.logs.add_argparse_options(parser)

    parser.set_defaults(
        ts_mon_flush="manual",
        ts_mon_target_type="task",
        ts_mon_task_service_name="send_monitoring_event",
        ts_mon_task_job_name="manual",
    )

    args = parser.parse_args(argv)

    if args.service_event_stack_trace:
        args.service_event_type = "CRASH"

    if args.build_event_type and args.service_event_type:
        parser.error(
            "Only one type of event can be sent at once. " "Got both --build-event-type and --service-event-type."
        )
    if (args.build_event_type and args.events_from_file) or (args.service_event_type and args.events_from_file):
        parser.error("--events-from-file is not compatible with either" "--service-event-type or --build-event-type.")
    return args
Ejemplo n.º 8
0
def get_arguments(argv):
  """Process command-line arguments.

  Args:
    argv (list of strings): sys.argv[1:]
  Returns:
    args (argparse.Namespace): processed command-line arguments
  """
  # This function must be testable. Put non-testable side-effects
  # in main().

  parser = argparse.ArgumentParser(
    description="""Send an event to the monitoring pipeline.

    Examples:
    run.py infra.tools.send_monitoring_event --service-event-type=START \\
                                     --service-event-revinfo <filename>

    run.py infra.tools.send_monitoring_event \\
                                     --service-event-stack-trace "<stack trace>"

    run.py infra.tools.send_monitoring_event --build-event-type=SCHEDULER \\
                                     --build-event-build-name=foo
                                     --build-event-hostname='bot.dns.name'
    """, formatter_class=argparse.RawTextHelpFormatter)

  # Common fields
  common_group = parser.add_argument_group('Common event options')
  common_group.add_argument('--event-mon-timestamp-kind',
                            choices=event_mon.TIMESTAMP_KINDS,
                            help='General kind of event. This value is used '
                            'e.g. to\nautomatically compute durations between '
                            'START and STOP\nevents.')
  common_group.add_argument('--event-mon-event-timestamp', type=int,
                            help='Timestamp when the event was generated, as '
                            'number of\nmilliseconds since the Unix EPOCH.'
                            '\nDefaults to current time.')

  # Service event
  service_group = parser.add_argument_group('Service event options')
  type_group = service_group.add_mutually_exclusive_group()
  type_group.add_argument('--service-event-type',
                          choices=event_mon.EVENT_TYPES,
                          help='Kind of event to send.')

  type_group.add_argument('--service-event-stack-trace',
                          metavar='STACK_TRACE',
                          help='String containing a stack trace. Sets the event'
                          ' type\nto "CRASH" automatically.')

  revinfo = service_group.add_mutually_exclusive_group()
  revinfo.add_argument('--service-event-revinfo',
                       metavar='FILENAME',
                       help='File to read revision information from, "-" means'
                       '\nstandard input. The file'
                       ' is supposed to contain the\noutput of'
                       ' "gclient revinfo -a".')
  revinfo.add_argument('--service-event-revinfo-from-gclient',
                       action='store_true',
                       help='Calls gclient to get revision information. '
                       '\nMutually exclusive with --service-event-revinfo')

  # Build events
  build_group = parser.add_argument_group('Build event options')
  build_group.add_argument('--build-event-type',
                           choices=event_mon.BUILD_EVENT_TYPES,
                           help='Type of the build event.')
  build_group.add_argument('--build-event-hostname',
                           metavar='HOSTNAME',
                           help='Hostname of the bot running the build.')
  build_group.add_argument('--build-event-build-name',
                           metavar='BUILDER_NAME',
                           help='Builder name as known to Buildbot.')
  build_group.add_argument('--build-event-build-number',
                           type=int,
                           metavar='BUILD_NUMBER',
                           help='Build number as known to Buildbot')
  build_group.add_argument('--build-event-build-scheduling-time',
                           type=int,
                           metavar='TIMESTAMP',
                           help='Timestamp (in milliseconds since the epoch),'
                           ' when the\nbuild was scheduled. Used to tell '
                           'apart builds with\n identical build numbers.')
  build_group.add_argument('--build-event-step-name',
                           metavar='STEP_NAME',
                           help='Step name as known to Buildbot.')
  build_group.add_argument('--build-event-step-number',
                           type=int,
                           metavar='BUILD_NUMBER',
                           help='Step number inside the build. Zero-based.')
  build_group.add_argument('--build-event-result',
                           choices=event_mon.BUILD_RESULTS,
                           help='Result of build or step depending on '
                           'whether any \n--build-event-step-* options have '
                           'been provided or not.')

  build_group.add_argument('--build-event-extra-result-code',
                           help='Extra result code. String, comma-separated '
                           'list of strings or json-encoded list of string. '
                           'Each one must be less than 20 characters long.')
  build_group.add_argument('--build-event-patch-url',
                           help='URL of the patchset that triggered build')

  build_group.add_argument('--build-event-goma-stats-path',
                           metavar='FILENAME',
                           help='File containing a serialized GomaStats '
                           'protobuf.')
  build_group.add_argument('--build-event-goma-error',
                           choices=event_mon.GOMA_ERROR_TYPES,
                           help='Reason for no GomaStats protobuf.')
  build_group.add_argument('--build-event-goma-crash-report-id-path',
                           metavar='FILENAME',
                           help='File containing a crash report id.')

  # Read events from file
  file_group = parser.add_argument_group('Read events from file')
  file_group.add_argument('--events-from-file',
                          metavar='FILENAME', nargs='*',
                          help='File containing events as json dict. This '
                          'option\nis incompatible with --build-event-type and'
                          '\n--service-event-type.\nSee '
                          'send_event.read_events_from_file for details\n'
                          'on the format. This option can be passed multiple\n'
                          'times, and wildcards can be used.')
  file_group.add_argument('--delete-file-when-sent',
                          action='store_true', default=False,
                          help='If all events read from a file have been '
                          'successfully\nsent to the endpoint, delete the '
                          'file. By default\nfiles are kept. This does not '
                          'affect the file pointed to by '
                          '--event-logrequest-path')

  file_group.add_argument('--event-logrequest-path',
                          metavar='FILENAME',
                          help='File containing a serialized LogRequestLite'
                          'proto, containing a single ChromeInfraEvent that '
                          'will be used as the default event. Such a file can '
                          'be generated by passing "file" to '
                          '--event-mon-run-type.')

  ts_mon.add_argparse_options(parser)
  event_mon.add_argparse_options(parser)
  infra_libs.logs.add_argparse_options(parser)

  parser.set_defaults(
      ts_mon_flush='manual',
      ts_mon_target_type='task',
      ts_mon_task_service_name='send_monitoring_event',
      ts_mon_task_job_name='manual',
  )

  args = parser.parse_args(argv)

  if args.service_event_stack_trace:
    args.service_event_type = 'CRASH'

  if args.build_event_type and args.service_event_type:
    parser.error('Only one type of event can be sent at once. '
                 'Got both --build-event-type and --service-event-type.')
  if ((args.build_event_type and args.events_from_file)
      or (args.service_event_type and args.events_from_file)):
    parser.error('--events-from-file is not compatible with either'
                 '--service-event-type or --build-event-type.')

  # Convert extra_result_code to a list when needed.
  if args.build_event_extra_result_code:
    extra_result_code = args.build_event_extra_result_code.strip()
    if extra_result_code.startswith('['):
      extra_result_code = json.loads(extra_result_code)
    elif ',' in extra_result_code:
      extra_result_code = extra_result_code.split(',')
    args.build_event_extra_result_code = extra_result_code

  return args