def _send_to_endpoint(self, events): try: for ev in events.log_event: ev_str = str(ChromeInfraEvent.FromString(ev.source_extension)) logging.log(self.severity, 'Sending event_mon event:\n%s' % ev_str) except Exception: logging.exception('Unable to log the events') return False return True
def _send_to_endpoint(self, events): # Prints individual events because it's what we're usually interested in # in that case. infra_events = [ str(ChromeInfraEvent.FromString(ev.source_extension)) for ev in events.log_event ] try: self.stream.write('%s\n' % '\n'.join(infra_events)) except Exception: logging.exception('Unable to write to provided stream') return False return True
def process_argparse_options(args): """Sets the default event based on --event-logrequest-path. This function raises exceptions because if the base event is wrong, then it's not worth sending anything anyway. """ event_mon.process_argparse_options(args) _extra_argument_checking(args) if args.event_logrequest_path: try: with open(args.event_logrequest_path, 'rb') as f: request = LogRequestLite.FromString(f.read()) if len(request.log_event) == 1: default_event = ChromeInfraEvent.FromString( request.log_event[0].source_extension) # Assume that the content is sane because we don't want to duplicate # any business logic here. # TODO(pgervais): find a better solution. event_mon.set_default_event(default_event) else: raise ValueError( 'Expected only one log_event in the LogRequestLite proto ' 'pointed by --event-logrequest-path. Found %d in %s', len(request.log_event), args.event_logrequest_path) except Exception: LOGGER.exception('Failure when reading/parsing file %s', args.event_logrequest_path) raise default_event = event_mon.get_default_event() # When the default event is set using --event-logrequest-path, passing # --build-event-type or --service-event-type is optional. These options # still takes precedence but they must keep the event type the same. if (default_event.build_event.HasField('type') and default_event.service_event.HasField('type')): msg = ( 'Default event contains both service_event_type and ' 'build_event_type which is incorrect. Make sure you passed ' 'a correct proto to --event-logrequest-path. Otherwise it\'s an ' 'internal error. Aborting.') LOGGER.error(msg) raise ValueError(msg) if default_event.build_event.HasField('type'): if args.service_event_type: msg = ( 'The default event contains a type for build_event, but a ' 'service_event type was provided on the command-line. At most ' 'one of them can be specified. Aborting.') LOGGER.error(msg) raise ValueError(msg) if not args.build_event_type: args.build_event_type = event_mon.BuildEvent.BuildEventType.Name( default_event.build_event.type) if default_event.service_event.HasField('type'): if args.build_event_type: msg = ( 'The default event contains a type for service_event, but a ' 'build_event type was provided on the command-line. At most ' 'one of them can be specified. Aborting.') LOGGER.error(msg) raise ValueError(msg) if not args.service_event_type: args.service_event_type = event_mon.ServiceEvent.ServiceEventType.Name( default_event.service_event.type)