Skip to content

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

perf: move more endpoints to read only (#9105)

Max Deichmann65bd0bf5c15f
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index f28e322adc..9087ab90a0 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -6,7 +6,7 @@ on:
workflow_dispatch:
inputs:
service:
- description: 'Service to be deployed'
+ description: "Service to be deployed"
type: choice
options:
- all
@@ -15,7 +15,7 @@ on:
- worker
required: true
environment:
- description: 'Environment to deploy to'
+ description: "Environment to deploy to"
type: choice
options:
- staging
diff --git a/packages/shared/src/server/repositories/observations.ts b/packages/shared/src/server/repositories/observations.ts
index d7360b7397..0c5ea1a5ff 100644
--- a/packages/shared/src/server/repositories/observations.ts
+++ b/packages/shared/src/server/repositories/observations.ts
@@ -318,6 +318,7 @@ export const getObservationById = async ({
type,
traceId,
renderingProps = DEFAULT_RENDERING_PROPS,
+ preferredClickhouseService,
}: {
id: string;
projectId: string;
@@ -326,6 +327,7 @@ export const getObservationById = async ({
type?: ObservationType;
traceId?: string;
renderingProps?: RenderingProps;
+ preferredClickhouseService?: PreferredClickhouseService;
}) => {
const records = await getObservationByIdInternal({
id,
@@ -335,6 +337,7 @@ export const getObservationById = async ({
type,
traceId,
renderingProps,
+ preferredClickhouseService,
});
const mapped = records.map((record) =>
convertObservation(record, renderingProps),
@@ -419,6 +422,7 @@ const getObservationByIdInternal = async ({
type,
traceId,
renderingProps = DEFAULT_RENDERING_PROPS,
+ preferredClickhouseService,
}: {
id: string;
projectId: string;
@@ -427,6 +431,7 @@ const getObservationByIdInternal = async ({
type?: ObservationType;
traceId?: string;
renderingProps?: RenderingProps;
+ preferredClickhouseService?: PreferredClickhouseService;
}) => {
const query = `
SELECT
@@ -483,6 +488,7 @@ const getObservationByIdInternal = async ({
kind: "byId",
projectId,
},
+ preferredClickhouseService,
});
};
diff --git a/packages/shared/src/server/repositories/scores-utils.ts b/packages/shared/src/server/repositories/scores-utils.ts
index 19da04ec9b..4e384b7c26 100644
--- a/packages/shared/src/server/repositories/scores-utils.ts
+++ b/packages/shared/src/server/repositories/scores-utils.ts
@@ -1,4 +1,5 @@
import { ScoreSourceType } from "../../domain";
+import { PreferredClickhouseService } from "../clickhouse/client";
import { queryClickhouse } from "./clickhouse";
import { ScoreRecordReadType } from "./definitions";
import { convertToScore } from "./scores_converters";
@@ -13,11 +14,13 @@ export const _handleGetScoreById = async ({
scoreId,
source,
scoreScope,
+ preferredClickhouseService,
}: {
projectId: string;
scoreId: string;
source?: ScoreSourceType;
scoreScope: "traces_only" | "all";
+ preferredClickhouseService?: PreferredClickhouseService;
}) => {
const query = `
SELECT *
@@ -44,6 +47,7 @@ export const _handleGetScoreById = async ({
kind: "byId",
projectId,
},
+ preferredClickhouseService,
});
return rows.map(convertToScore).shift();
};
diff --git a/packages/shared/src/server/repositories/traces.ts b/packages/shared/src/server/repositories/traces.ts
index 96261ab6cf..a5819491ec 100644
--- a/packages/shared/src/server/repositories/traces.ts
+++ b/packages/shared/src/server/repositories/traces.ts
@@ -21,6 +21,7 @@ import { UiColumnMappings } from "../../tableDefinitions";
import {
clickhouseClient,
convertDateToClickhouseDateTime,
+ PreferredClickhouseService,
} from "../clickhouse/client";
import { convertClickhouseToDomain } from "./traces_converters";
import { clickhouseSearchCondition } from "../queries/clickhouse-sql/search";
@@ -694,6 +695,7 @@ export const getTraceById = async ({
fromTimestamp,
renderingProps = DEFAULT_RENDERING_PROPS,
clickhouseFeatureTag = "tracing",
+ preferredClickhouseService,
}: {
traceId: string;
projectId: string;
@@ -701,6 +703,7 @@ export const getTraceById = async ({
fromTimestamp?: Date;
renderingProps?: RenderingProps;
clickhouseFeatureTag?: string;
+ preferredClickhouseService?: PreferredClickhouseService;
}) => {
const records = await measureAndReturn({
operationName: "getTraceById",
@@ -759,6 +762,7 @@ export const getTraceById = async ({
query,
params: input.params,
tags: { ...input.tags, experiment_amt: "original" },
+ preferredClickhouseService,
});
},
newExecution: (input) => {
@@ -794,6 +798,7 @@ export const getTraceById = async ({
query,
params: input.params,
tags: { ...input.tags, experiment_amt: "new" },
+ preferredClickhouseService,
});
},
});
diff --git a/web/src/features/public-api/server/scores-api-service.ts b/web/src/features/public-api/server/scores-api-service.ts
index f0461a6044..a732e24550 100644
--- a/web/src/features/public-api/server/scores-api-service.ts
+++ b/web/src/features/public-api/server/scores-api-service.ts
@@ -26,6 +26,7 @@ export class ScoresApiService {
scoreId,
source,
scoreScope: this.apiVersion === "v1" ? "traces_only" : "all",
+ preferredClickhouseService: "ReadOnly",
});
}
diff --git a/web/src/features/public-api/server/scores.ts b/web/src/features/public-api/server/scores.ts
index 3ffb6d3357..f5b46417e5 100644
--- a/web/src/features/public-api/server/scores.ts
+++ b/web/src/features/public-api/server/scores.ts
@@ -134,6 +134,7 @@ export const _handleGenerateScoresForPublicApi = async ({
query: query.replace("__TRACE_TABLE__", "traces"),
params: input.params,
tags: { ...input.tags, experiment_amt: "original" },
+ preferredClickhouseService: "ReadOnly",
});
return records.map((record) => ({
@@ -159,6 +160,7 @@ export const _handleGenerateScoresForPublicApi = async ({
query: query.replace("__TRACE_TABLE__", "traces_all_amt"),
params: input.params,
tags: { ...input.tags, experiment_amt: "new" },
+ preferredClickhouseService: "ReadOnly",
});
return records.map((record) => ({
@@ -246,6 +248,7 @@ export const _handleGetScoresCountForPublicApi = async ({
query: query.replace("__TRACE_TABLE__", "traces"),
params: input.params,
tags: { ...input.tags, experiment_amt: "original" },
+ preferredClickhouseService: "ReadOnly",
});
return records.map((record) => Number(record.count)).shift();
},
@@ -254,6 +257,7 @@ export const _handleGetScoresCountForPublicApi = async ({
query: query.replace("__TRACE_TABLE__", "traces_all_amt"),
params: input.params,
tags: { ...input.tags, experiment_amt: "new" },
+ preferredClickhouseService: "ReadOnly",
});
return records.map((record) => Number(record.count)).shift();
},
diff --git a/web/src/pages/api/public/observations/[observationId].ts b/web/src/pages/api/public/observations/[observationId].ts
index b5167339d4..1ba15521f5 100644
--- a/web/src/pages/api/public/observations/[observationId].ts
+++ b/web/src/pages/api/public/observations/[observationId].ts
@@ -19,6 +19,7 @@ export default withMiddlewares({
id: query.observationId,
projectId: auth.scope.projectId,
fetchWithInputOutput: true,
+ preferredClickhouseService: "ReadOnly",
});
if (!clickhouseObservation) {
throw new LangfuseNotFoundError(
diff --git a/web/src/pages/api/public/traces/[traceId].ts b/web/src/pages/api/public/traces/[traceId].ts
index d43242c48e..fe83001074 100644
--- a/web/src/pages/api/public/traces/[traceId].ts
+++ b/web/src/pages/api/public/traces/[traceId].ts
@@ -33,6 +33,7 @@ export default withMiddlewares({
traceId,
projectId: auth.scope.projectId,
clickhouseFeatureTag: "tracing-public-api",
+ preferredClickhouseService: "ReadOnly",
});
if (!trace) {