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: implement task run session detail (#12877)
boojackd898f9ea61c7
diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunDetail.vue b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunDetail.vuenew file mode 100644index 0000000000..3f9a476e3c--- /dev/null+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunDetail.vue@@ -0,0 +1,69 @@+<template>+ <NTabs v-model:value="state.currentTab" type="line">+ <NTabPane name="LOG" :tab="$t('issue.task-run.logs')">+ <TaskRunLogTable :task-run="taskRun" />+ </NTabPane>+ <NTabPane+ v-if="showTaskRunSessionTab"+ name="SESSION"+ :tab="$t('issue.task-run.session')"+ >+ <TaskRunSession :key="componentId" :task-run="taskRun" />+ </NTabPane>++ <template v-if="showRefreshButton" #suffix>+ <NButton text @click="componentId = uniqueId()">+ <template #icon>+ <RefreshCcwIcon class="w-4 h-auto" />+ </template>+ {{ $t("common.refresh") }}+ </NButton>+ </template>+ </NTabs>+</template>++<script lang="ts" setup>+import { uniqueId } from "lodash-es";+import { RefreshCcwIcon } from "lucide-vue-next";+import { NButton, NTabs, NTabPane } from "naive-ui";+import { computed, reactive, ref } from "vue";+import { Engine } from "@/types/proto/v1/common";+import { TaskRun_Status, type TaskRun } from "@/types/proto/v1/rollout_service";+import { databaseForTask, useIssueContext } from "../../logic";+import TaskRunLogTable from "./TaskRunLogTable";+import TaskRunSession from "./TaskRunSession";++const TASK_RUN_SESSION_SUPPORTED_ENGINES = [Engine.POSTGRES];++interface LocalState {+ currentTab: "LOG" | "SESSION";+}++const props = defineProps<{+ taskRun: TaskRun;+}>();++const { issue, selectedTask } = useIssueContext();++const state = reactive<LocalState>({+ currentTab: "LOG",+});+// Mainly using to force re-render of TaskRunSession component which will re-fetch the session data.+const componentId = ref<string>(uniqueId());++const showTaskRunSessionTab = computed(() =>+ TASK_RUN_SESSION_SUPPORTED_ENGINES.includes(+ database.value.instanceResource.engine+ )+);++const showRefreshButton = computed(+ () =>+ state.currentTab === "SESSION" &&+ props.taskRun.status === TaskRun_Status.RUNNING+);++const database = computed(() =>+ databaseForTask(issue.value, selectedTask.value)+);+</script>diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/Cells/StatementCell.vue b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/Cells/StatementCell.vuenew file mode 100644index 0000000000..f132f47885--- /dev/null+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/Cells/StatementCell.vue@@ -0,0 +1,67 @@+<template>+ <div class="text-sm group">+ <TextOverflowPopover+ v-if="query"+ :content="query.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 { useI18n } from "vue-i18n";+import TextOverflowPopover from "@/components/misc/TextOverflowPopover.vue";+import { pushNotification } from "@/store";+import { toClipboard } from "@/utils";++const props = defineProps<{+ query: string;+}>();++const { t } = useI18n();++const copyStatement = () => {+ toClipboard(props.query.trim()).then(() => {+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("common.copied"),+ });+ });+};+</script>diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/Cells/TimeCell.vue b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/Cells/TimeCell.vuenew file mode 100644index 0000000000..a254d83ce5--- /dev/null+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/Cells/TimeCell.vue@@ -0,0 +1,18 @@+<template>+ <div class="text-sm">+ <HumanizeDate+ v-if="date"+ :date="date"+ format="YYYY-MM-DD HH:mm:ss.SSS UTCZZ"+ />+ <div v-else class="text-control-placeholder">-</div>+ </div>+</template>++<script setup lang="ts">+import HumanizeDate from "@/components/misc/HumanizeDate.vue";++defineProps<{+ date: Date | undefined;+}>();+</script>diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/Cells/index.ts b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/Cells/index.tsnew file mode 100644index 0000000000..60f6710307--- /dev/null+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/Cells/index.ts@@ -0,0 +1,4 @@+import StatementCell from "./StatementCell.vue";+import TimeCell from "./TimeCell.vue";++export { StatementCell, TimeCell };diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/PostgresSessionTable.vue b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/PostgresSessionTable.vuenew file mode 100644index 0000000000..7af71eeeeb--- /dev/null+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/PostgresSessionTable.vue@@ -0,0 +1,199 @@+<template>+ <div class="w-full space-y-2">+ <NDataTable+ :single-column="true"+ :columns="columns"+ :data="[session]"+ :row-key="rowKey"+ size="small"+ />++ <div class="pt-2 flex flex-row justify-start items-center">+ <AlignHorizontalJustifyEndIcon class="w-4 h-auto mr-2 opacity-80" />+ <span class="textlabel">+ {{ $t("issue.task-run.task-run-session.blocking-sessions.self") }}+ </span>+ <span class="textinfolabel ml-1">+ ({{+ $t("issue.task-run.task-run-session.blocking-sessions.description")+ }})+ </span>+ </div>+ <NDataTable+ size="small"+ :columns="columns"+ :data="blockingSessions"+ :row-key="rowKey"+ />++ <template v-if="blockedSessions.length > 0">+ <div class="pt-2 flex flex-row justify-start items-center">+ <AlignHorizontalJustifyStartIcon class="w-4 h-auto mr-2 opacity-80" />+ <p class="textlabel">+ {{ $t("issue.task-run.task-run-session.blocked-sessions.self") }}+ </p>+ <p class="textinfolabel ml-1">+ {{+ $t("issue.task-run.task-run-session.blocked-sessions.description")+ }}+ </p>+ </div>+ <NDataTable+ size="small"+ :columns="columns"+ :data="blockedSessions"+ :row-key="rowKey"+ />+ </template>+ </div>+</template>++<script setup lang="tsx">+import {+ AlignHorizontalJustifyEndIcon,+ AlignHorizontalJustifyStartIcon,+} from "lucide-vue-next";+import { NDataTable, type DataTableColumn } from "naive-ui";+import { computed } from "vue";+import {+ TaskRunSession_Postgres,+ TaskRunSession_Postgres_Session,+} from "@/types/proto/v1/rollout_service";+import { StatementCell, TimeCell } from "./Cells";++const props = defineProps<{+ taskRunSession: TaskRunSession_Postgres;+}>();++const session = computed(() => props.taskRunSession.session!);+const blockingSessions = computed(() => props.taskRunSession.blockingSessions);+const blockedSessions = computed(() => props.taskRunSession.blockedSessions);++const rowKey = (session: TaskRunSession_Postgres_Session) => {+ return session.pid;+};++const columns = computed(() => {+ const columns: (DataTableColumn<TaskRunSession_Postgres_Session> & {+ hide?: boolean;+ })[] = [+ {+ key: "pid",+ title: () => "pid",+ width: 50,+ className: "whitespace-nowrap",+ render: (session) => {+ return session.pid;+ },+ },+ {+ key: "blocked_by_pids",+ title: () => "blocked_by_pids",+ width: 120,+ className: "whitespace-nowrap",+ render: (session) => {+ return session.blockedByPids.join(", ");+ },+ },+ {+ key: "query",+ resizable: true,+ title: () => "query",+ width: "60%",+ minWidth: 256,+ render: (session) => {+ return <StatementCell query={session.query} />;+ },+ },+ {+ key: "state",+ title: () => "state",+ width: 120,+ render: (session) => {+ return session.state;+ },+ },+ {+ key: "wait_event_type",+ title: () => "wait_event_type",+ width: 144,+ render: (session) => {+ return session.waitEventType;+ },+ },+ {+ key: "wait_event",+ title: () => "wait_event",+ width: 120,+ render: (session) => {+ return session.waitEvent;+ },+ },+ {+ key: "datname",+ title: () => "datname",+ width: 120,+ render: (session) => {+ return session.datname;+ },+ },+ {+ key: "usename",+ title: () => "usename",+ width: 120,+ render: (session) => {+ return session.usename;+ },+ },+ {+ key: "application_name",+ title: () => "application_name",+ width: 144,+ render: (session) => {+ return session.applicationName;+ },+ },+ {+ key: "client_addr",+ title: () => "client_addr",+ width: 120,+ render: (session) => {+ return session.clientAddr;+ },+ },+ {+ key: "client_port",+ width: 120,+ title: () => "client_port",+ render: (session) => {+ return session.clientPort;+ },+ },+ {+ key: "backend_start",+ title: () => "backend_start",+ width: 120,+ render: (session) => {+ return <TimeCell date={session.backendStart} />;+ },+ },+ {+ key: "xact_start",+ title: () => "xact_start",+ width: 120,+ render: (session) => {+ return <TimeCell date={session.xactStart} />;+ },+ },+ {+ key: "query_start",+ title: () => "query_start",+ width: 120,+ render: (session) => {+ return <TimeCell date={session.queryStart} />;+ },+ },+ ];+ return columns.filter((column) => !column.hide);+});+</script>diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/TaskRunSession.vue b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/TaskRunSession.vuenew file mode 100644index 0000000000..d89cc74df8--- /dev/null+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/TaskRunSession.vue@@ -0,0 +1,52 @@+<template>+ <template v-if="showSessionTables">+ <PostgresSessionTable+ v-if="postgresSession"+ :task-run-session="postgresSession"+ />++ <div v-if="isLoading" class="flex justify-center items-center py-10">+ <BBSpin />+ </div>+ </template>+ <div v-else class="text-control-placeholder">+ {{ $t("issue.task-run.task-run-session.no-session-found") }}+ </div>+</template>++<script setup lang="tsx">+import { computedAsync } from "@vueuse/core";+import { computed, ref } from "vue";+import { rolloutServiceClient } from "@/grpcweb";+import { TaskRun_Status, type TaskRun } from "@/types/proto/v1/rollout_service";+import PostgresSessionTable from "./PostgresSessionTable.vue";++const props = defineProps<{+ taskRun: TaskRun;+}>();++const isLoading = ref(false);++const taskRunSession = computedAsync(+ async () => {+ try {+ const session = await rolloutServiceClient.getTaskRunSession({+ parent: props.taskRun.name,+ });+ return session;+ } catch (error) {+ return undefined;+ }+ },+ undefined,+ {+ evaluating: isLoading,+ }+);++const showSessionTables = computed(+ () => props.taskRun.status === TaskRun_Status.RUNNING+);++const postgresSession = computed(() => taskRunSession.value?.postgres);+</script>diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/index.ts b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/index.tsnew file mode 100644index 0000000000..0a3abcbab1--- /dev/null+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunSession/index.ts@@ -0,0 +1,3 @@+import TaskRunSession from "./TaskRunSession.vue";++export default TaskRunSession;diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunTable.vue b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunTable.vueindex 73c587e6c6..d9313538a9 100644--- a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunTable.vue+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunTable.vue@@ -38,9 +38,9 @@<Drawer v-model:show="taskRunDetailContext.show"><DrawerContent:title="$t('common.detail')"- style="width: calc(100vw - 8rem)"+ style="width: calc(100vw - 14rem)">- <TaskRunLogTable+ <TaskRunDetailv-if="taskRunDetailContext.taskRun":key="taskRunDetailContext.taskRun.name":task-run="taskRunDetailContext.taskRun"@@ -61,7 +61,7 @@ import { Duration } from "@/types/proto/google/protobuf/duration";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 TaskRunDetail from "./TaskRunDetail.vue";import TaskRunStatusIcon from "./TaskRunStatusIcon.vue";defineOptions({@@ -119,9 +119,7 @@ const executionDurationOfTaskRun = (taskRun: TaskRun): Duration | undefined => {if (startTime.getTime() === 0) {return undefined;}- if (- taskRun.status === TaskRun_Status.RUNNING- ) {+ if (taskRun.status === TaskRun_Status.RUNNING) {const elapsedMS = Date.now() - startTime.getTime();return Duration.fromPartial({seconds: Math.floor(elapsedMS / 1000),diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 330f234ded..de9d224216 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -277,7 +277,8 @@"resource": "Resource","closed": "Closed","options": "Options",- "reset": "Reset"+ "reset": "Reset",+ "refresh": "Refresh"},"error-page": {"go-back-home": "Go back home"@@ -1240,6 +1241,8 @@"self": "Update rollout time"},"task-run": {+ "logs": "Logs",+ "session": "Session","task-run-log": {"batch": "Batch","affected-rows": "Affected rows",@@ -1255,6 +1258,17 @@"waiting": "Ready to be executed","running": "Being executed"}+ },+ "task-run-session": {+ "blocking-sessions": {+ "self": "Blocking sessions",+ "description": "The sessions that are blocking the current session"+ },+ "blocked-sessions": {+ "self": "Blocked sessions",+ "description": "The sessions that are blocked by the current session"+ },+ "no-session-found": "No session found."}},"sql-review": {diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex d7ad76cca7..60df7a01f5 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -277,7 +277,8 @@"resource": "Recurso","closed": "Cerrado","options": "Opciones",- "reset": "Reiniciar"+ "reset": "Reiniciar",+ "refresh": "Actualizar"},"error-page": {"go-back-home": "Volver al inicio"@@ -1240,6 +1241,8 @@"self": "Hora de implementación de la actualización"},"task-run": {+ "logs": "Registros",+ "session": "Sesión","task-run-log": {"batch": "Lote","affected-rows": "Filas afectadas",@@ -1255,6 +1258,17 @@"waiting": "Listo para ser ejecutado","running": "Ser ejecutado"}+ },+ "task-run-session": {+ "blocking-sessions": {+ "self": "Sesiones de bloqueo",+ "description": "Las sesiones que están bloqueando la sesión actual."+ },+ "blocked-sessions": {+ "self": "Sesiones bloqueadas",+ "description": "Las sesiones que están bloqueadas por la sesión actual."+ },+ "no-session-found": "No se encontró ninguna sesión."}},"sql-review": {diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex a3c266b32a..28dffa3f32 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -277,7 +277,8 @@"resource": "リソース","closed": "閉まっている","options": "オプション",- "reset": "リセット"+ "reset": "リセット",+ "refresh": "リフレッシュ"},"error-page": {"go-back-home": "ホームページに戻る"@@ -1240,6 +1241,8 @@"self": "更新のロールアウト時間"},"task-run": {+ "logs": "ログ",+ "session": "セッション","task-run-log": {"batch": "バッチ","affected-rows": "影響を受ける行",@@ -1255,6 +1258,17 @@"waiting": "実行の準備完了","running": "処刑される"}+ },+ "task-run-session": {+ "blocking-sessions": {+ "self": "セッションのブロック",+ "description": "現在のセッションをブロックしているセッション"+ },+ "blocked-sessions": {+ "self": "ブロックされたセッション",+ "description": "現在のセッションによってブロックされているセッション"+ },+ "no-session-found": "セッションが見つかりません。"}},"sql-review": {diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 525bafdf31..67c05a6ec1 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -277,7 +277,8 @@"resource": "资源","closed": "已关闭","options": "配置项",- "reset": "重置"+ "reset": "重置",+ "refresh": "刷新"},"error-page": {"go-back-home": "回到主页"@@ -1240,6 +1241,8 @@"self": "修改指定发布时间"},"task-run": {+ "logs": "日志",+ "session": "会话","task-run-log": {"batch": "批次","affected-rows": "影响行数",@@ -1255,6 +1258,17 @@"waiting": "准备就绪,等待执行","running": "开始执行"}+ },+ "task-run-session": {+ "blocking-sessions": {+ "self": "阻塞会话",+ "description": "当前会话被以下会话阻塞"+ },+ "blocked-sessions": {+ "self": "被阻塞会话",+ "description": "当前会话阻塞了以下会话"+ },+ "no-session-found": "未找到会话。"}},"sql-review": {