2020-06-09 18:11:08 +00:00
|
|
|
# pylint: disable=line-too-long
|
|
|
|
# pylint: disable=unused-argument
|
|
|
|
# pylint: disable=redefined-outer-name
|
|
|
|
|
2023-07-28 07:23:34 +00:00
|
|
|
import time
|
2020-06-09 18:11:08 +00:00
|
|
|
import pytest
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
2023-07-28 07:23:34 +00:00
|
|
|
from helpers.test_tools import assert_eq_with_retry
|
2020-06-09 18:11:08 +00:00
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
2023-07-28 07:23:34 +00:00
|
|
|
node = cluster.add_instance(
|
|
|
|
"node_default",
|
|
|
|
stay_alive=True,
|
|
|
|
)
|
2020-06-09 18:11:08 +00:00
|
|
|
|
|
|
|
system_logs = [
|
|
|
|
# disabled by default
|
2022-03-22 16:39:58 +00:00
|
|
|
("system.text_log", 0),
|
2020-06-09 18:11:08 +00:00
|
|
|
# enabled by default
|
2022-03-22 16:39:58 +00:00
|
|
|
("system.query_log", 1),
|
|
|
|
("system.query_thread_log", 1),
|
|
|
|
("system.part_log", 1),
|
|
|
|
("system.trace_log", 1),
|
|
|
|
("system.metric_log", 1),
|
2020-06-09 18:11:08 +00:00
|
|
|
]
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
@pytest.fixture(scope="module", autouse=True)
|
2020-06-09 18:11:08 +00:00
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
@pytest.fixture(scope="function")
|
2020-06-09 18:11:08 +00:00
|
|
|
def flush_logs():
|
2022-03-22 16:39:58 +00:00
|
|
|
node.query("SYSTEM FLUSH LOGS")
|
2020-06-09 18:11:08 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
@pytest.mark.parametrize("table,exists", system_logs)
|
2020-06-09 18:11:08 +00:00
|
|
|
def test_system_logs(flush_logs, table, exists):
|
2022-03-22 16:39:58 +00:00
|
|
|
q = "SELECT * FROM {}".format(table)
|
2020-06-09 18:11:08 +00:00
|
|
|
if exists:
|
|
|
|
node.query(q)
|
|
|
|
else:
|
2023-08-08 19:54:07 +00:00
|
|
|
response = node.query_and_get_error(q)
|
2023-08-08 20:06:59 +00:00
|
|
|
assert (
|
2023-08-11 10:24:16 +00:00
|
|
|
"Table {} does not exist".format(table) in response
|
2023-08-08 20:06:59 +00:00
|
|
|
or "Unknown table expression identifier '{}'".format(table) in response
|
|
|
|
)
|
2020-06-09 18:11:08 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2020-06-09 18:11:08 +00:00
|
|
|
# Logic is tricky, let's check that there is no hang in case of message queue
|
|
|
|
# is not empty (this is another code path in the code).
|
|
|
|
def test_system_logs_non_empty_queue():
|
2022-03-22 16:39:58 +00:00
|
|
|
node.query(
|
|
|
|
"SELECT 1",
|
|
|
|
settings={
|
|
|
|
# right now defaults are the same,
|
|
|
|
# this set explicitly to avoid depends from defaults.
|
|
|
|
"log_queries": 1,
|
|
|
|
"log_queries_min_type": "QUERY_START",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
node.query("SYSTEM FLUSH LOGS")
|
2021-12-10 17:58:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_system_suspend():
|
|
|
|
node.query("CREATE TABLE t (x DateTime) ENGINE=Memory;")
|
|
|
|
node.query("INSERT INTO t VALUES (now());")
|
|
|
|
node.query("SYSTEM SUSPEND FOR 1 SECOND;")
|
|
|
|
node.query("INSERT INTO t VALUES (now());")
|
|
|
|
assert "1\n" == node.query("SELECT max(x) - min(x) >= 1 FROM t;")
|
2023-07-28 07:23:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_log_max_size(start_cluster):
|
|
|
|
node.exec_in_container(
|
|
|
|
[
|
|
|
|
"bash",
|
|
|
|
"-c",
|
|
|
|
f"""echo "
|
|
|
|
<clickhouse>
|
|
|
|
<query_log>
|
|
|
|
<flush_interval_milliseconds replace=\\"replace\\">1000000</flush_interval_milliseconds>
|
|
|
|
<max_size_rows replace=\\"replace\\">10</max_size_rows>
|
|
|
|
<reserved_size_rows replace=\\"replace\\">10</reserved_size_rows>
|
|
|
|
</query_log>
|
|
|
|
</clickhouse>
|
|
|
|
" > /etc/clickhouse-server/config.d/yyy-override-query_log.xml
|
|
|
|
""",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
node.restart_clickhouse()
|
|
|
|
for i in range(10):
|
|
|
|
node.query(f"select {i}")
|
|
|
|
|
|
|
|
assert node.query("select count() >= 10 from system.query_log") == "1\n"
|
|
|
|
node.exec_in_container(
|
|
|
|
["rm", f"/etc/clickhouse-server/config.d/yyy-override-query_log.xml"]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_log_buffer_size_rows_flush_threshold(start_cluster):
|
|
|
|
node.exec_in_container(
|
|
|
|
[
|
|
|
|
"bash",
|
|
|
|
"-c",
|
|
|
|
f"""echo "
|
|
|
|
<clickhouse>
|
|
|
|
<query_log>
|
|
|
|
<flush_interval_milliseconds replace=\\"replace\\">1000000</flush_interval_milliseconds>
|
|
|
|
<buffer_size_rows_flush_threshold replace=\\"replace\\">10</buffer_size_rows_flush_threshold>
|
|
|
|
<max_size_rows replace=\\"replace\\">10000</max_size_rows>
|
|
|
|
</query_log>
|
|
|
|
</clickhouse>
|
|
|
|
" > /etc/clickhouse-server/config.d/yyy-override-query_log.xml
|
|
|
|
""",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
node.restart_clickhouse()
|
|
|
|
node.query(f"TRUNCATE TABLE IF EXISTS system.query_log")
|
|
|
|
for i in range(10):
|
|
|
|
node.query(f"select {i}")
|
|
|
|
|
|
|
|
assert_eq_with_retry(
|
|
|
|
node,
|
|
|
|
f"select count() >= 11 from system.query_log",
|
|
|
|
"1",
|
|
|
|
sleep_time=0.2,
|
|
|
|
retry_count=100,
|
|
|
|
)
|
|
|
|
|
|
|
|
node.query(f"TRUNCATE TABLE IF EXISTS system.query_log")
|
|
|
|
node.exec_in_container(
|
|
|
|
[
|
|
|
|
"bash",
|
|
|
|
"-c",
|
|
|
|
f"""echo "
|
|
|
|
<clickhouse>
|
|
|
|
<query_log>
|
|
|
|
<flush_interval_milliseconds replace=\\"replace\\">1000000</flush_interval_milliseconds>
|
|
|
|
<buffer_size_rows_flush_threshold replace=\\"replace\\">10000</buffer_size_rows_flush_threshold>
|
|
|
|
<max_size_rows replace=\\"replace\\">10000</max_size_rows>
|
|
|
|
</query_log>
|
|
|
|
</clickhouse>
|
|
|
|
" > /etc/clickhouse-server/config.d/yyy-override-query_log.xml
|
|
|
|
""",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
node.restart_clickhouse()
|
|
|
|
for i in range(10):
|
|
|
|
node.query(f"select {i}")
|
|
|
|
|
|
|
|
# Logs aren't flushed
|
|
|
|
assert_eq_with_retry(
|
|
|
|
node,
|
|
|
|
f"select count() < 10 from system.query_log",
|
|
|
|
"1",
|
|
|
|
sleep_time=0.2,
|
|
|
|
retry_count=100,
|
|
|
|
)
|
|
|
|
|
|
|
|
node.exec_in_container(
|
|
|
|
["rm", f"/etc/clickhouse-server/config.d/yyy-override-query_log.xml"]
|
|
|
|
)
|