Skip to content

Commit

Permalink
Fix timestamp parsing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
maddieford committed Jul 10, 2023
1 parent 3a21a12 commit 603c90b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tests_e2e/tests/lib/agent_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@ def from_dictionary(dictionary: Dict[str, str]):

@property
def timestamp(self) -> datetime:
# Logs from the DcrTestExtension follows this format: 2023/07/10 20:50:13
dcr_test_ext_timestamp_regex = r"\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}[.\d]*"
if re.match(dcr_test_ext_timestamp_regex, self.when):
# Extension logs may follow different timestamp formats
# 2023/07/10 20:50:13
ext_timestamp_regex_1 = r"\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}"
# 2023/07/10 20:50:13.459260
ext_timestamp_regex_2 = r"\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}[.\d]*"

if re.match(ext_timestamp_regex_1, self.when):
return datetime.strptime(self.when, u'%Y/%m/%d %H:%M:%S')
elif re.match(ext_timestamp_regex_2, self.when):
return datetime.strptime(self.when, u'%Y/%m/%d %H:%M:%S.%f')
# Logs from agent follow this format: 2023-07-10T20:50:13.038599Z
return datetime.strptime(self.when, u'%Y-%m-%dT%H:%M:%S.%fZ')

Expand Down

0 comments on commit 603c90b

Please sign in to comment.