Skip to content

Commit 146f3b5

Browse files
authored
Merge pull request #3 from xogoodnow/json-utc-formatted-log-tests
Add 'date_time_utc' format to tests
2 parents 25f73df + 9ac9dea commit 146f3b5

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

  • tests/integration/test_structured_logging_json

tests/integration/test_structured_logging_json/test.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import json
2+
from datetime import datetime
23
from xml.etree import ElementTree as ET
34

45
import pytest
56

7+
68
from helpers.cluster import ClickHouseCluster
79

810
cluster = ClickHouseCluster(__file__)
@@ -58,12 +60,21 @@ def validate_log_level(config, logs):
5860
return True
5961

6062

63+
def is_valid_utc_datetime(datetime_str):
64+
try:
65+
datetime_obj = datetime.strptime(datetime_str, "%Y-%m-%dT%H:%M:%S.%fZ")
66+
return datetime_obj.tzinfo is None
67+
except ValueError:
68+
return False
69+
70+
6171
def validate_log_config_relation(config, logs, config_type):
6272
root = ET.fromstring(config)
6373
keys_in_config = set()
6474

6575
if config_type == "config_no_keys":
6676
keys_in_config.add("date_time")
77+
keys_in_config.add("date_time_utc")
6778
keys_in_config.add("thread_name")
6879
keys_in_config.add("thread_id")
6980
keys_in_config.add("level")
@@ -85,9 +96,12 @@ def validate_log_config_relation(config, logs, config_type):
8596
keys_in_log.add(log_key)
8697
if log_key not in keys_in_config:
8798
return False
88-
for config_key in keys_in_config:
89-
if config_key not in keys_in_log:
90-
return False
99+
100+
# Validate the UTC datetime format in "date_time_utc" if it exists
101+
if "date_time_utc" in json_log and not is_valid_utc_datetime(
102+
json_log["date_time_utc"]
103+
):
104+
return False
91105
except ValueError as e:
92106
return False
93107
return True

0 commit comments

Comments
 (0)