Skip to content

Commit 73f6bed

Browse files
committed
cloudtest,mzcompose: generalize external service configuration
This commit avoids duplicating the configuration of CockroachDB and MinIO across our various test harnesses. The mzcompose `Cockroach`, `MinioSetup`, and `Materialized` services learn convenience options that configure them all appropriately for one another. Additionally, the CockroachDB initialization is shared between cloudtest and mzcompose. This yields a natural spot to install the workaround for the CockroachDB bug discovered in #16726. Fix #16726.
1 parent 7b6c3f2 commit 73f6bed

File tree

21 files changed

+235
-215
lines changed

21 files changed

+235
-215
lines changed

ci/nightly/pipeline.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ steps:
378378
plugins:
379379
- ./ci/plugins/mzcompose:
380380
composition: platform-checks
381-
args: [--scenario=RestartPostgresBackend, --execution-mode=oneatatime]
381+
args: [--scenario=RestartCockroach, --execution-mode=oneatatime]
382382

383383
- id: checks-oneatatime-restart-redpanda-debezium
384384
label: "Checks oneatatime + restart Redpanda & Debezium"
@@ -448,7 +448,7 @@ steps:
448448
plugins:
449449
- ./ci/plugins/mzcompose:
450450
composition: platform-checks
451-
args: [--scenario=RestartPostgresBackend, --execution-mode=parallel]
451+
args: [--scenario=RestartCockroach, --execution-mode=parallel]
452452

453453
- id: checks-parallel-restart-redpanda
454454
label: "Checks parallel + restart Redpanda & Debezium"

ci/test/pipeline.template.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@ steps:
508508
composition: platform-checks
509509
args: [--scenario=KillClusterdStorage]
510510

511-
- id: checks-restart-postgres-backend
512-
label: "Checks + restart Postgres backend"
511+
- id: checks-restart-cockroach
512+
label: "Checks + restart Cockroach"
513513
depends_on: build-x86_64
514514
inputs: [misc/python/materialize/checks]
515515
timeout_in_minutes: 30
@@ -518,7 +518,7 @@ steps:
518518
plugins:
519519
- ./ci/plugins/mzcompose:
520520
composition: platform-checks
521-
args: [--scenario=RestartPostgresBackend]
521+
args: [--scenario=RestartCockroach]
522522

523523
- id: checks-restart-source-postgres
524524
label: "Checks + restart source Postgres"

misc/cockroach/setup_materialize.sql

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Copyright Materialize, Inc. and contributors. All rights reserved.
2+
--
3+
-- Use of this software is governed by the Business Source License
4+
-- included in the LICENSE file at the root of this repository.
5+
--
6+
-- As of the Change Date specified in that file, in accordance with
7+
-- the Business Source License, use of this software will be governed
8+
-- by the Apache License, Version 2.0.
9+
10+
-- Sets up a CockroachDB cluster for use by Materialize.
11+
12+
-- See: https://github.com/cockroachdb/cockroach/issues/93892
13+
-- See: https://github.com/MaterializeInc/materialize/issues/16726
14+
-- TODO: remove this workaround before upgrading to CockroachDB 22.2 in
15+
-- production.
16+
SET CLUSTER SETTING sql.stats.forecasts.enabled = false;
17+
18+
CREATE SCHEMA consensus;
19+
CREATE SCHEMA adapter;
20+
CREATE SCHEMA storage;

misc/dbt-materialize/mzcompose.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@
1111
from typing import Dict, List, Optional
1212

1313
from materialize.mzcompose import Composition, WorkflowArgumentParser
14-
from materialize.mzcompose.services import Materialized, Redpanda, Service, TestCerts
14+
from materialize.mzcompose.services import Materialized, Redpanda, Service
1515

1616
SERVICES = [
17-
TestCerts(),
1817
Materialized(),
1918
Redpanda(),
2019
Service(
2120
"dbt-test",
2221
{
2322
"mzbuild": "dbt-materialize",
24-
"depends_on": ["test-certs"],
2523
"environment": [
2624
"TMPDIR=/share/tmp",
2725
],
@@ -63,7 +61,6 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
6361
materialized = Materialized(
6462
options=test_case.materialized_options,
6563
image=test_case.materialized_image,
66-
depends_on=["test-certs"],
6764
volumes_extra=["secrets:/secrets"],
6865
)
6966

misc/python/materialize/checks/debezium.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def initialize(self) -> Testdrive:
1919
return Testdrive(
2020
dedent(
2121
"""
22-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
22+
$ postgres-execute connection=postgres://postgres:postgres@postgres
2323
CREATE TABLE debezium_table (f1 TEXT, f2 INTEGER, f3 INTEGER, f4 TEXT, PRIMARY KEY (f1, f2));
2424
ALTER TABLE debezium_table REPLICA IDENTITY FULL;
2525
INSERT INTO debezium_table SELECT 'A', generate_series, 1, REPEAT('X', 16) FROM generate_series(1,1000);
@@ -29,7 +29,7 @@ def initialize(self) -> Testdrive:
2929
"name": "psql-connector",
3030
"config": {
3131
"connector.class": "io.debezium.connector.postgresql.PostgresConnector",
32-
"database.hostname": "postgres-source",
32+
"database.hostname": "postgres",
3333
"database.port": "5432",
3434
"database.user": "postgres",
3535
"database.password": "postgres",
@@ -59,7 +59,7 @@ def initialize(self) -> Testdrive:
5959
FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
6060
ENVELOPE DEBEZIUM;
6161
62-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
62+
$ postgres-execute connection=postgres://postgres:postgres@postgres
6363
INSERT INTO debezium_table SELECT 'B', generate_series, 1, REPEAT('X', 16) FROM generate_series(1,1000);
6464
6565
> CREATE MATERIALIZED VIEW debezium_view1 AS SELECT f1, f3, SUM(LENGTH(f4)) FROM debezium_source1 GROUP BY f1, f3;
@@ -76,7 +76,7 @@ def manipulate(self) -> List[Testdrive]:
7676
Testdrive(dedent(s))
7777
for s in [
7878
"""
79-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
79+
$ postgres-execute connection=postgres://postgres:postgres@postgres
8080
BEGIN;
8181
INSERT INTO debezium_table SELECT 'C', generate_series, 1, REPEAT('X', 16) FROM generate_series(1,1000);
8282
UPDATE debezium_table SET f3 = f3 + 1;
@@ -87,7 +87,7 @@ def manipulate(self) -> List[Testdrive]:
8787
FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
8888
ENVELOPE DEBEZIUM;
8989
90-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
90+
$ postgres-execute connection=postgres://postgres:postgres@postgres
9191
BEGIN;
9292
INSERT INTO debezium_table SELECT 'D', generate_series, 1, REPEAT('X', 16) FROM generate_series(1,1000);
9393
UPDATE debezium_table SET f3 = f3 + 1;
@@ -96,7 +96,7 @@ def manipulate(self) -> List[Testdrive]:
9696
> CREATE MATERIALIZED VIEW debezium_view2 AS SELECT f1, f3, SUM(LENGTH(f4)) FROM debezium_source2 GROUP BY f1, f3;
9797
""",
9898
"""
99-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
99+
$ postgres-execute connection=postgres://postgres:postgres@postgres
100100
BEGIN;
101101
INSERT INTO debezium_table SELECT 'E', generate_series, 1, REPEAT('X', 16) FROM generate_series(1,1000);
102102
UPDATE debezium_table SET f3 = f3 + 1;
@@ -107,7 +107,7 @@ def manipulate(self) -> List[Testdrive]:
107107
FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
108108
ENVELOPE DEBEZIUM;
109109
110-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
110+
$ postgres-execute connection=postgres://postgres:postgres@postgres
111111
BEGIN;
112112
INSERT INTO debezium_table SELECT 'F', generate_series, 1, REPEAT('X', 16) FROM generate_series(1,1000);
113113
UPDATE debezium_table SET f3 = f3 + 1;

misc/python/materialize/checks/mzcompose_actions.py

+7-14
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ class MzcomposeAction(Action):
2727

2828

2929
class StartMz(MzcomposeAction):
30-
DEFAULT_MZ_OPTIONS = [
31-
"--persist-consensus-url=postgresql://postgres:postgres@postgres-backend:5432?options=--search_path=consensus",
32-
"--storage-stash-url=postgresql://postgres:postgres@postgres-backend:5432?options=--search_path=storage",
33-
"--adapter-stash-url=postgresql://postgres:postgres@postgres-backend:5432?options=--search_path=adapter",
34-
]
35-
3630
def __init__(
3731
self, tag: Optional[str] = None, environment_extra: List[str] = []
3832
) -> None:
@@ -46,7 +40,7 @@ def execute(self, e: Executor) -> None:
4640
print(f"Starting Mz using image {image}")
4741
mz = Materialized(
4842
image=image,
49-
options=StartMz.DEFAULT_MZ_OPTIONS,
43+
external_cockroach=True,
5044
environment_extra=self.environment_extra,
5145
)
5246

@@ -134,22 +128,21 @@ def execute(self, e: Executor) -> None:
134128
c.start_and_wait_for_tcp(services=[service])
135129

136130

137-
class RestartPostgresBackend(MzcomposeAction):
131+
class RestartCockroach(MzcomposeAction):
138132
def execute(self, e: Executor) -> None:
139133
c = e.mzcompose_composition()
140134

141-
c.kill("postgres-backend")
142-
c.up("postgres-backend")
143-
c.wait_for_postgres(service="postgres-backend")
135+
c.kill("cockroach")
136+
c.up("cockroach")
144137

145138

146139
class RestartSourcePostgres(MzcomposeAction):
147140
def execute(self, e: Executor) -> None:
148141
c = e.mzcompose_composition()
149142

150-
c.kill("postgres-source")
151-
c.up("postgres-source")
152-
c.wait_for_postgres(service="postgres-source")
143+
c.kill("postgres")
144+
c.up("postgres")
145+
c.wait_for_postgres(service="postgres")
153146

154147

155148
class KillClusterdStorage(MzcomposeAction):

misc/python/materialize/checks/pg_cdc.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ def initialize(self) -> Testdrive:
2222
> CREATE SECRET pgpass1 AS 'postgres';
2323
2424
> CREATE CONNECTION pg1 FOR POSTGRES
25-
HOST 'postgres-source',
25+
HOST 'postgres',
2626
DATABASE postgres,
2727
USER postgres1,
2828
PASSWORD SECRET pgpass1
2929
30-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
30+
$ postgres-execute connection=postgres://postgres:postgres@postgres
3131
CREATE USER postgres1 WITH SUPERUSER PASSWORD 'postgres';
3232
ALTER USER postgres1 WITH replication;
3333
DROP PUBLICATION IF EXISTS postgres_source;
@@ -54,25 +54,25 @@ def manipulate(self) -> List[Testdrive]:
5454
(PUBLICATION 'postgres_source')
5555
FOR TABLES (postgres_source_table AS postgres_source_tableA);
5656
57-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
57+
$ postgres-execute connection=postgres://postgres:postgres@postgres
5858
INSERT INTO postgres_source_table SELECT 'B', 1, REPEAT('X', 1024) FROM generate_series(1,100);
5959
UPDATE postgres_source_table SET f2 = f2 + 1;
6060
6161
> CREATE SECRET pgpass2 AS 'postgres';
6262
6363
> CREATE CONNECTION pg2 FOR POSTGRES
64-
HOST 'postgres-source',
64+
HOST 'postgres',
6565
DATABASE postgres,
6666
USER postgres1,
6767
PASSWORD SECRET pgpass1
6868
69-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
69+
$ postgres-execute connection=postgres://postgres:postgres@postgres
7070
INSERT INTO postgres_source_table SELECT 'C', 1, REPEAT('X', 1024) FROM generate_series(1,100);
7171
UPDATE postgres_source_table SET f2 = f2 + 1;
7272
""",
7373
"""
7474
75-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
75+
$ postgres-execute connection=postgres://postgres:postgres@postgres
7676
INSERT INTO postgres_source_table SELECT 'D', 1, REPEAT('X', 1024) FROM generate_series(1,100);
7777
UPDATE postgres_source_table SET f2 = f2 + 1;
7878
@@ -81,18 +81,18 @@ def manipulate(self) -> List[Testdrive]:
8181
(PUBLICATION 'postgres_source')
8282
FOR TABLES (postgres_source_table AS postgres_source_tableB);
8383
84-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
84+
$ postgres-execute connection=postgres://postgres:postgres@postgres
8585
INSERT INTO postgres_source_table SELECT 'E', 1, REPEAT('X', 1024) FROM generate_series(1,100);
8686
UPDATE postgres_source_table SET f2 = f2 + 1;
8787
88-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
88+
$ postgres-execute connection=postgres://postgres:postgres@postgres
8989
INSERT INTO postgres_source_table SELECT 'F', 1, REPEAT('X', 1024) FROM generate_series(1,100);
9090
UPDATE postgres_source_table SET f2 = f2 + 1;
9191
9292
> CREATE SECRET pgpass3 AS 'postgres';
9393
9494
> CREATE CONNECTION pg3 FOR POSTGRES
95-
HOST 'postgres-source',
95+
HOST 'postgres',
9696
DATABASE postgres,
9797
USER postgres1,
9898
PASSWORD SECRET pgpass3
@@ -102,12 +102,12 @@ def manipulate(self) -> List[Testdrive]:
102102
(PUBLICATION 'postgres_source')
103103
FOR TABLES (postgres_source_table AS postgres_source_tableC);
104104
105-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
105+
$ postgres-execute connection=postgres://postgres:postgres@postgres
106106
INSERT INTO postgres_source_table SELECT 'G', 1, REPEAT('X', 1024) FROM generate_series(1,100);
107107
UPDATE postgres_source_table SET f2 = f2 + 1;
108108
109109
110-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
110+
$ postgres-execute connection=postgres://postgres:postgres@postgres
111111
INSERT INTO postgres_source_table SELECT 'H', 1, REPEAT('X', 1024) FROM generate_series(1,100);
112112
UPDATE postgres_source_table SET f2 = f2 + 1;
113113
""",
@@ -160,12 +160,12 @@ def initialize(self) -> Testdrive:
160160
> CREATE SECRET postgres_mz_now_pass AS 'postgres';
161161
162162
> CREATE CONNECTION postgres_mz_now_conn FOR POSTGRES
163-
HOST 'postgres-source',
163+
HOST 'postgres',
164164
DATABASE postgres,
165165
USER postgres2,
166166
PASSWORD SECRET postgres_mz_now_pass
167167
168-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
168+
$ postgres-execute connection=postgres://postgres:postgres@postgres
169169
CREATE USER postgres2 WITH SUPERUSER PASSWORD 'postgres';
170170
ALTER USER postgres2 WITH replication;
171171
DROP PUBLICATION IF EXISTS postgres_mz_now_publication;
@@ -201,7 +201,7 @@ def manipulate(self) -> List[Testdrive]:
201201
Testdrive(dedent(s))
202202
for s in [
203203
"""
204-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
204+
$ postgres-execute connection=postgres://postgres:postgres@postgres
205205
INSERT INTO postgres_mz_now_table VALUES (NOW(), 'A2');
206206
INSERT INTO postgres_mz_now_table VALUES (NOW(), 'B2');
207207
INSERT INTO postgres_mz_now_table VALUES (NOW(), 'C2');
@@ -211,7 +211,7 @@ def manipulate(self) -> List[Testdrive]:
211211
UPDATE postgres_mz_now_table SET f1 = NOW() WHERE f2 = 'C1';
212212
""",
213213
"""
214-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
214+
$ postgres-execute connection=postgres://postgres:postgres@postgres
215215
INSERT INTO postgres_mz_now_table VALUES (NOW(), 'A3');
216216
INSERT INTO postgres_mz_now_table VALUES (NOW(), 'B3');
217217
INSERT INTO postgres_mz_now_table VALUES (NOW(), 'C3');
@@ -230,7 +230,7 @@ def validate(self) -> Testdrive:
230230
> SELECT COUNT(*) FROM postgres_mz_now_table;
231231
13
232232
233-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
233+
$ postgres-execute connection=postgres://postgres:postgres@postgres
234234
INSERT INTO postgres_mz_now_table VALUES (NOW(), 'A4');
235235
INSERT INTO postgres_mz_now_table VALUES (NOW(), 'B4');
236236
INSERT INTO postgres_mz_now_table VALUES (NOW(), 'C4');
@@ -250,7 +250,7 @@ def validate(self) -> Testdrive:
250250
0
251251
252252
# Rollback the last INSERTs so that validate() can be called multiple times
253-
$ postgres-execute connection=postgres://postgres:postgres@postgres-source
253+
$ postgres-execute connection=postgres://postgres:postgres@postgres
254254
INSERT INTO postgres_mz_now_table VALUES (NOW(), 'B3');
255255
DELETE FROM postgres_mz_now_table WHERE f2 LIKE '%4%';
256256
"""

misc/python/materialize/checks/scenarios.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
)
3030
from materialize.checks.mzcompose_actions import KillMz
3131
from materialize.checks.mzcompose_actions import (
32-
RestartPostgresBackend as RestartPostgresBackendAction,
32+
RestartCockroach as RestartCockroachAction,
3333
)
3434
from materialize.checks.mzcompose_actions import (
3535
RestartRedpandaDebezium as RestartRedpandaDebeziumAction,
@@ -155,16 +155,16 @@ def actions(self) -> List[Action]:
155155
]
156156

157157

158-
class RestartPostgresBackend(Scenario):
158+
class RestartCockroach(Scenario):
159159
def actions(self) -> List[Action]:
160160
return [
161161
StartMz(),
162162
Initialize(self.checks),
163-
RestartPostgresBackendAction(),
163+
RestartCockroachAction(),
164164
Manipulate(self.checks, phase=1),
165-
RestartPostgresBackendAction(),
165+
RestartCockroachAction(),
166166
Manipulate(self.checks, phase=2),
167-
RestartPostgresBackendAction(),
167+
RestartCockroachAction(),
168168
Validate(self.checks),
169169
]
170170

0 commit comments

Comments
 (0)