2020-09-06 02:49:47 +00:00
|
|
|
import time
|
|
|
|
|
2020-09-10 00:56:21 +00:00
|
|
|
import pytest
|
2020-09-06 02:49:47 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
2020-09-10 00:56:21 +00:00
|
|
|
cluster = ClickHouseCluster(__file__)
|
2022-03-22 16:39:58 +00:00
|
|
|
node1 = cluster.add_instance(
|
|
|
|
"node1",
|
|
|
|
with_zookeeper=True,
|
|
|
|
main_configs=["configs/asynchronous_metrics_update_period_s.xml"],
|
|
|
|
)
|
2020-09-10 00:56:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def started_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
2022-04-24 22:08:11 +00:00
|
|
|
# Tests that the system.asynchronous_metric_log table gets populated.
|
2020-09-06 02:49:47 +00:00
|
|
|
# asynchronous metrics are updated once every 60s by default. To make the test run faster, the setting
|
|
|
|
# asynchronous_metric_update_period_s is being set to 2s so that the metrics are populated faster and
|
|
|
|
# are available for querying during the test.
|
2020-09-10 00:56:21 +00:00
|
|
|
def test_event_time_microseconds_field(started_cluster):
|
2020-09-06 02:49:47 +00:00
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
node1.query("SET log_queries = 1;")
|
|
|
|
node1.query("CREATE DATABASE replica;")
|
2022-03-22 16:39:58 +00:00
|
|
|
query_create = """CREATE TABLE replica.test
|
2020-09-06 02:49:47 +00:00
|
|
|
(
|
|
|
|
id Int64,
|
|
|
|
event_time DateTime
|
|
|
|
)
|
|
|
|
Engine=MergeTree()
|
|
|
|
PARTITION BY toYYYYMMDD(event_time)
|
2022-03-22 16:39:58 +00:00
|
|
|
ORDER BY id;"""
|
2020-09-06 02:49:47 +00:00
|
|
|
time.sleep(2)
|
|
|
|
node1.query(query_create)
|
2022-03-22 16:39:58 +00:00
|
|
|
node1.query("""INSERT INTO replica.test VALUES (1, now())""")
|
2020-09-06 02:49:47 +00:00
|
|
|
node1.query("SYSTEM FLUSH LOGS;")
|
2022-04-24 22:08:11 +00:00
|
|
|
|
2022-04-28 03:30:14 +00:00
|
|
|
test_query = (
|
|
|
|
"SELECT count() > 0 ? 'ok' : 'fail' FROM system.asynchronous_metric_log"
|
|
|
|
)
|
2022-04-24 22:08:11 +00:00
|
|
|
assert "ok\n" in node1.query(test_query)
|
2020-09-06 02:49:47 +00:00
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|