2024-10-15 03:16:18 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
node = cluster.add_instance(
|
|
|
|
"node", with_zookeeper=False, main_configs=["configs/log.xml"]
|
|
|
|
)
|
|
|
|
|
2024-10-18 07:50:25 +00:00
|
|
|
original_config = """
|
|
|
|
<clickhouse>
|
|
|
|
<logger>
|
|
|
|
<level>trace</level>
|
|
|
|
<log>/var/log/clickhouse-server/clickhouse-server.log</log>
|
|
|
|
</logger>
|
|
|
|
</clickhouse>
|
|
|
|
"""
|
|
|
|
|
2024-10-15 15:43:51 +00:00
|
|
|
updated_config = """
|
|
|
|
<clickhouse>
|
2024-10-15 03:16:18 +00:00
|
|
|
<logger>
|
|
|
|
<level>trace</level>
|
|
|
|
<log>/var/log/clickhouse-server/clickhouse-server.log</log>
|
2024-10-18 07:50:25 +00:00
|
|
|
<message_regexp_negative>.*Loaded config.*</message_regexp_negative>
|
2024-10-15 15:43:51 +00:00
|
|
|
<message_regexps>
|
|
|
|
<logger>
|
|
|
|
<name>executeQuery</name>
|
|
|
|
<message_regexp>.*Read.*</message_regexp>
|
|
|
|
<message_regexp_negative>.*from.*</message_regexp_negative>
|
|
|
|
</logger>
|
|
|
|
</message_regexps>
|
2024-10-15 03:16:18 +00:00
|
|
|
</logger>
|
2024-10-15 15:43:51 +00:00
|
|
|
</clickhouse>
|
|
|
|
"""
|
2024-10-15 03:16:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
2024-10-15 15:43:51 +00:00
|
|
|
def test_regexp_pattern_update(start_cluster):
|
2024-10-18 07:50:25 +00:00
|
|
|
# Display config being used
|
|
|
|
node.exec_in_container(["cat", "/etc/clickhouse-server/config.d/log.xml"])
|
|
|
|
|
2024-10-15 03:16:18 +00:00
|
|
|
# Make sure that there are enough log messages for the test
|
|
|
|
for _ in range(5):
|
2024-10-18 07:50:25 +00:00
|
|
|
node.query("SYSTEM RELOAD CONFIG")
|
2024-10-15 03:16:18 +00:00
|
|
|
node.query("SELECT 1")
|
|
|
|
|
2024-10-21 18:44:11 +00:00
|
|
|
assert node.contains_in_log(r".*Loaded config.*")
|
|
|
|
assert node.contains_in_log(r".*executeQuery.*Read.*")
|
|
|
|
assert node.contains_in_log(r".*executeQuery.*from.*")
|
2024-10-15 03:16:18 +00:00
|
|
|
|
2024-10-15 15:43:51 +00:00
|
|
|
node.replace_config("/etc/clickhouse-server/config.d/log.xml", updated_config)
|
2024-10-15 03:16:18 +00:00
|
|
|
node.query("SYSTEM RELOAD CONFIG;")
|
2024-10-21 18:44:11 +00:00
|
|
|
node.rotate_logs()
|
2024-10-15 03:16:18 +00:00
|
|
|
|
|
|
|
for _ in range(5):
|
2024-10-18 07:50:25 +00:00
|
|
|
node.query("SYSTEM RELOAD CONFIG")
|
2024-10-15 03:16:18 +00:00
|
|
|
node.query("SELECT 1")
|
|
|
|
|
2024-10-21 18:44:11 +00:00
|
|
|
assert not node.contains_in_log(r".*Loaded config.*")
|
|
|
|
assert node.contains_in_log(r".*executeQuery.*Read.*")
|
|
|
|
assert not node.contains_in_log(r".*executeQuery.*from.*")
|
2024-10-18 07:50:25 +00:00
|
|
|
|
|
|
|
node.replace_config("/etc/clickhouse-server/config.d/log.xml", original_config)
|