Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(frontend): auto-refresh task run logs for running tasks (#18367)

boojacke3c596cb1949
diff --git a/frontend/src/components/Plan/components/AddSpecDrawer.vue b/frontend/src/components/Plan/components/AddSpecDrawer.vue
index 3bade7c238..efbc9b67cc 100644
--- a/frontend/src/components/Plan/components/AddSpecDrawer.vue
+++ b/frontend/src/components/Plan/components/AddSpecDrawer.vue
@@ -1,8 +1,8 @@
<template>
<Drawer
- v-model:show="show"
- :mask-closable="false"
placement="right"
+ v-model:show="show"
+ :mask-closable="true"
:resizable="true"
>
<DrawerContent
diff --git a/frontend/src/components/Plan/components/RolloutView/v2/LatestTaskRunInfo.vue b/frontend/src/components/Plan/components/RolloutView/v2/LatestTaskRunInfo.vue
index b26fce9fdb..a7e83d0acc 100644
--- a/frontend/src/components/Plan/components/RolloutView/v2/LatestTaskRunInfo.vue
+++ b/frontend/src/components/Plan/components/RolloutView/v2/LatestTaskRunInfo.vue
@@ -6,57 +6,45 @@
<span class="font-medium text-gray-700 shrink-0">{{
t("task-run.latest")
}}</span>
- <span class="text-gray-300">·</span>
+ <Separator />
<!-- Status badge -->
- <span class="flex items-center gap-x-1 shrink-0" :class="statusClass">
+ <span
+ class="flex items-center gap-x-1 shrink-0"
+ :class="statusConfig.class"
+ >
<component
- :is="statusIcon"
+ :is="statusConfig.icon"
class="w-4 h-4"
- :class="{ 'animate-spin': taskStatus === Task_Status.RUNNING }"
+ :class="{ 'animate-spin': status === Task_Status.RUNNING }"
/>
- <span>{{ statusText }}</span>
+ <span>{{ t(statusConfig.textKey) }}</span>
</span>
- <span class="text-gray-300">·</span>
+ <Separator />
<!-- Timestamp -->
<span class="text-gray-500 shrink-0">
- <Timestamp :timestamp="taskRun.updateTime" />
+ <Timestamp :timestamp="updateTime" />
</span>
<!-- Metadata items -->
<template v-if="executorEmail">
- <span class="text-gray-300">·</span>
- <NTooltip>
- <template #trigger>
- <span class="flex items-center gap-x-1 text-gray-500 min-w-0 cursor-default">
- <UserIcon class="w-3.5 h-3.5 shrink-0" />
- <span class="truncate">{{ executorEmail }}</span>
- </span>
- </template>
- {{ t("task.executed-by") }}
- </NTooltip>
+ <Separator />
+ <MetadataItem :tooltip="t('task.executed-by')">
+ <UserIcon class="w-3.5 h-3.5 shrink-0" />
+ <span class="truncate">{{ executorEmail }}</span>
+ </MetadataItem>
</template>
<template v-if="duration">
- <span class="text-gray-300">·</span>
- <NTooltip>
- <template #trigger>
- <span class="flex items-center gap-x-1 text-gray-500 shrink-0 cursor-default">
- <ClockIcon class="w-3.5 h-3.5" />
- {{ duration }}
- </span>
- </template>
- {{ t("common.duration") }}
- </NTooltip>
+ <Separator />
+ <MetadataItem :tooltip="t('common.duration')">
+ <ClockIcon class="w-3.5 h-3.5" />
+ {{ duration }}
+ </MetadataItem>
</template>
<template v-if="affectedRowsDisplay">
- <span class="text-gray-300">·</span>
- <NTooltip>
- <template #trigger>
- <span class="flex items-center gap-x-1 text-gray-500 shrink-0 cursor-default">
- <RowsIcon class="w-3.5 h-3.5" />
- {{ affectedRowsDisplay }}
- </span>
- </template>
- {{ t("task.affected-rows") }}
- </NTooltip>
+ <Separator />
+ <MetadataItem :tooltip="t('task.affected-rows')">
+ <RowsIcon class="w-3.5 h-3.5" />
+ {{ affectedRowsDisplay }}
+ </MetadataItem>
</template>
</div>
@@ -71,6 +59,7 @@
</template>
<script lang="ts" setup>
+import type { Timestamp as TimestampType } from "@bufbuild/protobuf/wkt";
import {
CheckCircle2Icon,
CircleDotIcon,
@@ -81,14 +70,13 @@ import {
XCircleIcon,
} from "lucide-vue-next";
import { NTooltip } from "naive-ui";
-import type { Component } from "vue";
-import { computed } from "vue";
+import type { Component, FunctionalComponent } from "vue";
+import { computed, h } from "vue";
import { useI18n } from "vue-i18n";
import Timestamp from "@/components/misc/Timestamp.vue";
-import type { Task, TaskRun } from "@/types/proto-es/v1/rollout_service_pb";
import { Task_Status } from "@/types/proto-es/v1/rollout_service_pb";
import type { Sheet } from "@/types/proto-es/v1/sheet_service_pb";
-import { useTaskRunLogSummary } from "./composables/useTaskRunLogSummary";
+import type { TaskRunLogSummary } from "./composables/useTaskRunLogSummary";
import TaskRunLogEntries from "./TaskRunLogEntries.vue";
// Types
@@ -98,83 +86,84 @@ interface StatusConfig {
textKey: string;
}
-// Default status config
-const DEFAULT_STATUS_CONFIG: StatusConfig = {
- icon: CircleDotIcon,
- class: "text-gray-500",
- textKey: "common.unknown",
-};
+// Functional components for repeated patterns
+const Separator: FunctionalComponent = () =>
+ h("span", { class: "text-gray-300" }, "·");
+
+const MetadataItem: FunctionalComponent<{ tooltip: string }> = (
+ props,
+ { slots }
+) =>
+ h(NTooltip, null, {
+ trigger: () =>
+ h(
+ "span",
+ {
+ class:
+ "flex items-center gap-x-1 text-gray-500 shrink-0 cursor-default",
+ },
+ slots.default?.()
+ ),
+ default: () => props.tooltip,
+ });
-// Constants
-const STATUS_CONFIG: Partial<Record<Task_Status, StatusConfig>> = {
+// Status configuration - defined outside setup for better performance
+const STATUS_CONFIG: Record<Task_Status, StatusConfig> = {
[Task_Status.FAILED]: {
icon: XCircleIcon,
class: "text-red-600",
- textKey: "common.failed",
+ textKey: "task.status.failed",
},
[Task_Status.RUNNING]: {
icon: LoaderCircleIcon,
class: "text-blue-600",
- textKey: "common.running",
+ textKey: "task.status.running",
},
[Task_Status.DONE]: {
icon: CheckCircle2Icon,
class: "text-green-600",
- textKey: "common.success",
+ textKey: "task.status.done",
},
[Task_Status.PENDING]: {
icon: CircleDotIcon,
class: "text-gray-500",
- textKey: "common.pending",
+ textKey: "task.status.pending",
},
[Task_Status.SKIPPED]: {
icon: CircleDotIcon,
class: "text-gray-500",
- textKey: "common.skipped",
+ textKey: "task.status.skipped",
},
[Task_Status.CANCELED]: {
icon: CircleDotIcon,
class: "text-gray-500",
- textKey: "common.canceled",
+ textKey: "task.status.canceled",
},
[Task_Status.NOT_STARTED]: {
icon: CircleDotIcon,
class: "text-gray-500",
- textKey: "common.pending",
+ textKey: "task.status.not-started",
+ },
+ [Task_Status.STATUS_UNSPECIFIED]: {
+ icon: CircleDotIcon,
+ class: "text-gray-500",
+ textKey: "common.unknown",
},
};
-// Props
+// Props - simplified to only required fields
const props = defineProps<{
- task: Task;
- taskRun: TaskRun;
+ status: Task_Status;
+ updateTime?: TimestampType;
sheet?: Sheet;
executorEmail?: string;
duration?: string;
+ affectedRowsDisplay?: string;
+ summary: TaskRunLogSummary;
}>();
const { t } = useI18n();
-// Status display
-const taskStatus = computed(() => props.task.status);
-
-const statusConfig = computed(() => {
- return STATUS_CONFIG[taskStatus.value] ?? DEFAULT_STATUS_CONFIG;
-});
-const statusIcon = computed(() => statusConfig.value.icon);
-const statusClass = computed(() => statusConfig.value.class);
-const statusText = computed(() => t(statusConfig.value.textKey));
-
-// Fetch and summarize task run log
-const { summary } = useTaskRunLogSummary(
- () => props.taskRun,
- () => true
-);
-
-const affectedRowsDisplay = computed(() => {
- if (!summary.value.hasAffectedRows) return "";
- const rows = summary.value.totalAffectedRows;
- if (rows <= BigInt(0)) return "";
- return `${rows.toLocaleString()} row${rows === BigInt(1) ? "" : "s"}`;
-});
+// Single computed for status - eliminates computed chain
+const statusConfig = computed(() => STATUS_CONFIG[props.status]);
</script>
diff --git a/frontend/src/components/Plan/components/RolloutView/v2/TaskItem.vue b/frontend/src/components/Plan/components/RolloutView/v2/TaskItem.vue
index f3ba34d263..49f14892dc 100644
--- a/frontend/src/components/Plan/components/RolloutView/v2/TaskItem.vue
+++ b/frontend/src/components/Plan/components/RolloutView/v2/TaskItem.vue
@@ -87,16 +87,16 @@
<!-- Collapsed: contextual status line (time + error/skip) -->
<div
- v-if="!isExpanded && (latestTaskRun?.createTime || collapsedStatusText)"
+ v-if="!isExpanded && collapsedStatusText"
class="flex items-center gap-x-2 text-xs mt-1"
>
<NTag v-if="latestTaskRun?.createTime" size="tiny" round>
<Timestamp :timestamp="latestTaskRun.createTime" />
</NTag>
<span
- v-if="collapsedStatusText"
- class="truncate"
+ class="truncate cursor-pointer"
:class="task.status === Task_Status.FAILED ? 'text-red-600' : 'text-gray-500 italic'"
+ @click.stop="emit('toggle-expand')"
>
{{ collapsedStatusText }}
</span>
@@ -190,11 +190,13 @@
<!-- Latest Task Run Info -->
<LatestTaskRunInfo
v-if="latestTaskRun"
- :task="task"
- :task-run="latestTaskRun"
+ :status="task.status"
+ :update-time="latestTaskRun.updateTime"
:sheet="taskSheet"
:executor-email="executorEmail"
:duration="timingType !== 'scheduled' ? timingDisplay : undefined"
+ :affected-rows-display="affectedRowsDisplay"
+ :summary="taskRunLogSummary"
/>
</div>
</div>
diff --git a/frontend/src/components/Plan/components/RolloutView/v2/TaskRunLogEntries.vue b/frontend/src/components/Plan/components/RolloutView/v2/TaskRunLogEntries.vue
index 7059ab3028..471f40c93b 100644
--- a/frontend/src/components/Plan/components/RolloutView/v2/TaskRunLogEntries.vue
+++ b/frontend/src/components/Plan/components/RolloutView/v2/TaskRunLogEntries.vue
@@ -1,25 +1,20 @@
<template>
<NVirtualList
- v-if="entries.length > 0"
- :items="entries"
+ v-if="displayItems.length > 0"
+ :items="displayItems"
:item-size="20"
item-resizable
+ item-key="key"
class="w-full font-mono text-xs bg-gray-50 border border-gray-200 rounded p-2 max-h-48"
>
- <template #default="{ item: entry }">
+ <template #default="{ item }">
<div class="flex items-start gap-x-2 py-0.5">
- <span class="text-gray-400 shrink-0">{{
- formatLogTime(entry.logTime)
- }}</span>
- <span class="shrink-0" :class="getLogLevelClass(entry)"
- >[{{ getLogLevel(entry) }}]</span
+ <span class="text-gray-400 shrink-0">{{ item.time }}</span>
+ <span class="shrink-0" :class="item.levelClass"
+ >[{{ item.level }}]</span
>
- <span class="text-blue-600 shrink-0">{{
- getEntryTypeLabel(entry)
- }}</span>
- <span :class="getLogDetailClass(entry)">{{
- getEntryDetail(entry)
- }}</span>
+ <span class="text-blue-600 shrink-0">{{ item.typeLabel }}</span>
+ <span :class="item.detailClass">{{ item.detail }}</span>
</div>
</template>
</NVirtualList>
@@ -28,6 +23,7 @@
<script lang="ts" setup>
import type { Timestamp as PbTimestamp } from "@bufbuild/protobuf/wkt";
import { NVirtualList } from "naive-ui";
+import { computed } from "vue";
import { getDateForPbTimestampProtoEs } from "@/types";
import type { TaskRunLogEntry } from "@/types/proto-es/v1/rollout_service_pb";
import {
@@ -41,6 +37,16 @@ import { extractSheetCommandByIndex } from "@/utils";
// Types
type LogLevel = "ERR" | "WRN" | "INF";
+interface DisplayItem {
+ key: string; // Stable key based on timestamp
+ time: string;
+ level: LogLevel;
+ levelClass: string;
+ typeLabel: string;
+ detail: string;
+ detailClass: string;
+}
+
// Constants
const LOG_LEVEL_CONFIG: Record<
LogLevel,
@@ -124,14 +130,6 @@ const getLogLevel = (entry: TaskRunLogEntry): LogLevel => {
return "INF";
};
-const getLogLevelClass = (entry: TaskRunLogEntry): string => {
- return LOG_LEVEL_CONFIG[getLogLevel(entry)].levelClass;
-};
-
-const getLogDetailClass = (entry: TaskRunLogEntry): string => {
- return LOG_LEVEL_CONFIG[getLogLevel(entry)].detailClass;
-};
-
const getEntryTypeLabel = (entry: TaskRunLogEntry): string => {
return ENTRY_TYPE_LABELS[entry.type] ?? "LOG";
};
@@ -237,4 +235,32 @@ const getEntryDetail = (entry: TaskRunLogEntry): string => {
return "";
}
};
+
+// Generate stable key from timestamp
+const getEntryKey = (entry: TaskRunLogEntry, index: number): string => {
+ const ts = entry.logTime;
+ if (ts) {
+ // Use seconds + nanos for uniqueness
+ return `${ts.seconds}-${ts.nanos}`;
+ }
+ // Fallback to index if no timestamp
+ return `idx-${index}`;
+};
+
+// Pre-compute display data to avoid multiple function calls per render
+const displayItems = computed((): DisplayItem[] => {
+ return props.entries.map((entry, index) => {
+ const level = getLogLevel(entry);
+ const config = LOG_LEVEL_CONFIG[level];
+ return {
+ key: getEntryKey(entry, index),
+ time: formatLogTime(entry.logTime),
+ level,
+ levelClass: config.levelClass,
+ typeLabel: getEntryTypeLabel(entry),
+ detail: getEntryDetail(entry),
+ detailClass: config.detailClass,
+ };
+ });
+});
</script>
diff --git a/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskDisplay.ts b/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskDisplay.ts
index 9c397abbba..a5e7fd6e7f 100644
--- a/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskDisplay.ts
+++ b/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskDisplay.ts
@@ -4,8 +4,6 @@ import { useI18n } from "vue-i18n";
import type { Task, TaskRun } from "@/types/proto-es/v1/rollout_service_pb";
import { Task_Status, Task_Type } from "@/types/proto-es/v1/rollout_service_pb";
-const MAX_ERROR_PREVIEW_LENGTH = 100;
-
export interface UseTaskDisplayReturn {
taskTypeDisplay: ComputedRef<string>;
executorEmail: ComputedRef<string>;
@@ -60,16 +58,12 @@ export const useTaskDisplay = (
// Collapsed view: error or skip reason
const collapsedStatusText = computed(() => {
- const currentTask = task();
-
- if (currentTask.status === Task_Status.FAILED) {
- const detail = latestTaskRun()?.detail || "";
- const firstLine = detail.split("\n")[0];
- return firstLine.length > MAX_ERROR_PREVIEW_LENGTH
- ? `${firstLine.substring(0, MAX_ERROR_PREVIEW_LENGTH)}...`
- : firstLine;
+ const detail = latestTaskRun()?.detail || "";
+ if (detail) {
+ return detail;
}
+ const currentTask = task();
if (
currentTask.status === Task_Status.SKIPPED &&
currentTask.skippedReason
diff --git a/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskRunLogSummary.ts b/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskRunLogSummary.ts
index 0c6d7b465d..7e22e3d8a9 100644
--- a/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskRunLogSummary.ts
+++ b/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskRunLogSummary.ts
@@ -1,5 +1,6 @@
import type { ComputedRef, MaybeRefOrGetter } from "vue";
-import { computed, ref, toValue, watch } from "vue";
+import { computed, onUnmounted, ref, toValue, watch } from "vue";
+import { usePlanContext } from "@/components/Plan/logic/context";
import { useTaskRunLogStore } from "@/store/modules/v1/taskRunLog";
import type {
TaskRun,
@@ -14,6 +15,9 @@ export interface TaskRunLogSummary {
latestEntries: TaskRunLogEntry[];
}
+// Limit entries to prevent performance issues with large logs
+const MAX_DISPLAY_ENTRIES = 100;
+
export interface UseTaskRunLogSummaryReturn {
taskRunLog: ComputedRef<TaskRunLog | undefined>;
summary: ComputedRef<TaskRunLogSummary>;
@@ -24,29 +28,58 @@ export interface UseTaskRunLogSummaryReturn {
* Composable for fetching and summarizing task run logs.
* Provides affected rows count and log entries.
* Data is cached in the store, so multiple calls with the same taskRun are efficient.
+ * Listens to poller's "resource-refresh-completed" event to refetch logs when taskRuns are updated.
*/
export const useTaskRunLogSummary = (
taskRun: MaybeRefOrGetter<TaskRun | undefined>,
shouldFetch: MaybeRefOrGetter<boolean>
): UseTaskRunLogSummaryReturn => {
+ const { events } = usePlanContext();
const taskRunLogStore = useTaskRunLogStore();
const isLoading = ref(false);
+ const fetchLog = async (
+ taskRunName: string,
+ options?: { skipCache?: boolean }
+ ) => {
+ isLoading.value = true;
+ try {
+ await taskRunLogStore.fetchTaskRunLog(taskRunName, options);
+ } finally {
+ isLoading.value = false;
+ }
+ };
+
+ // Initial fetch when taskRun changes
watch(
[() => toValue(taskRun)?.name, () => toValue(shouldFetch)],
async ([taskRunName, fetch]) => {
if (fetch && taskRunName) {
- isLoading.value = true;
- try {
- await taskRunLogStore.fetchTaskRunLog(taskRunName);
- } finally {
- isLoading.value = false;
- }
+ await fetchLog(taskRunName);
}
},
{ immediate: true }
);
+ // Refetch logs when poller refreshes taskRuns (skip cache to get latest)
+ const unsubscribe = events.on(
+ "resource-refresh-completed",
+ async ({ resources }) => {
+ const taskRunName = toValue(taskRun)?.name;
+ if (
+ resources.includes("taskRuns") &&
+ toValue(shouldFetch) &&
+ taskRunName
+ ) {
+ await fetchLog(taskRunName, { skipCache: true });
+ }
+ }
+ );
+
+ onUnmounted(() => {
+ unsubscribe();
+ });
+
const taskRunLog = computed(() => {
const run = toValue(taskRun);
if (!run?.name) return undefined;
@@ -73,7 +106,11 @@ export const useTaskRunLogSummary = (
}
}
- result.latestEntries = [...log.entries].reverse();
+ // Get latest entries (reversed, limited for performance)
+ // Slice from the end to get latest entries, then reverse for display order
+ const entries = log.entries;
+ const startIndex = Math.max(0, entries.length - MAX_DISPLAY_ENTRIES);
+ result.latestEntries = entries.slice(startIndex).reverse();
return result;
});
diff --git a/frontend/src/store/modules/v1/taskRunLog.ts b/frontend/src/store/modules/v1/taskRunLog.ts
index 8b300e463b..3c5d744ef8 100644
--- a/frontend/src/store/modules/v1/taskRunLog.ts
+++ b/frontend/src/store/modules/v1/taskRunLog.ts
@@ -23,10 +23,15 @@ export const useTaskRunLogStore = defineStore("taskRunLog", () => {
return emptyLog;
};
- const fetchTaskRunLog = async (taskRunName: string): Promise<TaskRunLog> => {
- const existing = taskRunLogByName.get(taskRunName);
- if (existing) {
- return existing;
+ const fetchTaskRunLog = async (
+ taskRunName: string,
+ options?: { skipCache?: boolean }
+ ): Promise<TaskRunLog> => {
+ if (!options?.skipCache) {
+ const existing = taskRunLogByName.get(taskRunName);
+ if (existing) {
+ return existing;
+ }
}
try {