11import json
2+ from datetime import datetime
23from xml .etree import ElementTree as ET
34
45import pytest
56
7+
68from helpers .cluster import ClickHouseCluster
79
810cluster = 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+
6171def 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