🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix: do not use memory tables in clickhouse (#4394)
Max Deichmann0ba66526e939
diff --git a/.env.dev.legacy.example b/.env.dev.legacy.exampleindex 4e2cdb07b9..49ae361256 100644--- a/.env.dev.legacy.example+++ b/.env.dev.legacy.example@@ -11,7 +11,7 @@ CLICKHOUSE_MIGRATION_URL="clickhouse://localhost:9000"CLICKHOUSE_URL="http://localhost:8123"CLICKHOUSE_USER="clickhouse"CLICKHOUSE_PASSWORD="clickhouse"-CLICKHOUSE_MIGRATION_CLUSTER_DISABLED="true"+CLICKHOUSE_CLUSTER_ENABLED="false"# Next Auth# You can generate a new secret on the command line with:diff --git a/docker-compose.v3preview.yml b/docker-compose.v3preview.ymlindex 2496cf5328..956a6d7828 100644--- a/docker-compose.v3preview.yml+++ b/docker-compose.v3preview.yml@@ -25,7 +25,7 @@ services:CLICKHOUSE_URL: ${CLICKHOUSE_URL:-http://clickhouse:8123}CLICKHOUSE_USER: ${CLICKHOUSE_USER:-clickhouse}CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD:-clickhouse}- CLICKHOUSE_MIGRATION_CLUSTER_DISABLED: ${CLICKHOUSE_MIGRATION_CLUSTER_DISABLED:-true}+ CLICKHOUSE_CLUSTER_ENABLED: ${CLICKHOUSE_CLUSTER_ENABLED:-false}LANGFUSE_S3_EVENT_UPLOAD_ENABLED: ${LANGFUSE_S3_EVENT_UPLOAD_ENABLED:-true}LANGFUSE_S3_EVENT_UPLOAD_BUCKET: ${LANGFUSE_S3_EVENT_UPLOAD_BUCKET:-langfuse}LANGFUSE_S3_EVENT_UPLOAD_REGION: ${LANGFUSE_S3_EVENT_UPLOAD_REGION:-us-east-1}diff --git a/packages/shared/clickhouse/scripts/down.sh b/packages/shared/clickhouse/scripts/down.shindex 7df218423b..c9b0725a4e 100644--- a/packages/shared/clickhouse/scripts/down.sh+++ b/packages/shared/clickhouse/scripts/down.sh@@ -19,7 +19,7 @@ thenfi# Construct the database URL-if [ "$CLICKHOUSE_MIGRATION_CLUSTER_DISABLED" != "true" ] ; then+if [ "$CLICKHOUSE_CLUSTER_ENABLED" == "true" ] ; thenif [ "$CLICKHOUSE_MIGRATION_SSL" = true ] ; thenDATABASE_URL="${CLICKHOUSE_MIGRATION_URL}?username=${CLICKHOUSE_USER}&password=${CLICKHOUSE_PASSWORD}&database=default&x-multi-statement=true&secure=true&skip_verify=true&x-cluster-name=default&x-migrations-table-engine=ReplicatedMergeTree"elsediff --git a/packages/shared/clickhouse/scripts/up.sh b/packages/shared/clickhouse/scripts/up.shindex c5d7d94737..40a5ea8cb2 100644--- a/packages/shared/clickhouse/scripts/up.sh+++ b/packages/shared/clickhouse/scripts/up.sh@@ -19,7 +19,7 @@ thenfi# Construct the database URL-if [ "$CLICKHOUSE_MIGRATION_CLUSTER_DISABLED" != "true" ] ; then+if [ "$CLICKHOUSE_CLUSTER_ENABLED" == "true" ] ; thenif [ "$CLICKHOUSE_MIGRATION_SSL" = true ] ; thenDATABASE_URL="${CLICKHOUSE_MIGRATION_URL}?username=${CLICKHOUSE_USER}&password=${CLICKHOUSE_PASSWORD}&database=default&x-multi-statement=true&secure=true&skip_verify=true&x-cluster-name=default&x-migrations-table-engine=ReplicatedMergeTree"elsediff --git a/web/src/env.mjs b/web/src/env.mjsindex c02cf08497..d78c84564c 100644--- a/web/src/env.mjs+++ b/web/src/env.mjs@@ -119,6 +119,7 @@ export const env = createEnv({CLICKHOUSE_URL: z.string().optional(),CLICKHOUSE_USER: z.string().optional(),CLICKHOUSE_PASSWORD: z.string().optional(),+ CLICKHOUSE_CLUSTER_ENABLED: z.enum(["true", "false"]).default("false"),// EE ui customizationLANGFUSE_UI_API_HOST: z.string().optional(),LANGFUSE_UI_DOCUMENTATION_HREF: z.string().url().optional(),@@ -373,6 +374,7 @@ export const env = createEnv({CLICKHOUSE_URL: process.env.CLICKHOUSE_URL,CLICKHOUSE_USER: process.env.CLICKHOUSE_USER,CLICKHOUSE_PASSWORD: process.env.CLICKHOUSE_PASSWORD,+ CLICKHOUSE_CLUSTER_ENABLED: process.env.CLICKHOUSE_CLUSTER_ENABLED,// EE ui customizationLANGFUSE_UI_API_HOST: process.env.LANGFUSE_UI_API_HOST,LANGFUSE_UI_DOCUMENTATION_HREF: process.env.LANGFUSE_UI_DOCUMENTATION_HREF,diff --git a/web/src/features/datasets/server/service.ts b/web/src/features/datasets/server/service.tsindex b8e77dd3bb..cea984cf61 100644--- a/web/src/features/datasets/server/service.ts+++ b/web/src/features/datasets/server/service.ts@@ -27,6 +27,7 @@ import {import { aggregateScores } from "@/src/features/scores/lib/aggregateScores";import Decimal from "decimal.js";import { measureAndReturnApi } from "@/src/server/utils/checkClickhouseAccess";+import { env } from "@/src/env.mjs";export const datasetRunsTableSchema = z.object({projectId: z.string(),@@ -152,7 +153,7 @@ export const createTempTableInClickhouse = async (clickhouseSession: string,) => {const query = `- CREATE TABLE IF NOT EXISTS ${tableName}+ CREATE TABLE IF NOT EXISTS ${tableName} ${env.CLICKHOUSE_CLUSTER_ENABLED === "true" ? "ON CLUSTER default" : ""}(project_id String,run_id String,@@ -160,7 +161,10 @@ export const createTempTableInClickhouse = async (dataset_id String,trace_id String,observation_id Nullable(String)- ) ENGINE = Memory+ )+ ENGINE = ${env.CLICKHOUSE_CLUSTER_ENABLED === "true" ? "ReplicatedMergeTree()" : "MergeTree()"}+ PRIMARY KEY (project_id, dataset_id, run_id, trace_id)+`;await commandClickhouse({@@ -221,6 +225,8 @@ const getScoresFromTempTable = async (tableName: string,clickhouseSession: string,) => {+ // adds a setting to read data once it is replicated from the writer node.+ // Only then, we can guarantee that the created mergetree before was replicated.const query = `SELECTs.*,@@ -233,6 +239,7 @@ const getScoresFromTempTable = async (AND tmp.dataset_id = {datasetId: String}ORDER BY s.event_ts DESCLIMIT 1 BY s.id, s.project_id+ SETTINGS select_sequential_consistency = 1;`;const rows = await queryClickhouse<