Skip to content

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

chore: restrict domain timestamp updates to one day in clickhouse ingestion (#4085)

Steffen Schmitz5d4125208c69
diff --git a/worker/src/services/IngestionService/index.ts b/worker/src/services/IngestionService/index.ts
index d71b848e25..610da91032 100644
--- a/worker/src/services/IngestionService/index.ts
+++ b/worker/src/services/IngestionService/index.ts
@@ -122,6 +122,12 @@ export class IngestionService {
const timeSortedEvents =
IngestionService.toTimeSortedEventList(scoreEventList);
+ const minTimestamp = Math.min(
+ ...timeSortedEvents.flatMap((e) =>
+ e.timestamp ? [new Date(e.timestamp).getTime()] : [],
+ ),
+ );
+ const timestamp = minTimestamp === Infinity ? undefined : minTimestamp;
const [postgresScoreRecord, clickhouseScoreRecord, scoreRecords] =
await Promise.all([
this.getPostgresRecord({
@@ -133,7 +139,12 @@ export class IngestionService {
projectId,
entityId,
table: TableName.Scores,
- additionalFilters: { whereCondition: "", params: {} },
+ additionalFilters: {
+ whereCondition: timestamp
+ ? " AND timestamp >= {timestamp: DateTime} - INTERVAL 1 DAY "
+ : "",
+ params: { timestamp },
+ },
}),
Promise.all(
timeSortedEvents.map(async (scoreEvent) => {
@@ -191,6 +202,12 @@ export class IngestionService {
traceEventList: timeSortedEvents,
});
+ const minTimestamp = Math.min(
+ ...timeSortedEvents.flatMap((e) =>
+ e.body?.timestamp ? [new Date(e.body.timestamp).getTime()] : [],
+ ),
+ );
+ const timestamp = minTimestamp === Infinity ? undefined : minTimestamp;
const [postgresTraceRecord, clickhouseTraceRecord] = await Promise.all([
this.getPostgresRecord({
projectId,
@@ -201,7 +218,12 @@ export class IngestionService {
projectId,
entityId,
table: TableName.Traces,
- additionalFilters: { whereCondition: "", params: {} },
+ additionalFilters: {
+ whereCondition: timestamp
+ ? " AND timestamp >= {timestamp: DateTime} - INTERVAL 1 DAY "
+ : "",
+ params: { timestamp },
+ },
}),
]);
@@ -226,6 +248,12 @@ export class IngestionService {
IngestionService.toTimeSortedEventList(observationEventList);
const type = this.getObservationType(observationEventList[0]);
+ const minStartTime = Math.min(
+ ...observationEventList.flatMap((e) =>
+ e.body?.startTime ? [new Date(e.body.startTime).getTime()] : [],
+ ),
+ );
+ const startTime = minStartTime === Infinity ? undefined : minStartTime;
const [postgresObservationRecord, clickhouseObservationRecord, prompt] =
await Promise.all([
this.getPostgresRecord({
@@ -238,8 +266,8 @@ export class IngestionService {
entityId,
table: TableName.Observations,
additionalFilters: {
- whereCondition: "AND type = {type: String}",
- params: { type },
+ whereCondition: `AND type = {type: String} ${startTime ? "AND start_time >= {startTime: DateTime} - INTERVAL 1 DAY" : ""}`,
+ params: { type, startTime },
},
}),
this.getPrompt(projectId, observationEventList),
diff --git a/worker/src/services/IngestionService/tests/IngestionService.integration.test.ts b/worker/src/services/IngestionService/tests/IngestionService.integration.test.ts
index 73c7e0f07e..5fc364769d 100644
--- a/worker/src/services/IngestionService/tests/IngestionService.integration.test.ts
+++ b/worker/src/services/IngestionService/tests/IngestionService.integration.test.ts
@@ -1259,9 +1259,6 @@ describe("Ingestion end-to-end tests", () => {
const observationId = randomUUID();
const latestEvent = new Date();
- const oldEvent = new Date(latestEvent).setSeconds(
- latestEvent.getSeconds() - 1,
- );
const observationEventList1: ObservationEvent[] = [
{
@@ -1271,6 +1268,7 @@ describe("Ingestion end-to-end tests", () => {
body: {
id: observationId,
traceId: traceId,
+ startTime: new Date().toISOString(),
output: "to overwrite",
usage: undefined,
},