Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup ClickHouse integration conftest #249

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 5 additions & 27 deletions tests/integration/coordinator/plugins/clickhouse/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
CONSTANT_TEST_RSA_PRIVATE_KEY,
CONSTANT_TEST_RSA_PUBLIC_KEY,
format_astacus_command,
get_clickhouse_version,
)

import argparse
Expand All @@ -54,8 +53,6 @@

@dataclasses.dataclass
class ClickHouseServiceCluster(ServiceCluster):
use_named_collections: bool
expands_uuid_in_zookeeper_path: bool
object_storage_prefix: str


Expand Down Expand Up @@ -264,9 +261,6 @@ async def create_clickhouse_cluster(
object_storage_prefix: str = "prefix/",
) -> AsyncIterator[ClickHouseServiceCluster]:
cluster_size = len(cluster_shards)
clickhouse_version = get_clickhouse_version(command)
use_named_collections = clickhouse_version >= (22, 4)
expands_uuid_in_zookeeper_path = clickhouse_version < (22, 4)
tcp_ports = [ports.allocate() for _ in range(cluster_size)]
http_ports = [ports.allocate() for _ in range(cluster_size)]
interserver_http_ports = [ports.allocate() for _ in range(cluster_size)]
Expand All @@ -280,7 +274,6 @@ async def create_clickhouse_cluster(
tcp_ports,
http_ports,
interserver_http_ports,
use_named_collections,
minio_bucket=minio_bucket,
object_storage_prefix=object_storage_prefix,
)
Expand All @@ -300,8 +293,6 @@ async def create_clickhouse_cluster(
Service(process=process, port=http_port, username="default", password="secret", data_dir=data_dir)
for process, http_port, data_dir in zip(processes, http_ports, data_dirs)
],
use_named_collections=use_named_collections,
expands_uuid_in_zookeeper_path=expands_uuid_in_zookeeper_path,
object_storage_prefix=object_storage_prefix,
)

Expand Down Expand Up @@ -339,7 +330,6 @@ def create_clickhouse_configs(
tcp_ports: Sequence[int],
http_ports: Sequence[int],
interserver_http_ports: Sequence[int],
use_named_collections: bool,
minio_bucket: MinioBucket | None = None,
object_storage_prefix: str = "/",
):
Expand All @@ -357,17 +347,6 @@ def setting(name: str, value: int | float | str):
"""
for tcp_port in tcp_ports
)
named_collections = (
"""
<named_collections>
<default_cluster>
<cluster_secret>secret</cluster_secret>
</default_cluster>
</named_collections>
"""
if use_named_collections
else ""
)
storage_configuration = (
f"""
<storage_configuration>
Expand Down Expand Up @@ -460,7 +439,11 @@ def setting(name: str, value: int | float | str):
</shard>
</defaultcluster>
</remote_servers>
{named_collections}
<named_collections>
<default_cluster>
<cluster_secret>secret</cluster_secret>
</default_cluster>
</named_collections>
<default_replica_path>/clickhouse/tables/{{uuid}}/{{my_shard}}</default_replica_path>
<default_replica_name>{{my_replica}}</default_replica_name>
<macros>
Expand Down Expand Up @@ -579,11 +562,6 @@ def create_astacus_configs(
ReplicatedDatabaseSettings(
collection_name="default_cluster",
)
if clickhouse_cluster.use_named_collections
else ReplicatedDatabaseSettings(
cluster_username=clickhouse_cluster.services[0].username,
cluster_password=clickhouse_cluster.services[0].password,
)
),
replicated_user_defined_zookeeper_path="/clickhouse/user_defined_functions/",
disks=[
Expand Down
15 changes: 3 additions & 12 deletions tests/integration/coordinator/plugins/clickhouse/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ async def restorable_cluster_manager(
clients = [get_clickhouse_client(service) for service in clickhouse_cluster.services]
await setup_cluster_content(
clients,
clickhouse_cluster.use_named_collections,
get_clickhouse_version(clickhouse_command),
)
await setup_cluster_users(clients)
Expand Down Expand Up @@ -187,18 +186,12 @@ async def sync_replicated_table(clients: Sequence[ClickHouseClient], table_name:
await client.execute(f"SYSTEM SYNC REPLICA default.{escape_sql_identifier(table_name.encode())} STRICT".encode())


async def setup_cluster_content(
clients: Sequence[HttpClickHouseClient], use_named_collections: bool, clickhouse_version: tuple[int, ...]
) -> None:
async def setup_cluster_content(clients: Sequence[HttpClickHouseClient], clickhouse_version: tuple[int, ...]) -> None:
for client in clients:
await client.execute(b"DROP DATABASE default SYNC")
await client.execute(
b"CREATE DATABASE default ENGINE = Replicated('/clickhouse/databases/thebase', '{my_shard}', '{my_replica}') "
+ (
b"SETTINGS collection_name='default_cluster'"
if use_named_collections
else b"SETTINGS cluster_username='default', cluster_password='secret'"
)
b"SETTINGS collection_name='default_cluster'"
)
# table creation is auto-replicated so we only do it once :
await clients[0].execute(
Expand Down Expand Up @@ -558,9 +551,7 @@ async def test_cleanup_does_not_break_object_storage_disk_files(
storage_path, zookeeper, clickhouse_cluster, ports, minio_bucket
) as astacus_cluster:
clients = [get_clickhouse_client(service) for service in clickhouse_cluster.services]
await setup_cluster_content(
clients, clickhouse_cluster.use_named_collections, get_clickhouse_version(clickhouse_command)
)
await setup_cluster_content(clients, get_clickhouse_version(clickhouse_command))
await setup_cluster_users(clients)
run_astacus_command(astacus_cluster, "backup")
run_astacus_command(astacus_cluster, "backup")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ async def test_retrieve_tables(ports: Ports, clickhouse_command: ClickHouseComma
replica=b"{my_replica}",
),
]
zookeeper_path = (
f"/clickhouse/tables/{table_uuid!s}/{{my_shard}}"
if clickhouse_cluster.expands_uuid_in_zookeeper_path
else "/clickhouse/tables/{uuid}/{my_shard}"
)
assert tables == [
Table(
database="has_tablés".encode(),
Expand All @@ -98,7 +93,7 @@ async def test_retrieve_tables(ports: Ports, clickhouse_command: ClickHouseComma
create_query=(
f"CREATE TABLE `has_tablés`.`tablé_1` UUID '{table_uuid!s}' (`thekey` UInt32) "
f"ENGINE = "
f"ReplicatedMergeTree('{zookeeper_path}', '{{my_replica}}') "
f"ReplicatedMergeTree('/clickhouse/tables/{{uuid}}/{{my_shard}}', '{{my_replica}}') "
f"ORDER BY thekey SETTINGS index_granularity = 8192"
).encode(),
dependencies=[],
Expand Down
Loading