def process_log_line( cls, value: Text, node: Optional[str], pod: Optional[str], container: Optional[str], timestamp=None, ) -> "V1Log": if not value: return None if not isinstance(value, str): value = value.decode("utf-8") value = value.strip() if not timestamp: value, timestamp = timestamp_search_regex(ISO_DATETIME_REGEX, value) if not timestamp: value, timestamp = timestamp_search_regex(DATETIME_REGEX, value) if isinstance(timestamp, str): try: timestamp = dt_parser.parse(timestamp) except Exception as e: raise ValidationError("Received an invalid timestamp") from e return cls( timestamp=timestamp if timestamp else now(tzinfo=True), node=node, pod=pod, container=container, value=value, )
def test_log_line_has_iso_datetime(self): log_line = "2018-12-11T08:49:07.163495183Z foo" log_value, ts = timestamp_search_regex(ISO_DATETIME_REGEX, log_line) assert ts == dt_parser.parse("2018-12-11T08:49:07.163495183Z") assert log_value == "foo"
def test_log_line_has_datetime(self): log_line = "2018-12-11 10:24:57 UTC foo" log_value, ts = timestamp_search_regex(DATETIME_REGEX, log_line) assert ts == dt_parser.parse("2018-12-11 10:24:57 UTC") assert log_value == "foo"
def test_has_timestamp(self): log_line = "2018-12-11 10:24:57 UTC" log_value, ts = timestamp_search_regex(DATETIME_REGEX, log_line) assert ts == parse_datetime("2018-12-11 10:24:57 UTC") assert log_value == ""