Skip to content

Commit 4ccabd3

Browse files
liyakaCometActionsthiagohora
authored
[OPIK-906] Updates to support clickhouse replications (#1400)
* add migration change_tables_to_replicated * update docker-compose * use better Test reports for backend tests * add zookeeper to helm chart default * Update Helm documentation * update clickhouse config for docker-compose * Fix tests * OPIK-906: Fix tests * fix * add detach partition from the old table before dropping it * Add attachments * update migration script * add Troubleshooting to docs * adjust migrations * fix migartion --------- Co-authored-by: CometActions <[email protected]> Co-authored-by: Thiago Hora <[email protected]>
1 parent 34bda61 commit 4ccabd3

File tree

46 files changed

+683
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+683
-132
lines changed

.github/workflows/backend_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ jobs:
3636
env:
3737
TESTCONTAINERS_REUSE_ENABLE: true
3838
run: mvn clean test -Dmaven.test.failure.ignore=true
39-
39+
4040
- name: Publish Test Report
4141
uses: EnricoMi/publish-unit-test-result-action/linux@v2
4242
if: always()
4343
with:
4444
action_fail: true
45-
files: '**/target/surefire-reports/TEST-*.xml'
45+
files: '**/target/surefire-reports/TEST-*.xml'

apps/opik-backend/src/main/java/com/comet/opik/domain/FeedbackScoreDAO.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ AND entity_id IN (
138138
WHERE trace_id IN :trace_ids
139139
)
140140
AND workspace_id = :workspace_id
141+
SETTINGS allow_nondeterministic_mutations = 1
141142
;
142143
""";
143144

apps/opik-backend/src/main/resources/liquibase/db-app-analytics/migrations/000017_change_tables_to_replicated.sql

Lines changed: 311 additions & 0 deletions
Large diffs are not rendered by default.

apps/opik-backend/src/test/java/com/comet/opik/api/resources/utils/ClickHouseContainerUtils.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
import com.comet.opik.infrastructure.DatabaseAnalyticsFactory;
44
import org.testcontainers.clickhouse.ClickHouseContainer;
5+
import org.testcontainers.containers.GenericContainer;
6+
import org.testcontainers.containers.Network;
57
import org.testcontainers.utility.DockerImageName;
8+
import org.testcontainers.utility.MountableFile;
69

710
import java.util.Map;
811

912
public class ClickHouseContainerUtils {
1013

1114
public static final String DATABASE_NAME = "opik";
1215
public static final String DATABASE_NAME_VARIABLE = "ANALYTICS_DB_DATABASE_NAME";
16+
private static final Network NETWORK = Network.newNetwork();
1317

1418
public static ClickHouseContainer newClickHouseContainer() {
1519
return newClickHouseContainer(true);
@@ -20,6 +24,49 @@ public static ClickHouseContainer newClickHouseContainer(boolean reusable) {
2024
.withReuse(reusable);
2125
}
2226

27+
public static GenericContainer<?> newZookeeperContainer() {
28+
return newZookeeperContainer(true, NETWORK);
29+
}
30+
31+
public static GenericContainer<?> newZookeeperContainer(boolean reusable, Network network) {
32+
return new GenericContainer<>("zookeeper:3.9.3")
33+
.withExposedPorts(2181)
34+
.withNetworkAliases("zookeeper")
35+
.withNetwork(network)
36+
.withEnv("ALLOW_ANONYMOUS_LOGIN", "yes")
37+
.withEnv("ZOO_MY_ID", "1")
38+
.withReuse(reusable);
39+
}
40+
41+
public static ClickHouseContainer newClickHouseContainer(GenericContainer<?> zooKeeperContainer) {
42+
return newClickHouseContainer(true, NETWORK, zooKeeperContainer);
43+
}
44+
45+
public static ClickHouseContainer newClickHouseContainer(boolean reusable, Network network,
46+
GenericContainer<?> zooKeeperContainer) {
47+
48+
try {
49+
50+
ClickHouseContainer container = newClickHouseContainer(reusable);
51+
52+
if (zooKeeperContainer != null) {
53+
container.dependsOn(zooKeeperContainer);
54+
}
55+
56+
return container
57+
.withReuse(reusable)
58+
.withEnv("CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT", "1")
59+
.withNetwork(network)
60+
.withCopyFileToContainer(MountableFile.forClasspathResource("macros.xml"),
61+
"/etc/clickhouse-server/config.d/macros.xml")
62+
.withCopyFileToContainer(MountableFile.forClasspathResource("zookeeper.xml"),
63+
"/etc/clickhouse-server/config.d/zookeeper.xml");
64+
65+
} catch (Exception e) {
66+
throw new RuntimeException(e);
67+
}
68+
}
69+
2370
public static DatabaseAnalyticsFactory newDatabaseAnalyticsFactory(ClickHouseContainer clickHouseContainer,
2471
String databaseName) {
2572
var databaseAnalyticsFactory = new DatabaseAnalyticsFactory();

apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/events/DatasetEventListenerTest.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import com.comet.opik.api.resources.utils.TestUtils;
1414
import com.comet.opik.api.resources.utils.WireMockUtils;
1515
import com.comet.opik.api.resources.utils.resources.ExperimentResourceClient;
16+
import com.comet.opik.extensions.DropwizardAppExtensionProvider;
17+
import com.comet.opik.extensions.RegisterApp;
1618
import com.comet.opik.infrastructure.DatabaseAnalyticsFactory;
1719
import com.comet.opik.podam.PodamFactoryUtils;
1820
import com.redis.testcontainers.RedisContainer;
@@ -26,8 +28,9 @@
2628
import org.junit.jupiter.api.Nested;
2729
import org.junit.jupiter.api.Test;
2830
import org.junit.jupiter.api.TestInstance;
29-
import org.junit.jupiter.api.extension.RegisterExtension;
31+
import org.junit.jupiter.api.extension.ExtendWith;
3032
import org.testcontainers.clickhouse.ClickHouseContainer;
33+
import org.testcontainers.containers.GenericContainer;
3134
import org.testcontainers.containers.MySQLContainer;
3235
import org.testcontainers.lifecycle.Startables;
3336
import org.testcontainers.shaded.org.awaitility.Awaitility;
@@ -47,6 +50,7 @@
4750

4851
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
4952
@DisplayName("Dataset Event Listener")
53+
@ExtendWith(DropwizardAppExtensionProvider.class)
5054
class DatasetEventListenerTest {
5155

5256
private static final String BASE_RESOURCE_URI = "%s/v1/private/datasets";
@@ -57,19 +61,18 @@ class DatasetEventListenerTest {
5761
private static final String WORKSPACE_ID = UUID.randomUUID().toString();
5862
private static final String TEST_WORKSPACE = UUID.randomUUID().toString();
5963

60-
private static final RedisContainer REDIS = RedisContainerUtils.newRedisContainer();
64+
private final RedisContainer REDIS = RedisContainerUtils.newRedisContainer();
65+
private final MySQLContainer<?> MYSQL = MySQLContainerUtils.newMySQLContainer();
66+
private final GenericContainer<?> ZOOKEEPER_CONTAINER = ClickHouseContainerUtils.newZookeeperContainer();
67+
private final ClickHouseContainer CLICKHOUSE = ClickHouseContainerUtils.newClickHouseContainer(ZOOKEEPER_CONTAINER);
6168

62-
private static final MySQLContainer<?> MYSQL = MySQLContainerUtils.newMySQLContainer();
69+
@RegisterApp
70+
private final TestDropwizardAppExtension APP;
6371

64-
private static final ClickHouseContainer CLICKHOUSE = ClickHouseContainerUtils.newClickHouseContainer();
72+
private final WireMockUtils.WireMockRuntime wireMock;
6573

66-
@RegisterExtension
67-
private static final TestDropwizardAppExtension APP;
68-
69-
private static final WireMockUtils.WireMockRuntime wireMock;
70-
71-
static {
72-
Startables.deepStart(MYSQL, CLICKHOUSE, REDIS).join();
74+
{
75+
Startables.deepStart(MYSQL, CLICKHOUSE, REDIS, ZOOKEEPER_CONTAINER).join();
7376

7477
wireMock = WireMockUtils.startWireMock();
7578

@@ -111,7 +114,7 @@ void tearDownAll() {
111114
wireMock.server().stop();
112115
}
113116

114-
private static void mockTargetWorkspace(String apiKey, String workspaceName, String workspaceId) {
117+
private void mockTargetWorkspace(String apiKey, String workspaceName, String workspaceId) {
115118
AuthTestUtils.mockTargetWorkspace(wireMock.server(), apiKey, workspaceName, workspaceId, USER);
116119
}
117120

0 commit comments

Comments
 (0)