Skip to content

Commit 5e920b9

Browse files
committed
query optimization
1 parent 46db1b2 commit 5e920b9

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

apps/webapp/app/presenters/v3/LogDetailPresenter.server.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,10 @@ export class LogDetailPresenter {
8484
}
8585

8686
try {
87-
// Handle attributes which could be a JSON object or string
88-
if (log.attributes) {
89-
if (typeof log.attributes === "string") {
90-
parsedAttributes = JSON.parse(log.attributes) as Record<string, unknown>;
91-
rawAttributesString = log.attributes;
92-
} else if (typeof log.attributes === "object") {
93-
parsedAttributes = log.attributes as Record<string, unknown>;
94-
rawAttributesString = JSON.stringify(log.attributes);
95-
}
87+
// Handle attributes_text which is a string
88+
if (log.attributes_text) {
89+
parsedAttributes = JSON.parse(log.attributes_text) as Record<string, unknown>;
90+
rawAttributesString = log.attributes_text;
9691
}
9792
} catch {
9893
// Ignore parse errors

apps/webapp/app/presenters/v3/LogsListPresenter.server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import { findDisplayableEnvironment } from "~/models/runtimeEnvironment.server";
1919
import { getAllTaskIdentifiers } from "~/models/task.server";
2020
import { RunsRepository } from "~/services/runsRepository/runsRepository.server";
2121
import { ServiceValidationError } from "~/v3/services/baseService.server";
22+
import { kindToLevel, type LogLevel, LogLevelSchema } from "~/utils/logUtils";
23+
import { BasePresenter } from "~/presenters/v3/basePresenter.server";
2224
import {
2325
convertDateToClickhouseDateTime,
2426
convertClickhouseDateTime64ToJsDate,
2527
} from "~/v3/eventRepository/clickhouseEventRepository.server";
26-
import { kindToLevel, type LogLevel, LogLevelSchema } from "~/utils/logUtils";
27-
import { BasePresenter } from "~/presenters/v3/basePresenter.server";
2828

2929

3030
export type { LogLevel };
@@ -542,9 +542,9 @@ export class LogsListPresenter extends BasePresenter {
542542
let displayMessage = log.message;
543543

544544
// For error logs with status ERROR, try to extract error message from attributes
545-
if (log.status === "ERROR" && log.attributes) {
545+
if (log.status === "ERROR" && log.attributes_text) {
546546
try {
547-
let attributes = log.attributes as ErrorAttributes;
547+
let attributes = JSON.parse(log.attributes_text) as ErrorAttributes;
548548

549549
if (attributes?.error?.message && typeof attributes.error.message === "string") {
550550
displayMessage = attributes.error.message;

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.logs/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function LogsList({
227227
showDebug,
228228
defaultPeriod,
229229
}: {
230-
list: Awaited<UseDataFunctionReturn<typeof loader>["data"]>;
230+
list: Exclude<Awaited<UseDataFunctionReturn<typeof loader>["data"]>, { error: string }>; //exclude error, it is handled
231231
rootOnlyDefault: boolean;
232232
isAdmin: boolean;
233233
showDebug: boolean;

internal-packages/clickhouse/src/taskEvents.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export const LogsListResult = z.object({
250250
status: z.string(),
251251
duration: z.number().or(z.string()),
252252
metadata: z.string(),
253-
attributes: z.any(),
253+
attributes_text: z.string(),
254254
});
255255

256256
export type LogsListResult = z.output<typeof LogsListResult>;
@@ -274,7 +274,7 @@ export function getLogsListQueryBuilderV2(ch: ClickhouseReader, settings?: Click
274274
"status",
275275
"duration",
276276
"metadata",
277-
"attributes"
277+
"attributes_text"
278278
],
279279
settings,
280280
});
@@ -296,7 +296,7 @@ export const LogDetailV2Result = z.object({
296296
status: z.string(),
297297
duration: z.number().or(z.string()),
298298
metadata: z.string(),
299-
attributes: z.any()
299+
attributes_text: z.string()
300300
});
301301

302302
export type LogDetailV2Result = z.output<typeof LogDetailV2Result>;
@@ -320,7 +320,7 @@ export function getLogDetailQueryBuilderV2(ch: ClickhouseReader, settings?: Clic
320320
"status",
321321
"duration",
322322
"metadata",
323-
"attributes",
323+
"attributes_text",
324324
],
325325
settings,
326326
});
@@ -349,7 +349,7 @@ export function getLogsListQueryBuilderV1(ch: ClickhouseReader, settings?: Click
349349
"status",
350350
"duration",
351351
"metadata",
352-
"attributes"
352+
"attributes_text"
353353
],
354354
settings,
355355
});
@@ -374,7 +374,7 @@ export function getLogDetailQueryBuilderV1(ch: ClickhouseReader, settings?: Clic
374374
"status",
375375
"duration",
376376
"metadata",
377-
"attributes",
377+
"attributes_text",
378378
],
379379
settings,
380380
});

0 commit comments

Comments
 (0)