Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change DAG Audit log tab to Event Log #40967

Merged
merged 3 commits into from
Jul 24, 2024
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
13 changes: 12 additions & 1 deletion airflow/api_connexion/openapi/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3430,6 +3430,16 @@ components:
type: string
readOnly: true
nullable: true
map_index:
description: The Map Index
type: integer
readOnly: true
nullable: true
try_number:
description: The Try Number
type: integer
readOnly: true
nullable: true
event:
description: A key describing the type of event.
type: string
Expand Down Expand Up @@ -3459,6 +3469,7 @@ components:
Collection of event logs.

*Changed in version 2.1.0*: 'total_entries' field is added.
*Changed in version 2.10.0*: 'try_number' and 'map_index' fields are added.
allOf:
- type: object
properties:
Expand Down Expand Up @@ -3487,7 +3498,7 @@ components:
stack_trace:
type: string
readOnly: true
description: The full stackstrace..
description: The full stackstrace.

ImportErrorCollection:
type: object
Expand Down
7 changes: 5 additions & 2 deletions airflow/www/static/js/components/NewTable/NewCells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@

import React from "react";
import { Code } from "@chakra-ui/react";
import type { CellContext } from "@tanstack/react-table";

import Time from "src/components/Time";

export const TimeCell = ({ getValue }: any) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const TimeCell = ({ getValue }: CellContext<any, any>) => {
const value = getValue();
return <Time dateTime={value} />;
};

export const CodeCell = ({ getValue }: any) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const CodeCell = ({ getValue }: CellContext<any, any>) => {
const value = getValue();
return value ? <Code>{value}</Code> : null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { useEventLogs } from "src/api";
import { getMetaValue, useOffsetTop } from "src/utils";
import type { DagRun } from "src/types";
import LinkButton from "src/components/LinkButton";
import type { EventLog } from "src/types/api-generated";
import type { EventLog as EventLogType } from "src/types/api-generated";
import { NewTable } from "src/components/NewTable/NewTable";
import { useTableURLState } from "src/components/NewTable/useTableUrlState";
import { CodeCell, TimeCell } from "src/components/NewTable/NewCells";
Expand All @@ -60,6 +60,7 @@ const configIncludedEvents = getMetaValue("included_audit_log_events");

interface Props {
taskId?: string;
showMapped?: boolean;
run?: DagRun;
}

Expand All @@ -70,9 +71,9 @@ interface Option extends OptionBase {

const dagId = getMetaValue("dag_id") || undefined;

const columnHelper = createColumnHelper<EventLog>();
const columnHelper = createColumnHelper<EventLogType>();

const AuditLog = ({ taskId, run }: Props) => {
const EventLog = ({ taskId, run, showMapped }: Props) => {
const logRef = useRef<HTMLDivElement>(null);
const offsetTop = useOffsetTop(logRef);
const { tableURLState, setTableURLState } = useTableURLState({
Expand Down Expand Up @@ -138,31 +139,48 @@ const AuditLog = ({ taskId, run }: Props) => {
const runId = columnHelper.accessor("runId", {
header: "Run Id",
});

const mapIndex = columnHelper.accessor("mapIndex", {
header: "Map Index",
enableSorting: false,
meta: {
skeletonWidth: 10,
},
cell: (props) => (props.getValue() === -1 ? undefined : props.getValue()),
});
const rest = [
columnHelper.accessor("tryNumber", {
header: "Try Number",
enableSorting: false,
meta: {
skeletonWidth: 10,
},
}),
columnHelper.accessor("event", {
header: "Event",
meta: {
skeletonWidth: 40,
},
}),
columnHelper.accessor("owner", {
header: "Owner",
header: "User",
meta: {
skeletonWidth: 20,
},
}),
columnHelper.accessor("extra", {
header: "Extra",
header: "Details",
cell: CodeCell,
}),
];
return [
when,
...(!run ? [runId] : []),
...(!taskId ? [task] : []),
...(showMapped ? [mapIndex] : []),
...rest,
];
}, [taskId, run]);
}, [taskId, run, showMapped]);

const memoData = useMemo(() => data?.eventLogs, [data?.eventLogs]);

Expand Down Expand Up @@ -262,4 +280,4 @@ const AuditLog = ({ taskId, run }: Props) => {
);
};

export default AuditLog;
export default EventLog;
14 changes: 8 additions & 6 deletions airflow/www/static/js/dag/details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ import {
MdOutlineViewTimeline,
MdSyncAlt,
MdHourglassBottom,
MdPlagiarism,
MdEvent,
MdOutlineEventNote,
} from "react-icons/md";
import { BiBracket, BiLogoKubernetes } from "react-icons/bi";
import URLSearchParamsWrapper from "src/utils/URLSearchParamWrapper";
Expand All @@ -65,7 +65,7 @@ import ClearInstance from "./taskInstance/taskActions/ClearInstance";
import MarkInstanceAs from "./taskInstance/taskActions/MarkInstanceAs";
import XcomCollection from "./taskInstance/Xcom";
import TaskDetails from "./task";
import AuditLog from "./AuditLog";
import EventLog from "./EventLog";
import RunDuration from "./dag/RunDuration";
import Calendar from "./dag/Calendar";
import RenderedK8s from "./taskInstance/RenderedK8s";
Expand All @@ -90,6 +90,7 @@ const tabToIndex = (tab?: string) => {
return 2;
case "code":
return 3;
case "event_log":
case "audit_log":
return 4;
case "logs":
Expand Down Expand Up @@ -130,7 +131,7 @@ const indexToTab = (
case 3:
return "code";
case 4:
return "audit_log";
return "event_log";
case 5:
if (isMappedTaskSummary) return "mapped_tasks";
if (isTaskInstance) return "logs";
Expand Down Expand Up @@ -323,9 +324,9 @@ const Details = ({
</Text>
</Tab>
<Tab>
<MdPlagiarism size={16} />
<MdOutlineEventNote size={16} />
<Text as="strong" ml={1}>
Audit Log
Event Log
</Text>
</Tab>
{isDag && (
Expand Down Expand Up @@ -438,8 +439,9 @@ const Details = ({
<DagCode />
</TabPanel>
<TabPanel height="100%">
<AuditLog
<EventLog
taskId={isGroup || !taskId ? undefined : taskId}
showMapped={isMapped || !taskId}
run={run}
/>
</TabPanel>
Expand Down
18 changes: 17 additions & 1 deletion airflow/www/static/js/dag/details/taskInstance/Logs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import React, { useState, useEffect, useMemo } from "react";
import { Text, Box, Flex, Checkbox, Icon, Spinner } from "@chakra-ui/react";
import { MdWarning } from "react-icons/md";
import { MdInfo, MdWarning } from "react-icons/md";

import { getMetaValue } from "src/utils";
import useTaskLog from "src/api/useTaskLog";
Expand Down Expand Up @@ -248,11 +248,27 @@ const Logs = ({
borderColor="gray.400"
alignItems="center"
p={2}
mb={2}
>
<Icon as={MdWarning} color="yellow.500" mr={2} />
<Text fontSize="sm">{warning}</Text>
</Flex>
)}
{(!data || !parsedLogs) && !isLoading && (
<Flex
bg="blue.100"
borderRadius={2}
borderColor="gray.400"
alignItems="center"
p={2}
mb={2}
>
<Icon as={MdInfo} color="blue.600" mr={2} />
<Text fontSize="sm">
No task logs found. Try the Event Log tab for more context.
</Text>
</Flex>
)}
{isLoading ? (
<Spinner />
) : (
Expand Down
7 changes: 6 additions & 1 deletion airflow/www/static/js/types/api-generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,10 @@ export interface components {
task_id?: string | null;
/** @description The DAG Run ID */
run_id?: string | null;
/** @description The Map Index */
map_index?: number | null;
/** @description The Try Number */
try_number?: number | null;
/** @description A key describing the type of event. */
event?: string;
/**
Expand All @@ -1300,6 +1304,7 @@ export interface components {
* @description Collection of event logs.
*
* *Changed in version 2.1.0*&#58; 'total_entries' field is added.
* *Changed in version 2.10.0*&#58; 'try_number' and 'map_index' fields are added.
*/
EventLogCollection: {
event_logs?: components["schemas"]["EventLog"][];
Expand All @@ -1314,7 +1319,7 @@ export interface components {
timestamp?: string;
/** @description The filename */
filename?: string;
/** @description The full stackstrace.. */
/** @description The full stackstrace. */
stack_trace?: string;
};
/**
Expand Down