2021-10-04 09:25:42 +00:00
|
|
|
import pytest
|
|
|
|
import re
|
|
|
|
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
2022-07-18 12:25:14 +00:00
|
|
|
cluster = ClickHouseCluster(__file__)
|
2022-08-24 16:14:30 +00:00
|
|
|
node = cluster.add_instance(
|
|
|
|
"node", with_zookeeper=False, main_configs=["configs/log.xml"]
|
|
|
|
)
|
2021-10-04 09:25:42 +00:00
|
|
|
|
2021-10-26 05:53:23 +00:00
|
|
|
config = """<clickhouse>
|
2021-10-04 09:25:42 +00:00
|
|
|
<logger>
|
2023-03-01 23:35:09 +00:00
|
|
|
<level>debug</level>
|
2021-10-04 09:25:42 +00:00
|
|
|
<log>/var/log/clickhouse-server/clickhouse-server.log</log>
|
|
|
|
</logger>
|
2021-10-26 05:53:23 +00:00
|
|
|
</clickhouse>"""
|
2021-10-04 09:25:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def get_log(node):
|
|
|
|
return node.exec_in_container(
|
|
|
|
["bash", "-c", "cat /var/log/clickhouse-server/clickhouse-server.log"]
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2021-10-04 09:25:42 +00:00
|
|
|
|
2022-08-24 15:49:15 +00:00
|
|
|
def check_it_will_work_slowly(node, log):
|
|
|
|
it_will_work_slowly = "It will work slowly"
|
|
|
|
if node.is_built_with_sanitizer() or node.is_debug_build():
|
|
|
|
# message still in logs
|
|
|
|
re.search(f"<Warning>.*{it_will_work_slowly}", log)
|
|
|
|
# but not in system.warnings
|
|
|
|
query = f"SELECT count() FROM system.warnings WHERE message ILIKE '%{it_will_work_slowly}%'"
|
|
|
|
assert 0 == int(node.query(query).strip())
|
|
|
|
|
|
|
|
|
2021-10-04 09:25:42 +00:00
|
|
|
def test_log_levels_update(start_cluster):
|
|
|
|
# Make sure that there are enough log messages for the test
|
2022-08-24 15:49:15 +00:00
|
|
|
for _ in range(5):
|
2021-10-04 09:25:42 +00:00
|
|
|
node.query("SELECT 1")
|
|
|
|
|
|
|
|
log = get_log(node)
|
|
|
|
assert re.search("(<Trace>|<Debug>)", log)
|
|
|
|
|
2022-08-24 15:49:15 +00:00
|
|
|
check_it_will_work_slowly(node, log)
|
|
|
|
|
2021-10-04 09:25:42 +00:00
|
|
|
node.replace_config("/etc/clickhouse-server/config.d/log.xml", config)
|
|
|
|
node.query("SYSTEM RELOAD CONFIG;")
|
|
|
|
node.exec_in_container(
|
|
|
|
["bash", "-c", "> /var/log/clickhouse-server/clickhouse-server.log"]
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2022-08-24 15:49:15 +00:00
|
|
|
for _ in range(5):
|
2021-10-04 09:25:42 +00:00
|
|
|
node.query("SELECT 1")
|
|
|
|
|
|
|
|
log = get_log(node)
|
|
|
|
assert len(log) > 0
|
2023-03-02 14:31:38 +00:00
|
|
|
assert not re.search("<Trace>", log)
|