Skip to content

Commit 35cb92b

Browse files
guan404mingSudi-Lyu
authored andcommitted
Enable streaming log (apache#54445)
1 parent cce1876 commit 35cb92b

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

airflow-core/src/airflow/ui/src/pages/TaskInstance/Logs/Logs.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,6 @@ describe("Task log grouping", () => {
9898

9999
fireEvent.click(collapseItem);
100100

101-
expect(screen.getByText(/Marking task as SUCCESS/iu)).toBeVisible();
101+
await waitFor(() => expect(screen.queryByText(/Marking task as SUCCESS/iu)).toBeVisible());
102102
}, 10_000);
103103
});

airflow-core/src/airflow/ui/src/queries/useLogs.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type { TaskInstanceResponse, TaskInstancesLogResponse } from "openapi/req
2626
import { renderStructuredLog } from "src/components/renderStructuredLog";
2727
import { isStatePending, useAutoRefresh } from "src/utils";
2828
import { getTaskInstanceLink } from "src/utils/links";
29+
import { parseStreamingLogContent } from "src/utils/logs";
2930

3031
type Props = {
3132
accept?: "*/*" | "application/json" | "application/x-ndjson";
@@ -173,7 +174,7 @@ const parseLogs = ({
173174

174175
export const useLogs = (
175176
{
176-
accept = "application/json",
177+
accept = "application/x-ndjson",
177178
dagId,
178179
expanded,
179180
logLevelFilters,
@@ -209,7 +210,7 @@ export const useLogs = (
209210
);
210211

211212
const parsedData = parseLogs({
212-
data: data?.content ?? [],
213+
data: parseStreamingLogContent(data),
213214
expanded,
214215
logLevelFilters,
215216
showSource,

airflow-core/src/airflow/ui/src/utils/logs.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
/* eslint-disable perfectionist/sort-objects */
2323
import { createListCollection } from "@chakra-ui/react";
2424

25+
import type { TaskInstancesLogResponse } from "openapi/requests/types.gen";
26+
2527
export enum LogLevel {
2628
DEBUG = "debug",
2729
INFO = "info",
@@ -51,3 +53,22 @@ export const logLevelOptions = createListCollection<{
5153
{ label: LogLevel.CRITICAL.toUpperCase(), value: LogLevel.CRITICAL },
5254
],
5355
});
56+
57+
export const parseStreamingLogContent = (
58+
data: TaskInstancesLogResponse | undefined,
59+
): TaskInstancesLogResponse["content"] => {
60+
if (!data?.content) {
61+
const content = data as unknown as string;
62+
63+
try {
64+
return content
65+
.split("\n")
66+
.filter((line) => line.trim() !== "")
67+
.map((line) => JSON.parse(line) as string);
68+
} catch {
69+
return [];
70+
}
71+
}
72+
73+
return data.content;
74+
};

0 commit comments

Comments
 (0)