Пример #1
0
    def scribe_get_from_time(self, scribe_env, stream_name, start_time,
                             end_time):
        # Scribe connection details
        host_and_port = scribereader.get_env_scribe_host(scribe_env,
                                                         tail=False)
        host = host_and_port['host']
        port = host_and_port['port']

        # Recent logs might not be archived yet. Log warning message.
        warning_end_time = datetime.datetime.utcnow().replace(
            tzinfo=pytz.utc) - datetime.timedelta(hours=4)
        if end_time > warning_end_time:
            log.warn(
                "Recent logs might be incomplete. Consider tailing instead.")

        # scribereader, sadly, is not based on UTC timestamps. It uses YST
        # dates instead.
        start_date_yst = start_time.astimezone(
            pytz.timezone('America/Los_Angeles')).date()
        end_date_yst = end_time.astimezone(
            pytz.timezone('America/Los_Angeles')).date()

        log.debug(
            "Running the equivalent of 'scribereader -e %s %s --min-date %s --max-date %s"
            % (scribe_env, stream_name, start_date_yst, end_date_yst))
        return scribereader.get_stream_reader(
            stream_name=stream_name,
            reader_host=host,
            reader_port=port,
            min_date=start_date_yst,
            max_date=end_date_yst,
        )
Пример #2
0
    def scribe_get_from_time(self, scribe_env, stream_name, start_time,
                             end_time):
        # Scribe connection details
        host_and_port = scribereader.get_env_scribe_host(scribe_env, True)
        host = host_and_port['host']
        port = host_and_port['port']

        # Annoyingly enough, scribe needs special handling if we're trying to retrieve logs from today.

        # There is a datetime.date.today but we can't use it because it isn't UTC
        today = datetime.datetime.utcnow().date()
        if start_time.date() == today or end_time.date() == today:
            # The reason we need a fake context here is because scribereader is a bit incosistent in its
            # returns. get_stream_reader returns a context that needs to be acquired for cleanup code but
            # get_stream_tailer simply returns an object that can be iterated over. We'd still like to have
            # the cleanup code for get_stream_reader to be executed by this function's caller and this is
            # one of the simpler ways to achieve it without having 2 if statements everywhere that calls
            # this method
            @contextmanager
            def fake_context():
                log.info(
                    "Running the equivalent of 'scribereader -f -e %s %s" %
                    (scribe_env, stream_name))
                yield scribereader.get_stream_tailer(stream_name, host, port,
                                                     True, -1)

            return fake_context()

        log.info("Running the equivalent of 'scribereader -e %s %s" %
                 (scribe_env, stream_name))
        return scribereader.get_stream_reader(stream_name, host, port,
                                              start_time, end_time)
Пример #3
0
    def scribe_get_from_time(self, scribe_env, stream_name, start_time, end_time):
        # Scribe connection details
        host_and_port = scribereader.get_env_scribe_host(scribe_env, True)
        host = host_and_port["host"]
        port = host_and_port["port"]

        # Annoyingly enough, scribe needs special handling if we're trying to retrieve logs from today.

        # There is a datetime.date.today but we can't use it because it isn't UTC
        today = datetime.datetime.utcnow().date()
        if start_time.date() == today or end_time.date() == today:
            # The reason we need a fake context here is because scribereader is a bit incosistent in its
            # returns. get_stream_reader returns a context that needs to be acquired for cleanup code but
            # get_stream_tailer simply returns an object that can be iterated over. We'd still like to have
            # the cleanup code for get_stream_reader to be executed by this function's caller and this is
            # one of the simpler ways to achieve it without having 2 if statements everywhere that calls
            # this method
            @contextmanager
            def fake_context():
                log.info("Running the equivalent of 'scribereader -f -e %s %s" % (scribe_env, stream_name))
                yield scribereader.get_stream_tailer(stream_name, host, port, True, -1)

            return fake_context()

        log.info("Running the equivalent of 'scribereader -e %s %s" % (scribe_env, stream_name))
        return scribereader.get_stream_reader(stream_name, host, port, start_time, end_time)