docker: for dev, separate standalone ClickHouse setup from cluster

This way, there is no need to start a whole cluster just to work on a
single ClickHouse. Also add some hints in CONTRIBUTING.md.
This commit is contained in:
Vincent Bernat
2025-08-08 08:55:29 +02:00
parent fd9dc0dbf3
commit 3e68a41f57
5 changed files with 35 additions and 19 deletions

View File

@@ -40,9 +40,12 @@ with `make test-go PKG=akvorado/orchestrator/clickhouse`. Using just `go test`
would work, but `make test-go` also runs linting and formatting automatically. would work, but `make test-go` also runs linting and formatting automatically.
If possible, tests should not rely on external components, but when it becomes If possible, tests should not rely on external components, but when it becomes
hard to do so, it is possible to spawns services through Docker. Locally, one hard to do so, it is possible to spawn services through Docker. Locally, one
can spawns them through `docker compose -f docker/docker-compose-dev.yml`. can spawn them through `docker compose -f docker/docker-compose-dev.yml`:
GitHub actions are using services to spawn them.
- `... up clickhouse` to spawn a single ClickHouse
- `... up clickhouse-\*` to spawn a ClickHouse cluster
- `... up kafka` to spawn a Kafka broker
For manual end-to-end tests, you can use `make docker-dev` to build a Docker For manual end-to-end tests, you can use `make docker-dev` to build a Docker
container of Akvorado, then use `docker compose up` to run Docker compose. container of Akvorado, then use `docker compose up` to run Docker compose.

View File

@@ -22,11 +22,14 @@ import (
func SetupClickHouse(t *testing.T, r *reporter.Reporter, cluster bool) *Component { func SetupClickHouse(t *testing.T, r *reporter.Reporter, cluster bool) *Component {
t.Helper() t.Helper()
config := DefaultConfiguration() config := DefaultConfiguration()
config.Servers = []string{ if !cluster {
helpers.CheckExternalService(t, "ClickHouse", []string{"clickhouse:9000", "127.0.0.1:9000"}), config.Servers = []string{
} helpers.CheckExternalService(t, "ClickHouse", []string{"clickhouse:9000", "127.0.0.1:9000"}),
if cluster { }
helpers.CheckExternalService(t, "ClickHouse cluster", []string{"clickhouse-2:9000", "127.0.0.1:9001"}) } else {
config.Servers = []string{
helpers.CheckExternalService(t, "ClickHouse cluster", []string{"clickhouse-2:9000", "127.0.0.1:9002"}),
}
config.Cluster = "akvorado" config.Cluster = "akvorado"
} }
config.DialTimeout = 100 * time.Millisecond config.DialTimeout = 100 * time.Millisecond

View File

@@ -7,7 +7,7 @@
<shard> <shard>
<internal_replication>true</internal_replication> <internal_replication>true</internal_replication>
<replica> <replica>
<host>clickhouse</host> <host>clickhouse-1</host>
<port>9000</port> <port>9000</port>
</replica> </replica>
<replica> <replica>

View File

@@ -0,0 +1,4 @@
<clickhouse>
<!-- For testing, ensure tables are dropped quickly -->
<database_atomic_delay_before_drop_table_sec>0</database_atomic_delay_before_drop_table_sec>
</clickhouse>

View File

@@ -121,41 +121,47 @@ services:
extends: extends:
file: versions.yml file: versions.yml
service: clickhouse service: clickhouse
depends_on:
- clickhouse-keeper-1
environment: environment:
- CLICKHOUSE_SKIP_USER_SETUP=1 - CLICKHOUSE_SKIP_USER_SETUP=1
- CLICKHOUSE_ALWAYS_RUN_INITDB_SCRIPTS=1 - CLICKHOUSE_ALWAYS_RUN_INITDB_SCRIPTS=1
cap_add: cap_add:
- SYS_NICE - SYS_NICE
volumes: volumes:
- ./clickhouse/cluster.xml:/etc/clickhouse-server/config.d/cluster.xml - ./clickhouse/standalone.xml:/etc/clickhouse-server/config.d/standalone.xml
- ./clickhouse/cluster-1.xml:/etc/clickhouse-server/config.d/cluster-1.xml
- ./clickhouse/test-db.sql:/docker-entrypoint-initdb.d/test-db.sql - ./clickhouse/test-db.sql:/docker-entrypoint-initdb.d/test-db.sql
ports: ports:
- 127.0.0.1:8123:8123/tcp - 127.0.0.1:8123:8123/tcp
- 127.0.0.1:9000:9000/tcp - 127.0.0.1:9000:9000/tcp
clickhouse-2: clickhouse-1: &clickhouse-cluster
<<: *clickhouse <<: *clickhouse
depends_on:
- clickhouse-keeper-1
volumes:
- ./clickhouse/cluster.xml:/etc/clickhouse-server/config.d/cluster.xml
- ./clickhouse/cluster-1.xml:/etc/clickhouse-server/config.d/cluster-1.xml
ports:
- 127.0.0.1:9001:9000/tcp
clickhouse-2:
<<: *clickhouse-cluster
volumes: volumes:
- ./clickhouse/cluster.xml:/etc/clickhouse-server/config.d/cluster.xml - ./clickhouse/cluster.xml:/etc/clickhouse-server/config.d/cluster.xml
- ./clickhouse/cluster-2.xml:/etc/clickhouse-server/config.d/cluster-2.xml - ./clickhouse/cluster-2.xml:/etc/clickhouse-server/config.d/cluster-2.xml
ports: ports:
- 127.0.0.1:9001:9000/tcp - 127.0.0.1:9002:9000/tcp
clickhouse-3: clickhouse-3:
<<: *clickhouse <<: *clickhouse-cluster
volumes: volumes:
- ./clickhouse/cluster.xml:/etc/clickhouse-server/config.d/cluster.xml - ./clickhouse/cluster.xml:/etc/clickhouse-server/config.d/cluster.xml
- ./clickhouse/cluster-3.xml:/etc/clickhouse-server/config.d/cluster-3.xml - ./clickhouse/cluster-3.xml:/etc/clickhouse-server/config.d/cluster-3.xml
ports: ports:
- 127.0.0.1:9002:9000/tcp - 127.0.0.1:9003:9000/tcp
clickhouse-4: clickhouse-4:
<<: *clickhouse <<: *clickhouse-cluster
volumes: volumes:
- ./clickhouse/cluster.xml:/etc/clickhouse-server/config.d/cluster.xml - ./clickhouse/cluster.xml:/etc/clickhouse-server/config.d/cluster.xml
- ./clickhouse/cluster-4.xml:/etc/clickhouse-server/config.d/cluster-4.xml - ./clickhouse/cluster-4.xml:/etc/clickhouse-server/config.d/cluster-4.xml
ports: ports:
- 127.0.0.1:9003:9000/tcp - 127.0.0.1:9004:9000/tcp
clickhouse-keeper-1: clickhouse-keeper-1:
extends: extends:
file: versions.yml file: versions.yml