Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/webapp/app/presenters/v3/RunPresenter.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ export class RunPresenter {
run.status === "PAUSED" ||
run.status === "RETRYING_AFTER_FAILURE" ||
run.status === "DEQUEUED" ||
run.status === "EXECUTING",
run.status === "EXECUTING" ||
run.status === "WAITING_TO_RESUME",
isCancelled: run.status === "CANCELED",
isDebug: false,
level: "TRACE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ export class ClickhouseEventRepository implements IEventRepository {
span.setAttribute("flush_id", flushId);
span.setAttribute("event_count", events.length);

const firstEvent = events[0];

if (firstEvent) {
logger.debug("ClickhouseEventRepository.flushBatch first event", {
event: firstEvent,
});
}

const [insertError, insertResult] = await this._clickhouse.taskEvents.insert(events);

if (insertError) {
Expand Down Expand Up @@ -147,7 +155,7 @@ export class ClickhouseEventRepository implements IEventRepository {
project_id: event.projectId,
task_identifier: event.taskSlug,
run_id: event.runId,
start_time: event.startTime.toString(),
start_time: formatClickhouseDate64NanosecondsEpochString(event.startTime.toString()),
duration: (event.duration ?? 0).toString(),
trace_id: event.traceId,
span_id: event.spanId,
Expand Down Expand Up @@ -177,7 +185,11 @@ export class ClickhouseEventRepository implements IEventRepository {
}

// Only return events where the event start_time is greater than the span start_time
return records.filter((r) => BigInt(r.start_time) > BigInt(event.startTime));
return records.filter(
(r) =>
convertClickhouseDate64NanosecondsEpochStringToBigInt(r.start_time) >
BigInt(event.startTime)
);
}

private createTaskEventV1InputFromSpanEvent(
Expand Down Expand Up @@ -209,7 +221,9 @@ export class ClickhouseEventRepository implements IEventRepository {
project_id: event.projectId,
task_identifier: event.taskSlug,
run_id: event.runId,
start_time: convertDateToNanoseconds(spanEvent.time).toString(),
start_time: formatClickhouseDate64NanosecondsEpochString(
convertDateToNanoseconds(spanEvent.time).toString()
),
duration: "0", // Events have no duration
trace_id: event.traceId,
span_id: event.spanId,
Expand Down Expand Up @@ -243,7 +257,9 @@ export class ClickhouseEventRepository implements IEventRepository {
project_id: event.projectId,
task_identifier: event.taskSlug,
run_id: event.runId,
start_time: convertDateToNanoseconds(spanEvent.time).toString(),
start_time: formatClickhouseDate64NanosecondsEpochString(
convertDateToNanoseconds(spanEvent.time).toString()
),
duration: "0", // Events have no duration
trace_id: event.traceId,
span_id: event.spanId,
Expand Down Expand Up @@ -271,7 +287,9 @@ export class ClickhouseEventRepository implements IEventRepository {
project_id: event.projectId,
task_identifier: event.taskSlug,
run_id: event.runId,
start_time: convertDateToNanoseconds(spanEvent.time).toString(),
start_time: formatClickhouseDate64NanosecondsEpochString(
convertDateToNanoseconds(spanEvent.time).toString()
),
duration: "0", // Events have no duration
trace_id: event.traceId,
span_id: event.spanId,
Expand Down Expand Up @@ -303,7 +321,9 @@ export class ClickhouseEventRepository implements IEventRepository {
project_id: event.projectId,
task_identifier: event.taskSlug,
run_id: event.runId,
start_time: convertDateToNanoseconds(spanEvent.time).toString(),
start_time: formatClickhouseDate64NanosecondsEpochString(
convertDateToNanoseconds(spanEvent.time).toString()
),
duration: "0", // Events have no duration
trace_id: event.traceId,
span_id: event.spanId,
Expand Down Expand Up @@ -439,7 +459,7 @@ export class ClickhouseEventRepository implements IEventRepository {
project_id: options.environment.projectId,
task_identifier: options.taskSlug,
run_id: options.attributes.runId,
start_time: startTime.toString(),
start_time: formatClickhouseDate64NanosecondsEpochString(startTime.toString()),
duration: duration.toString(),
trace_id: traceId,
span_id: spanId,
Expand Down Expand Up @@ -540,7 +560,7 @@ export class ClickhouseEventRepository implements IEventRepository {
project_id: options.environment.projectId,
task_identifier: options.taskSlug,
run_id: options.attributes.runId,
start_time: startTime.toString(),
start_time: formatClickhouseDate64NanosecondsEpochString(startTime.toString()),
duration: String(options.incomplete ? 0 : duration),
trace_id: traceId,
span_id: spanId,
Expand Down Expand Up @@ -574,7 +594,7 @@ export class ClickhouseEventRepository implements IEventRepository {
project_id: options.environment.projectId,
task_identifier: options.taskSlug,
run_id: options.attributes.runId,
start_time: startTime.toString(),
start_time: formatClickhouseDate64NanosecondsEpochString(startTime.toString()),
duration: String(options.incomplete ? 0 : duration),
trace_id: traceId,
span_id: spanId,
Expand Down Expand Up @@ -623,7 +643,7 @@ export class ClickhouseEventRepository implements IEventRepository {
project_id: run.projectId,
task_identifier: run.taskIdentifier,
run_id: run.friendlyId,
start_time: startTime.toString(),
start_time: formatClickhouseDate64NanosecondsEpochString(startTime.toString()),
duration: calculateDurationFromStart(startTime, endTime ?? new Date()).toString(),
trace_id: run.traceId,
span_id: run.spanId,
Expand Down Expand Up @@ -671,7 +691,7 @@ export class ClickhouseEventRepository implements IEventRepository {
project_id: run.projectId,
task_identifier: run.taskIdentifier,
run_id: blockedRun.friendlyId,
start_time: startTime.toString(),
start_time: formatClickhouseDate64NanosecondsEpochString(startTime.toString()),
duration: calculateDurationFromStart(startTime, endTime ?? new Date()).toString(),
trace_id: blockedRun.traceId,
span_id: spanId,
Expand Down Expand Up @@ -711,7 +731,7 @@ export class ClickhouseEventRepository implements IEventRepository {
project_id: run.projectId,
task_identifier: run.taskIdentifier,
run_id: run.friendlyId,
start_time: startTime.toString(),
start_time: formatClickhouseDate64NanosecondsEpochString(startTime.toString()),
duration: calculateDurationFromStart(startTime, endTime ?? new Date()).toString(),
trace_id: run.traceId,
span_id: run.spanId,
Expand Down Expand Up @@ -757,7 +777,7 @@ export class ClickhouseEventRepository implements IEventRepository {
project_id: run.projectId,
task_identifier: run.taskIdentifier,
run_id: run.friendlyId,
start_time: startTime.toString(),
start_time: formatClickhouseDate64NanosecondsEpochString(startTime.toString()),
duration: calculateDurationFromStart(startTime, endTime ?? new Date()).toString(),
trace_id: run.traceId,
span_id: run.spanId,
Expand Down Expand Up @@ -803,7 +823,7 @@ export class ClickhouseEventRepository implements IEventRepository {
project_id: run.projectId,
task_identifier: run.taskIdentifier,
run_id: run.friendlyId,
start_time: startTime.toString(),
start_time: formatClickhouseDate64NanosecondsEpochString(startTime.toString()),
duration: "0",
trace_id: run.traceId,
span_id: run.spanId,
Expand Down Expand Up @@ -847,7 +867,7 @@ export class ClickhouseEventRepository implements IEventRepository {
project_id: run.projectId,
task_identifier: run.taskIdentifier,
run_id: run.friendlyId,
start_time: startTime.toString(),
start_time: formatClickhouseDate64NanosecondsEpochString(startTime.toString()),
duration: calculateDurationFromStart(startTime, cancelledAt).toString(),
trace_id: run.traceId,
span_id: run.spanId,
Expand Down Expand Up @@ -1807,3 +1827,17 @@ function isLogEvent(kind: string): boolean {
function calculateEndTimeFromStartTime(startTime: Date, duration: number): Date {
return new Date(startTime.getTime() + duration / 1_000_000);
}

// This will take a string like "1759427319944999936" and return "1759427319.944999936"
function formatClickhouseDate64NanosecondsEpochString(date: string): string {
if (date.length !== 19) {
return date;
}

return date.substring(0, 10) + "." + date.substring(10);
}

function convertClickhouseDate64NanosecondsEpochStringToBigInt(date: string): bigint {
const parts = date.split(".");
return BigInt(parts.join(""));
}