Пример #1
0
def test_buffer_not_full() -> None:
    logfile = PyctuatorLogfile(test_buffer_size, "%(message)s")

    msg_num = "0123456789" * 50
    record = logging.LogRecord("test record", logging.WARNING, "", 0, msg_num,
                               (), None)
    logfile.log_messages.emit(record)

    log, start, end = logfile.get_logfile(f"bytes=-{2 * test_buffer_size}")
    assert start == 0
    assert end == len(log) == len(msg_num + "\n")
Пример #2
0
    def __init__(
        self,
        app_info: AppInfo,
        pyctuator_endpoint_url: str,
        logfile_max_size: int,
        logfile_formatter: str,
    ):
        self.app_info = app_info
        self.pyctuator_endpoint_url = pyctuator_endpoint_url

        self.metrics_providers: List[MetricsProvider] = []
        self.health_providers: List[HealthProvider] = []
        self.environment_providers: List[EnvironmentProvider] = []
        self.logging = PyctuatorLogging()
        self.thread_dump_provider = ThreadDumpProvider()
        self.logfile = PyctuatorLogfile(max_size=logfile_max_size,
                                        formatter=logfile_formatter)
        self.http_tracer = HttpTracer()

        # Determine the endpoint's URL path prefix and make sure it doesn't end with a "/"
        self.pyctuator_endpoint_path_prefix = urlparse(
            pyctuator_endpoint_url).path
        if self.pyctuator_endpoint_path_prefix[-1:] == "/":
            self.pyctuator_endpoint_path_prefix = self.pyctuator_endpoint_path_prefix[:
                                                                                      -1]
Пример #3
0
def test_forgotten_records() -> None:
    logfile = PyctuatorLogfile(test_buffer_size, "%(message)s")

    msg_chr = "ABCDEFGHIJ"
    record = logging.LogRecord("test record", logging.WARNING, "", 0, msg_chr,
                               (), None)
    logfile.log_messages.emit(record)

    msg_num = "0123456789" * 100  # test_buffer_size
    record = logging.LogRecord("test record", logging.WARNING, "", 0, msg_num,
                               (), None)
    logfile.log_messages.emit(record)

    log, start, end = logfile.get_logfile(f"bytes=-{2 * test_buffer_size}")
    assert log.count("ABCDEFGHIJ") == 0
    assert start == logfile.get_log_buffer_offset()
    assert end == start + len(log)
Пример #4
0
def test_buffer_overflow() -> None:
    logfile = PyctuatorLogfile(test_buffer_size, "%(message)s")

    msg_num = "0123456789" * 10
    record = logging.LogRecord("test record", logging.WARNING, "", 0, msg_num,
                               (), None)
    logfile.log_messages.emit(record)

    msg_chr = "ABCDEFGHIJ" * 95
    record = logging.LogRecord("test record", logging.WARNING, "", 0, msg_chr,
                               (), None)
    logfile.log_messages.emit(record)

    log, start, end = logfile.get_logfile(f"bytes=-{2 * test_buffer_size}")
    assert log.count(
        "0123456789"
    ) == 4  # Implicitly Added newlines "break" a single string appearance
    assert start == logfile.get_log_buffer_offset()
    assert end == start + len(log)
Пример #5
0
def test_empty_response() -> None:
    logfile = PyctuatorLogfile(test_buffer_size, default_logfile_format)
    log, start, end = logfile.get_logfile(f"bytes=-{2 * test_buffer_size}")
    assert log == ""
    assert start == 0
    assert end == 0