Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(frontend): show task run log detail (#11949)
Liu Jif4893d33afbc
diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/AffectedRowsCell.vue b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/AffectedRowsCell.vuenew file mode 100644index 0000000000..8a58beda14--- /dev/null+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/AffectedRowsCell.vue@@ -0,0 +1,33 @@+<template>+ <div class="text-sm">+ <div v-if="!isNaN(affectedRows)">{{ affectedRows }}</div>+ <div v-else class="text-control-placeholder">-</div>+ </div>+</template>++<script setup lang="ts">+import { computed } from "vue";+import { TaskRunLogEntry_Type } from "@/types/proto/v1/rollout_service";+import type { Sheet } from "@/types/proto/v1/sheet_service";+import type { FlattenLogEntry } from "./common";++const props = defineProps<{+ entry: FlattenLogEntry;+ sheet?: Sheet;+}>();++const affectedRows = computed(() => {+ const { entry } = props;+ if (entry.type === TaskRunLogEntry_Type.SCHEMA_DUMP && entry.schemaDump) {+ return Number.NaN;+ }+ if (+ entry.type === TaskRunLogEntry_Type.COMMAND_EXECUTE &&+ entry.commandExecute+ ) {+ const exec = entry.commandExecute;+ return exec.affectedRows ?? Number.NaN;+ }+ return Number.NaN;+});+</script>diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/DurationCell.vue b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/DurationCell.vuenew file mode 100644index 0000000000..5f6e06720d--- /dev/null+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/DurationCell.vue@@ -0,0 +1,37 @@+<template>+ <div class="text-sm">+ <div v-if="duration">+ {{ humanizeDurationV1(duration) }}+ </div>+ <div v-else class="text-control-placeholder">-</div>+ </div>+</template>++<script setup lang="ts">+import { computed } from "vue";+import { Duration } from "@/types/proto/google/protobuf/duration";+import type { FlattenLogEntry } from "./common";++const props = defineProps<{+ entry: FlattenLogEntry;+}>();++const toDuration = (startTime: Date, endTime: Date) => {+ const ms = endTime.getTime() - startTime.getTime();+ const seconds = Math.floor(ms / 1000);+ const nanos = (ms % 1000) * 1e6;+ return Duration.fromPartial({+ seconds,+ nanos,+ });+};++const duration = computed(() => {+ const { entry } = props;+ const { startTime, endTime } = entry;+ if (startTime && endTime) {+ return toDuration(startTime, endTime);+ }+ return undefined;+});+</script>diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/StatementCell.vue b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/StatementCell.vuenew file mode 100644index 0000000000..511acae4f4--- /dev/null+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/StatementCell.vue@@ -0,0 +1,94 @@+<template>+ <div class="text-sm group">+ <TextOverflowPopover+ v-if="statement"+ :content="statement.trim()"+ :max-length="100"+ :max-popover-content-length="1000"+ :line-wrap="false"+ :line-break-replacer="' '"+ code-class="relative"+ placement="top"+ >+ <template #default="{ displayContent }">+ <span class="flex-1 flex flex-row justify-start items-center gap-x-1">+ <span class="line-clamp-1">+ {{ displayContent }}+ </span>+ <NButton+ text+ size="tiny"+ class="invisible group-hover:visible"+ @click="copyStatement"+ >+ <template #icon>+ <CopyIcon class="w-3 h-3" />+ </template>+ </NButton>+ </span>+ </template>+ <template #popover-header>+ <div class="absolute bottom-1 right-1">+ <NButton text size="tiny" @click="copyStatement">+ <template #icon>+ <CopyIcon class="w-3 h-3" />+ </template>+ </NButton>+ </div>+ </template>+ </TextOverflowPopover>+ <div v-else class="text-control-placeholder">-</div>+ </div>+</template>++<script setup lang="ts">+import { CopyIcon } from "lucide-vue-next";+import { NButton } from "naive-ui";+import { computed } from "vue";+import { useI18n } from "vue-i18n";+import TextOverflowPopover from "@/components/misc/TextOverflowPopover.vue";+import { pushNotification } from "@/store";+import { TaskRunLogEntry_Type } from "@/types/proto/v1/rollout_service";+import type { Sheet } from "@/types/proto/v1/sheet_service";+import { extractSheetCommandByIndex, toClipboard } from "@/utils";+import type { FlattenLogEntry } from "./common";++const props = defineProps<{+ entry: FlattenLogEntry;+ sheet?: Sheet;+}>();++const { t } = useI18n();++const statement = computed(() => {+ const { entry, sheet } = props;+ if (entry.type === TaskRunLogEntry_Type.SCHEMA_DUMP && entry.schemaDump) {+ return "";+ }+ if (+ entry.type === TaskRunLogEntry_Type.COMMAND_EXECUTE &&+ entry.commandExecute+ ) {+ if (!sheet) {+ return "";+ }+ if (!sheet.payload?.commands) {+ return "";+ }++ const { commandExecute } = entry;+ return extractSheetCommandByIndex(sheet, commandExecute.commandIndex) ?? "";+ }+ return "";+});++const copyStatement = () => {+ toClipboard(statement.value.trim()).then(() => {+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("common.copied"),+ });+ });+};+</script>diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/TaskRunLogTable.vue b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/TaskRunLogTable.vuenew file mode 100644index 0000000000..028b56be04--- /dev/null+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/TaskRunLogTable.vue@@ -0,0 +1,202 @@+<template>+ <NDataTable+ :columns="columns"+ :loading="isLoading"+ :data="flattenLogEntries"+ :row-key="rowKey"+ size="small"+ />+</template>++<script setup lang="tsx">+import { computedAsync } from "@vueuse/core";+import { NDataTable, type DataTableColumn } from "naive-ui";+import { computed, ref } from "vue";+import { useI18n } from "vue-i18n";+import { useIssueContext } from "@/components/IssueV1";+import { rolloutServiceClient } from "@/grpcweb";+import { useSheetV1Store } from "@/store";+import {+ type TaskRun,+ TaskRunLogEntry_Type,+} from "@/types/proto/v1/rollout_service";+import { sheetNameOfTaskV1 } from "@/utils";+import AffectedRowsCell from "./AffectedRowsCell.vue";+import DurationCell from "./DurationCell.vue";+import StatementCell from "./StatementCell.vue";+import { type FlattenLogEntry } from "./common";++const props = defineProps<{+ taskRun: TaskRun;+}>();++const { t } = useI18n();+const { selectedTask } = useIssueContext();+const isLoadingTaskRunLog = ref(false);+const isLoadingSheet = ref(false);+const isLoading = computed(() => {+ return isLoadingTaskRunLog.value || isLoadingSheet.value;+});+const taskRunLog = computedAsync(+ () => {+ return rolloutServiceClient.getTaskRunLog({+ parent: props.taskRun.name,+ });+ },+ undefined,+ {+ evaluating: isLoadingTaskRunLog,+ }+);+const sheetName = computed(() => {+ return sheetNameOfTaskV1(selectedTask.value);+});+const sheet = computedAsync(+ async () => {+ const name = sheetName.value;+ return useSheetV1Store().getOrFetchSheetByName(name, "FULL");+ },+ undefined,+ {+ evaluating: isLoadingSheet,+ }+);+const logEntries = computed(() => {+ if (isLoading.value) return [];+ if (!sheet.value) return [];+ return taskRunLog.value?.entries ?? [];+});+const flattenLogEntries = computed(() => {+ const flattenEntries: FlattenLogEntry[] = [];+ logEntries.value.forEach((entry, batch) => {+ if (entry.type === TaskRunLogEntry_Type.SCHEMA_DUMP && entry.schemaDump) {+ const { schemaDump } = entry;+ flattenEntries.push({+ batch,+ serial: 0,+ type: TaskRunLogEntry_Type.SCHEMA_DUMP,+ startTime: schemaDump.startTime,+ endTime: schemaDump.endTime,+ schemaDump,+ });+ }+ if (+ entry.type === TaskRunLogEntry_Type.COMMAND_EXECUTE &&+ entry.commandExecute+ ) {+ const { commandExecute } = entry;+ const { response, logTime: startTime } = commandExecute;+ commandExecute.commandIndexes.forEach((commandIndex, serial) => {+ const affectedRows = response?.allAffectedRows[serial];+ const endTime = response?.logTime;+ flattenEntries.push({+ batch,+ serial,+ type: TaskRunLogEntry_Type.COMMAND_EXECUTE,+ startTime,+ endTime,+ commandExecute: {+ raw: commandExecute,+ commandIndex,+ affectedRows,+ },+ });+ });+ }+ });+ return flattenEntries;+});++const rowKey = (entry: FlattenLogEntry) => {+ return `${entry.batch}-${entry.serial}`;+};+const rowSpan = (entry: FlattenLogEntry) => {+ if (+ entry.type === TaskRunLogEntry_Type.COMMAND_EXECUTE &&+ entry.commandExecute+ ) {+ const { commandExecute } = entry;+ return commandExecute.raw.commandIndexes.length;+ }+ return 1;+};+const colSpan = (entry: FlattenLogEntry) => {+ if (+ entry.type === TaskRunLogEntry_Type.COMMAND_EXECUTE &&+ entry.commandExecute+ ) {+ const { commandExecute } = entry;+ if (commandExecute.raw.commandIndexes.length > 1) {+ return 1;+ }+ }+ return 2;+};++const columns = computed(() => {+ const splitBatchAndSerialCol = flattenLogEntries.value.some(+ (entry) => colSpan(entry) === 1+ );+ const columns: (DataTableColumn<FlattenLogEntry> & { hide?: boolean })[] = [+ {+ key: "batch",+ title: () => t("issue.task-run.task-run-log.batch"),+ width: 50,+ className: "whitespace-nowrap",+ titleColSpan: splitBatchAndSerialCol ? 2 : 1,+ rowSpan,+ colSpan: (entry) => {+ if (splitBatchAndSerialCol) return colSpan(entry);+ return 1;+ },+ render: (entry) => {+ return String(entry.batch + 1);+ },+ },+ {+ key: "serial",+ title: () => "serial",+ width: 50,+ className: "whitespace-nowrap",+ hide: !splitBatchAndSerialCol,+ render: (entry) => {+ return String(entry.serial + 1);+ },+ },+ {+ key: "type",+ title: () => t("common.type"),+ width: 120,+ className: "whitespace-nowrap",+ render: (entry) => {+ return <span class="text-sm">{entry.type}</span>;+ },+ },+ {+ key: "statement",+ title: () => t("common.statement"),+ render: (entry) => {+ return <StatementCell entry={entry} sheet={sheet.value} />;+ },+ },+ {+ key: "affected-rows",+ title: () => t("issue.task-run.task-run-log.affected-rows"),+ width: 120,+ render: (entry) => {+ return <AffectedRowsCell entry={entry} sheet={sheet.value} />;+ },+ },+ {+ key: "duration",+ title: () => t("common.duration"),+ width: 120,+ rowSpan,+ render: (entry) => {+ return <DurationCell entry={entry} />;+ },+ },+ ];+ return columns.filter((column) => !column.hide);+});+</script>diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/common.ts b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/common.tsnew file mode 100644index 0000000000..a19ac2d62b--- /dev/null+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/common.ts@@ -0,0 +1,19 @@+import type {+ TaskRunLogEntry_CommandExecute,+ TaskRunLogEntry_SchemaDump,+ TaskRunLogEntry_Type,+} from "@/types/proto/v1/rollout_service";++export type FlattenLogEntry = {+ batch: number;+ serial: number;+ type: TaskRunLogEntry_Type;+ startTime?: Date;+ endTime?: Date;+ schemaDump?: TaskRunLogEntry_SchemaDump;+ commandExecute?: {+ raw: TaskRunLogEntry_CommandExecute;+ commandIndex: number;+ affectedRows?: number;+ };+};diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/index.ts b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/index.tsnew file mode 100644index 0000000000..e4452795d8--- /dev/null+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunLogTable/index.ts@@ -0,0 +1,3 @@+import TaskRunLogTable from "./TaskRunLogTable.vue";++export default TaskRunLogTable;diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunTable.vue b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunTable.vueindex cd8797a347..9c0a653428 100644--- a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunTable.vue+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunTable.vue@@ -5,6 +5,7 @@:row-clickable="false"row-key="uid"class="border"+ v-bind="$attrs"><template #item="{ item: taskRun }: TaskRunGridRow"><div class="bb-grid-cell block">@@ -22,26 +23,51 @@<div class="bb-grid-cell">{{ humanizeDurationV1(executionDurationOfTaskRun(taskRun)) }}</div>+ <div class="bb-grid-cell">+ <NButton+ v-if="shouldShowDetailButton(taskRun)"+ size="tiny"+ @click="showDetail(taskRun)"+ >+ {{ $t("common.detail") }}+ </NButton>+ </div></template></BBGrid>++ <Drawer v-model:show="taskRunDetailContext.show">+ <DrawerContent+ :title="$t('common.detail')"+ style="width: calc(100vw - 8rem)"+ >+ <TaskRunLogTable+ v-if="taskRunDetailContext.taskRun"+ :key="taskRunDetailContext.taskRun.name"+ :task-run="taskRunDetailContext.taskRun"+ />+ </DrawerContent>+ </Drawer></template><script lang="ts" setup>-import { computed } from "vue";+import { NButton } from "naive-ui";+import { computed, ref } from "vue";import { useI18n } from "vue-i18n";import type { BBGridColumn, BBGridRow } from "@/bbkit";import { BBGrid } from "@/bbkit";import HumanizeDate from "@/components/misc/HumanizeDate.vue";+import { Drawer, DrawerContent } from "@/components/v2";import { Duration } from "@/types/proto/google/protobuf/duration";-import type { Task, TaskRun } from "@/types/proto/v1/rollout_service";+import type { TaskRun } from "@/types/proto/v1/rollout_service";import { TaskRun_Status } from "@/types/proto/v1/rollout_service";import TaskRunComment from "./TaskRunComment.vue";+import TaskRunLogTable from "./TaskRunLogTable";import TaskRunStatusIcon from "./TaskRunStatusIcon.vue";-export type MergedTaskRunItem = {- task: Task;- taskRun: TaskRun;-};+defineOptions({+ inheritAttrs: false,+});+export type TaskRunGridRow = BBGridRow<TaskRun>;defineProps<{@@ -49,6 +75,12 @@ defineProps<{}>();const { t } = useI18n();+const taskRunDetailContext = ref<{+ show: boolean;+ taskRun?: TaskRun;+}>({+ show: false,+});const columnList = computed((): BBGridColumn[] => {return [@@ -72,6 +104,10 @@ const columnList = computed((): BBGridColumn[] => {title: t("task.execution-time"),width: "auto",},+ {+ title: "",+ width: "auto",+ },];});@@ -101,4 +137,20 @@ const executionDurationOfTaskRun = (taskRun: TaskRun): Duration | undefined => {nanos: (elapsedMS % 1000) * 1e6,});};++const shouldShowDetailButton = (taskRun: TaskRun) => {+ return [+ TaskRun_Status.RUNNING,+ TaskRun_Status.DONE,+ TaskRun_Status.FAILED,+ TaskRun_Status.CANCELED,+ ].includes(taskRun.status);+};++const showDetail = (taskRun: TaskRun) => {+ taskRunDetailContext.value = {+ show: true,+ taskRun,+ };+};</script>diff --git a/frontend/src/components/misc/TextOverflowPopover.vue b/frontend/src/components/misc/TextOverflowPopover.vueindex f27776c0ef..0f4bffd9f7 100644--- a/frontend/src/components/misc/TextOverflowPopover.vue+++ b/frontend/src/components/misc/TextOverflowPopover.vue@@ -1,22 +1,26 @@<template><NPopover- :disabled="content.length <= maxLength"+ :disabled="popoverDisabled":placement="placement"style="max-height: 300px"width="trigger"scrollable>- <highlight-code-block- v-if="codeMode"- :code="displayPopoverContent"- class="whitespace-pre-wrap"- />+ <div v-if="codeMode" :class="codeClass">+ <slot name="popover-header" />+ <highlight-code-block+ :code="displayPopoverContent"+ class="whitespace-pre-wrap"+ />+ </div><div v-else class="whitespace-pre-wrap">{{ displayPopoverContent }}</div><template #trigger>- <span :class="contentClass" v-bind="$attrs">{{ displayContent }}</span>+ <slot name="default" :display-content="displayContent">+ <span :class="contentClass" v-bind="$attrs">{{ displayContent }}</span>+ </slot></template></NPopover></template>@@ -49,6 +53,10 @@ const props = defineProps({type: [String, Object, Array] as PropType<VueClass>,default: undefined,},+ codeClass: {+ type: [String, Object, Array] as PropType<VueClass>,+ default: undefined,+ },codeMode: {type: Boolean,default: true,@@ -78,4 +86,8 @@ const displayPopoverContent = computed(() => {? content: content.substring(0, maxPopoverContentLength) + "...";});++const popoverDisabled = computed(() => {+ return displayContent.value === props.content;+});</script>diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 1d0412d5fb..e0aaa76728 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1196,6 +1196,12 @@},"update-rollout-time": {"self": "Update rollout time"+ },+ "task-run": {+ "task-run-log": {+ "batch": "Batch",+ "affected-rows": "Affected rows"+ }}},"alter-schema": {diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 3f0c216111..eb1f2dbff9 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1196,6 +1196,12 @@},"update-rollout-time": {"self": "Hora de implementación de la actualización"+ },+ "task-run": {+ "task-run-log": {+ "batch": "Lote",+ "affected-rows": "Filas afectadas"+ }}},"alter-schema": {@@ -3487,4 +3493,4 @@"drop-partition-with-subpartitions-confirm": "También eliminará todas sus subparticiones."}}-}\ No newline at end of file+}diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex f66134f2fc..7ccfaec4f9 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -1196,6 +1196,12 @@},"update-rollout-time": {"self": "更新のロールアウト時間"+ },+ "task-run": {+ "task-run-log": {+ "batch": "バッチ",+ "affected-rows": "影響を受ける行"+ }}},"alter-schema": {@@ -3487,4 +3493,4 @@"drop-partition-with-subpartitions-confirm": "すべてのサブパーティションが同時に削除されます。"}}-}\ No newline at end of file+}diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex 8a7364f18a..cacd0d4624 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -1196,6 +1196,12 @@},"update-rollout-time": {"self": "Cập nhật thời gian triển khai"+ },+ "task-run": {+ "task-run-log": {+ "batch": "Lô hàng",+ "affected-rows": "Hàng bị ảnh hưởng"+ }}},"alter-schema": {@@ -3487,4 +3493,4 @@"drop-partition-with-subpartitions-confirm": "Cũng sẽ bỏ tất cả các phân vùng của nó."}}-}\ No newline at end of file+}diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 656ae49d5e..16cf053b17 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1196,6 +1196,12 @@},"update-rollout-time": {"self": "修改指定发布时间"+ },+ "task-run": {+ "task-run-log": {+ "batch": "批次",+ "affected-rows": "影响行数"+ }}},"alter-schema": {diff --git a/frontend/src/utils/v1/sheet.ts b/frontend/src/utils/v1/sheet.tsindex 6d6123ce14..b29ba5c5d0 100644--- a/frontend/src/utils/v1/sheet.ts+++ b/frontend/src/utils/v1/sheet.ts@@ -23,3 +23,12 @@ export const setSheetStatement = (export const getSheetStatement = (sheet: Sheet | Worksheet) => {return new TextDecoder().decode(sheet.content);};++export const extractSheetCommandByIndex = (sheet: Sheet, index: number) => {+ const commands = sheet.payload?.commands;+ if (!commands) return undefined;+ const command = commands[index];+ if (!command) return undefined;+ const subarray = sheet.content.subarray(command.start, command.end);+ return new TextDecoder().decode(subarray);+};