mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Merge pull request #3 from xogoodnow/json-utc-formatted-log-tests
Add 'date_time_utc' format to tests
This commit is contained in:
commit
146f3b5bef
@ -1,8 +1,10 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
from xml.etree import ElementTree as ET
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
from helpers.cluster import ClickHouseCluster
|
||||
|
||||
cluster = ClickHouseCluster(__file__)
|
||||
@ -58,12 +60,21 @@ def validate_log_level(config, logs):
|
||||
return True
|
||||
|
||||
|
||||
def is_valid_utc_datetime(datetime_str):
|
||||
try:
|
||||
datetime_obj = datetime.strptime(datetime_str, "%Y-%m-%dT%H:%M:%S.%fZ")
|
||||
return datetime_obj.tzinfo is None
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
def validate_log_config_relation(config, logs, config_type):
|
||||
root = ET.fromstring(config)
|
||||
keys_in_config = set()
|
||||
|
||||
if config_type == "config_no_keys":
|
||||
keys_in_config.add("date_time")
|
||||
keys_in_config.add("date_time_utc")
|
||||
keys_in_config.add("thread_name")
|
||||
keys_in_config.add("thread_id")
|
||||
keys_in_config.add("level")
|
||||
@ -85,9 +96,12 @@ def validate_log_config_relation(config, logs, config_type):
|
||||
keys_in_log.add(log_key)
|
||||
if log_key not in keys_in_config:
|
||||
return False
|
||||
for config_key in keys_in_config:
|
||||
if config_key not in keys_in_log:
|
||||
return False
|
||||
|
||||
# Validate the UTC datetime format in "date_time_utc" if it exists
|
||||
if "date_time_utc" in json_log and not is_valid_utc_datetime(
|
||||
json_log["date_time_utc"]
|
||||
):
|
||||
return False
|
||||
except ValueError as e:
|
||||
return False
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user