Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore: add wait time during validation of clickhouse background migra… (#4596)

Steffen Schmitz4a44adceddad
diff --git a/worker/src/backgroundMigrations/migrateObservationsFromPostgresToClickhouse.ts b/worker/src/backgroundMigrations/migrateObservationsFromPostgresToClickhouse.ts
index f66883a5b8..4506a57688 100644
--- a/worker/src/backgroundMigrations/migrateObservationsFromPostgresToClickhouse.ts
+++ b/worker/src/backgroundMigrations/migrateObservationsFromPostgresToClickhouse.ts
@@ -54,13 +54,44 @@ export default class MigrateObservationsFromPostgresToClickhouse
async validate(
args: Record<string, unknown>,
+ attempts = 5,
): Promise<{ valid: boolean; invalidReason: string | undefined }> {
- if (!env.CLICKHOUSE_URL) {
+ // Check if Clickhouse credentials are configured
+ if (
+ !env.CLICKHOUSE_URL ||
+ !env.CLICKHOUSE_USER ||
+ !env.CLICKHOUSE_PASSWORD
+ ) {
return {
valid: false,
- invalidReason: "Clickhouse URL must be configured to perform migration",
+ invalidReason:
+ "Clickhouse credentials must be configured to perform migration",
};
}
+
+ // Check if ClickHouse observations table exists
+ const tables = await clickhouseClient().query({
+ query: "SHOW TABLES",
+ });
+ const tableNames = (await tables.json()).data as { name: string }[];
+ if (!tableNames.some((r) => r.name === "observations")) {
+ // Retry if the table does not exist as this may mean migrations are still pending
+ if (attempts > 0) {
+ logger.info(
+ `ClickHouse observations table does not exist. Retrying in 10s...`,
+ );
+ return new Promise((resolve) => {
+ setTimeout(() => resolve(this.validate(args, attempts - 1)), 10_000);
+ });
+ }
+
+ // If all retries are exhausted, return as invalid
+ return {
+ valid: false,
+ invalidReason: "ClickHouse observations table does not exist",
+ };
+ }
+
return { valid: true, invalidReason: undefined };
}
diff --git a/worker/src/backgroundMigrations/migrateScoresFromPostgresToClickhouse.ts b/worker/src/backgroundMigrations/migrateScoresFromPostgresToClickhouse.ts
index cc2f460f23..a83d131a69 100644
--- a/worker/src/backgroundMigrations/migrateScoresFromPostgresToClickhouse.ts
+++ b/worker/src/backgroundMigrations/migrateScoresFromPostgresToClickhouse.ts
@@ -19,13 +19,44 @@ export default class MigrateScoresFromPostgresToClickhouse
async validate(
args: Record<string, unknown>,
+ attempts = 5,
): Promise<{ valid: boolean; invalidReason: string | undefined }> {
- if (!env.CLICKHOUSE_URL) {
+ // Check if Clickhouse credentials are configured
+ if (
+ !env.CLICKHOUSE_URL ||
+ !env.CLICKHOUSE_USER ||
+ !env.CLICKHOUSE_PASSWORD
+ ) {
return {
valid: false,
- invalidReason: "Clickhouse URL must be configured to perform migration",
+ invalidReason:
+ "Clickhouse credentials must be configured to perform migration",
};
}
+
+ // Check if ClickHouse scores table exists
+ const tables = await clickhouseClient().query({
+ query: "SHOW TABLES",
+ });
+ const tableNames = (await tables.json()).data as { name: string }[];
+ if (!tableNames.some((r) => r.name === "scores")) {
+ // Retry if the table does not exist as this may mean migrations are still pending
+ if (attempts > 0) {
+ logger.info(
+ `ClickHouse scores table does not exist. Retrying in 10s...`,
+ );
+ return new Promise((resolve) => {
+ setTimeout(() => resolve(this.validate(args, attempts - 1)), 10_000);
+ });
+ }
+
+ // If all retries are exhausted, return as invalid
+ return {
+ valid: false,
+ invalidReason: "ClickHouse scores table does not exist",
+ };
+ }
+
return { valid: true, invalidReason: undefined };
}
diff --git a/worker/src/backgroundMigrations/migrateTracesFromPostgresToClickhouse.ts b/worker/src/backgroundMigrations/migrateTracesFromPostgresToClickhouse.ts
index 40e2ab768e..a25dca9c91 100644
--- a/worker/src/backgroundMigrations/migrateTracesFromPostgresToClickhouse.ts
+++ b/worker/src/backgroundMigrations/migrateTracesFromPostgresToClickhouse.ts
@@ -19,13 +19,44 @@ export default class MigrateTracesFromPostgresToClickhouse
async validate(
args: Record<string, unknown>,
+ attempts = 5,
): Promise<{ valid: boolean; invalidReason: string | undefined }> {
- if (!env.CLICKHOUSE_URL) {
+ // Check if Clickhouse credentials are configured
+ if (
+ !env.CLICKHOUSE_URL ||
+ !env.CLICKHOUSE_USER ||
+ !env.CLICKHOUSE_PASSWORD
+ ) {
return {
valid: false,
- invalidReason: "Clickhouse URL must be configured to perform migration",
+ invalidReason:
+ "Clickhouse credentials must be configured to perform migration",
};
}
+
+ // Check if ClickHouse traces table exists
+ const tables = await clickhouseClient().query({
+ query: "SHOW TABLES",
+ });
+ const tableNames = (await tables.json()).data as { name: string }[];
+ if (!tableNames.some((r) => r.name === "traces")) {
+ // Retry if the table does not exist as this may mean migrations are still pending
+ if (attempts > 0) {
+ logger.info(
+ `ClickHouse traces table does not exist. Retrying in 10s...`,
+ );
+ return new Promise((resolve) => {
+ setTimeout(() => resolve(this.validate(args, attempts - 1)), 10_000);
+ });
+ }
+
+ // If all retries are exhausted, return as invalid
+ return {
+ valid: false,
+ invalidReason: "ClickHouse traces table does not exist",
+ };
+ }
+
return { valid: true, invalidReason: undefined };
}