Skip to content

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

feat(frontend): ui for debug logs (#2473)

ZhengX56d735ef221f
diff --git a/frontend/package.json b/frontend/package.json
index 4f7da92059..98b8ad97a5 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -22,6 +22,7 @@
"canvas-confetti": "^1.5.1",
"dayjs": "^1.10.7",
"dompurify": "^2.3.9",
+ "downloadjs": "^1.4.7",
"escape-string-regexp": "^5.0.0",
"highlight.js": "^11.0.1",
"inter-ui": "^3.15.0",
@@ -56,6 +57,7 @@
"@tailwindcss/typography": "^0.5.2",
"@types/canvas-confetti": "^1.4.3",
"@types/dompurify": "^2.3.3",
+ "@types/downloadjs": "^1.4.3",
"@types/js-yaml": "^4.0.5",
"@types/lodash-es": "^4.17.4",
"@types/node": "^16.11.9",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index ac5c32883f..eea7ec54b4 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -13,6 +13,7 @@ specifiers:
'@tailwindcss/typography': ^0.5.2
'@types/canvas-confetti': ^1.4.3
'@types/dompurify': ^2.3.3
+ '@types/downloadjs': ^1.4.3
'@types/js-yaml': ^4.0.5
'@types/lodash-es': ^4.17.4
'@types/node': ^16.11.9
@@ -36,6 +37,7 @@ specifiers:
canvas-confetti: ^1.5.1
dayjs: ^1.10.7
dompurify: ^2.3.9
+ downloadjs: ^1.4.7
escape-string-regexp: ^5.0.0
eslint: ^8.3.0
eslint-config-prettier: ^8.3.0
@@ -85,6 +87,7 @@ dependencies:
canvas-confetti: 1.5.1
dayjs: 1.10.8
dompurify: 2.3.9
+ downloadjs: 1.4.7
escape-string-regexp: 5.0.0
highlight.js: 11.5.0
inter-ui: 3.19.3
@@ -119,6 +122,7 @@ devDependencies:
'@tailwindcss/typography': [email protected]
'@types/canvas-confetti': 1.4.3
'@types/dompurify': 2.3.3
+ '@types/downloadjs': 1.4.3
'@types/js-yaml': 4.0.5
'@types/lodash-es': 4.17.6
'@types/node': 16.11.26
@@ -369,8 +373,8 @@ packages:
vue-i18n:
optional: true
dependencies:
- '@intlify/message-compiler': 9.3.0-beta.1
- '@intlify/shared': 9.3.0-beta.1
+ '@intlify/message-compiler': 9.3.0-beta.3
+ '@intlify/shared': 9.3.0-beta.3
jsonc-eslint-parser: 1.4.1
source-map: 0.6.1
@@ -399,11 +403,11 @@ packages:
'@intlify/shared': 9.2.0-beta.32
source-map: 0.6.1
- /@intlify/message-compiler/9.3.0-beta.1:
- resolution: {integrity: sha512-XHjwJB7qJciYA3T19ehBFpcmC1z+R4sMS43fEp30CLOOFLsrB0xuk0V2XeOFsHovaQ2LsK5x0qk+5+Dy6Hs7fw==}
+ /@intlify/message-compiler/9.3.0-beta.3:
+ resolution: {integrity: sha512-j8OwToBQgs01RBMX4GCDNQfcnmw3AiDG3moKIONTrfXcf+1yt/rWznLTYH/DXbKcFMAFijFpCzMYjUmH1jVFYA==}
engines: {node: '>= 14'}
dependencies:
- '@intlify/shared': 9.3.0-beta.1
+ '@intlify/shared': 9.3.0-beta.3
source-map: 0.6.1
dev: true
@@ -411,8 +415,8 @@ packages:
resolution: {integrity: sha512-lVaHnKFNg16eWlfDLzDFLapurrf0WK7xLWEkz8DMYNIXJshRQOZCkH7sQaqtONPoOT0LqjyPo1+sV0Wq85/HRQ==}
engines: {node: '>= 12'}
- /@intlify/shared/9.3.0-beta.1:
- resolution: {integrity: sha512-clf9EF4lY0sANjHlEndwfsR2hvYuq0TElq+gO/1xqH3FMGJwv+6lxJPOtoF4r2IE5RV3qX6YyZejZgdfbq2Yfg==}
+ /@intlify/shared/9.3.0-beta.3:
+ resolution: {integrity: sha512-Z/0TU4GhFKRxKh+0RbwJExik9zz57gXYgxSYaPn7YQdkQ/pabSioCY/SXnYxQHL6HzULF5tmqarFm6glbGqKhw==}
engines: {node: '>= 14'}
dev: true
@@ -430,7 +434,7 @@ packages:
optional: true
dependencies:
'@intlify/bundle-utils': [email protected]
- '@intlify/shared': 9.3.0-beta.1
+ '@intlify/shared': 9.3.0-beta.3
'@rollup/pluginutils': 4.2.0
debug: 4.3.3
fast-glob: 3.2.11
@@ -746,6 +750,10 @@ packages:
'@types/trusted-types': 2.0.2
dev: true
+ /@types/downloadjs/1.4.3:
+ resolution: {integrity: sha512-MjJepFle/tLtT2/jmDNth6ZnwWzEhm40L+olE5HKR70ISUCfgT55eqreeHldAzFLY2HDUGsn8zgyto8KygN0CA==}
+ dev: true
+
/@types/estree/0.0.39:
resolution: {integrity: sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==}
dev: true
@@ -1895,6 +1903,10 @@ packages:
resolution: {integrity: sha512-3zOnuTwup4lPV/GfGS6UzG4ub9nhSYagR/5tB3AvDEwqyy5dtyCM2dVjwGDCnrPerXifBKTYh/UWCGKK7ydhhw==}
dev: false
+ /downloadjs/1.4.7:
+ resolution: {integrity: sha512-LN1gO7+u9xjU5oEScGFKvXhYf7Y/empUIIEAGBs1LzUq/rg5duiDrkuH5A2lQGd5jfMOb9X9usDa2oVXwJ0U/Q==}
+ dev: false
+
/electron-to-chromium/1.4.89:
resolution: {integrity: sha512-z1Axg0Fu54fse8wN4fd+GAINdU5mJmLtcl6bqIcYyzNVGONcfHAeeJi88KYMQVKalhXlYuVPzKkFIU5VD0raUw==}
dev: true
diff --git a/frontend/src/components/DebugLog/DebugLogEmptyView.vue b/frontend/src/components/DebugLog/DebugLogEmptyView.vue
new file mode 100644
index 0000000000..d525c0d77f
--- /dev/null
+++ b/frontend/src/components/DebugLog/DebugLogEmptyView.vue
@@ -0,0 +1,14 @@
+<template>
+ <div class="bg-white rounded-lg py-6">
+ <div
+ class="border-4 border-dashed border-gray-200 rounded-lg h-96 flex justify-center items-center"
+ >
+ <div class="text-center flex flex-col justify-center items-center">
+ <img src="../../assets/illustration/no-data.webp" class="w-52" />
+ <h3 class="mt-2 font-medium text-gray-900">
+ {{ $t("debug-log.no-logs") }}
+ </h3>
+ </div>
+ </div>
+ </div>
+</template>
diff --git a/frontend/src/components/DebugLog/DebugLogTable.vue b/frontend/src/components/DebugLog/DebugLogTable.vue
new file mode 100644
index 0000000000..be0d507b03
--- /dev/null
+++ b/frontend/src/components/DebugLog/DebugLogTable.vue
@@ -0,0 +1,92 @@
+<template>
+ <BBTable
+ class="mt-2"
+ :column-list="columnList"
+ :data-source="debugLogList"
+ :show-header="true"
+ :row-clickable="false"
+ >
+ <template #body="{ rowData: debugLog }">
+ <BBTableCell :left-padding="4" class="table-cell w-56">
+ <div>
+ {{ dayjs.unix(debugLog.RecordTs).format("YYYY-MM-DD HH:mm:ss Z") }}
+ </div>
+ </BBTableCell>
+ <BBTableCell class="table-cell w-20">
+ <HTTPMethodTag :method="debugLog.Method" />
+ </BBTableCell>
+ <BBTableCell class="table-cell w-28">
+ <div>{{ debugLog.RequestPath }}</div>
+ </BBTableCell>
+ <BBTableCell class="table-cell w-20">
+ <span v-if="!debugLog.Role" class="italic text-gray-500">{{
+ $t("debug-log.table.empty")
+ }}</span>
+ <div v-else>{{ debugLog.Role }}</div>
+ </BBTableCell>
+ <BBTableCell class="table-cell pt-3">
+ <EllipsisText :line-clamp="2">{{ debugLog.Error }}</EllipsisText>
+ </BBTableCell>
+ <BBTableCell class="table-cell w-28">
+ <div class="tooltip-wrapper">
+ <div class="tooltip whitespace-nowrap">
+ {{ $t("debug-log.table.operation.view-details") }}
+ </div>
+ <button
+ type="button"
+ class="group btn-normal items-center !px-3 !text-accent hover:!bg-gray-50"
+ @click.stop="
+ () => {
+ $emit('view-detail', debugLog);
+ }
+ "
+ >
+ <heroicons-outline:document-magnifying-glass class="h-5 w-5" />
+ </button>
+ </div>
+ </BBTableCell>
+ </template>
+ </BBTable>
+</template>
+
+<script lang="ts" setup>
+import { computed, PropType } from "vue";
+import { useI18n } from "vue-i18n";
+import { DebugLog } from "@/types/debug";
+import HTTPMethodTag from "./HTTPMethodTag.vue";
+import EllipsisText from "../EllipsisText.vue";
+
+defineProps({
+ debugLogList: {
+ type: Array as PropType<DebugLog[]>,
+ required: true,
+ },
+});
+
+defineEmits<{
+ (event: "view-detail", list: DebugLog, e: MouseEvent): void;
+}>();
+
+const { t } = useI18n();
+
+const columnList = computed(() => [
+ {
+ title: t("debug-log.table.record-ts"),
+ },
+ {
+ title: t("debug-log.table.method"),
+ },
+ {
+ title: t("debug-log.table.request-path"),
+ },
+ {
+ title: t("debug-log.table.role"),
+ },
+ {
+ title: t("debug-log.table.error"),
+ },
+ {
+ title: t("debug-log.table.operation.operation"),
+ },
+]);
+</script>
diff --git a/frontend/src/components/DebugLog/HTTPMethodTag.vue b/frontend/src/components/DebugLog/HTTPMethodTag.vue
new file mode 100644
index 0000000000..084e4d69bc
--- /dev/null
+++ b/frontend/src/components/DebugLog/HTTPMethodTag.vue
@@ -0,0 +1,43 @@
+<template>
+ <div :class="`tag ${method}`">{{ method }}</div>
+</template>
+
+<script lang="ts" setup>
+defineProps({
+ method: {
+ required: true,
+ type: String,
+ },
+});
+</script>
+
+<style scoped>
+.tag {
+ @apply h-6 text-white text-xs px-2 rounded whitespace-nowrap inline-flex items-center;
+}
+
+.GET {
+ border: 1px solid #0f6ab4;
+ color: #0f6ab4;
+}
+.POST {
+ border: 1px solid #10a54a;
+ color: #10a54a;
+}
+.PUT {
+ border: 1px solid #c5862b;
+ color: #c5862b;
+}
+.DELETE {
+ border: 1px solid #a41e22;
+ color: #a41e22;
+}
+.PATCH {
+ border: 1px solid #d38042;
+ color: #d38042;
+}
+.HEAD {
+ border: 1px solid #ffd20f;
+ color: #ffd20f;
+}
+</style>
diff --git a/frontend/src/components/EllipsisText.vue b/frontend/src/components/EllipsisText.vue
index cbf650f796..63979a1945 100644
--- a/frontend/src/components/EllipsisText.vue
+++ b/frontend/src/components/EllipsisText.vue
@@ -1,17 +1,35 @@
<template>
- <span class="tooltip-wrapper w-full">
- <span v-if="hasTextOverflow" class="tooltip whitespace-nowrap">
- <slot></slot>
- </span>
- <div ref="textRef" class="truncate w-full"><slot></slot></div>
- </span>
+ <NEllipsis
+ :line-clamp="lineClamp"
+ :tooltip="{
+ showArrow: false,
+ raw: true,
+ contentStyle: tooltipStyle,
+ }"
+ >
+ <slot></slot>
+ </NEllipsis>
</template>
<script lang="ts" setup>
-import { ref, computed } from "vue";
+import { NEllipsis } from "naive-ui";
-const textRef = ref<HTMLElement | null>(null);
-const hasTextOverflow = computed(() => {
- return textRef.value && textRef.value.offsetWidth < textRef.value.scrollWidth;
+defineProps({
+ lineClamp: {
+ type: Number,
+ default: 1,
+ },
});
+
+const tooltipStyle = `
+ border-radius: 0.25rem;
+ background-color: rgb(0 0 0 / var(--tw-bg-opacity));
+ --tw-bg-opacity: 0.75;
+ padding-left: 0.5rem;
+ padding-right: 0.5rem;
+ padding-top: 0.25rem;
+ padding-bottom: 0.25rem;
+ --tw-text-opacity: 1;
+ color: rgb(255 255 255 / var(--tw-text-opacity));
+`;
</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index e409d546d7..f9e98d4387 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -319,7 +319,8 @@
"members": "Members",
"version-control": "Version Control",
"subscription": "Subscription",
- "labels": "Labels"
+ "labels": "Labels",
+ "debug-log": "Debug Log"
},
"profile": {
"email": "Email",
@@ -1543,5 +1544,28 @@
"name": "Preview"
}
}
+ },
+ "debug-log": {
+ "title": "Debug Log",
+ "no-logs": "No debug logs",
+ "count-of-logs": "Fetched latest {count} log(s) from server.",
+ "debug-log-detail": "Debug Log Details",
+ "table": {
+ "record-ts": "Time",
+ "method": "Method",
+ "request-path": "Request path",
+ "role": "Role",
+ "error": "Error",
+ "stack-trace": "Stack trace",
+ "empty": "<Empty>",
+ "operation": {
+ "operation": "Operation",
+ "view-details": "View Details",
+ "copy": "Copy",
+ "copy-all": "Copy All",
+ "copied": "Copied!",
+ "export": "Export"
+ }
+ }
}
}
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 56f85dc68a..4f9ccca4dc 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -319,7 +319,8 @@
"members": "成员",
"version-control": "版本控制",
"subscription": "订阅",
- "labels": "标签"
+ "labels": "标签",
+ "debug-log": "Debug 日志"
},
"profile": {
"email": "邮箱",
@@ -1543,5 +1544,28 @@
"name": "预览"
}
}
+ },
+ "debug-log": {
+ "title": "Debug 日志",
+ "no-logs": "暂无 Debug 日志",
+ "count-of-logs": "从服务端获取的最新 {count} 条日志。",
+ "debug-log-detail": "日志详情",
+ "table": {
+ "record-ts": "时间",
+ "method": "方法",
+ "request-path": "请求路径",
+ "role": "角色",
+ "error": "错误消息",
+ "stack-trace": "调用栈",
+ "empty": "<无>",
+ "operation": {
+ "operation": "操作",
+ "view-details": "查看详情",
+ "copy": "拷贝",
+ "copy-all": "拷贝全部",
+ "copied": "已拷贝",
+ "export": "导出"
+ }
+ }
}
}
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 194b15812a..ce33a21636 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -428,6 +428,16 @@ const routes: Array<RouteRecordRaw> = [
import("../views/SettingWorkspaceSQLReviewDetail.vue"),
props: true,
},
+ {
+ path: "debug-log",
+ name: "setting.workspace.debug-log",
+ meta: {
+ title: () => t("settings.sidebar.debug-log"),
+ },
+ component: () =>
+ import("../views/SettingWorkspaceDebugLog.vue"),
+ props: true,
+ },
],
},
{
@@ -1006,6 +1016,17 @@ router.beforeEach((to, from, next) => {
}
}
+ if (to.name?.toString().startsWith("setting.workspace.debug-log")) {
+ // Returns 403 immediately if not DBA or Owner.
+ if (!isDBAOrOwner(currentUser.role)) {
+ next({
+ name: "error.403",
+ replace: false,
+ });
+ return;
+ }
+ }
+
if (to.name === "workspace.instance") {
if (
!hasFeature("bb.feature.dba-workflow") ||
diff --git a/frontend/src/store/modules/debug.ts b/frontend/src/store/modules/debug.ts
index ac5441c67c..ad3f9ff25f 100644
--- a/frontend/src/store/modules/debug.ts
+++ b/frontend/src/store/modules/debug.ts
@@ -1,12 +1,19 @@
-import { defineStore } from "pinia";
+import { watchEffect } from "vue";
+import { defineStore, storeToRefs } from "pinia";
import axios from "axios";
-import type { DebugState, ResourceObject } from "@/types";
-import type { Debug, DebugPatch } from "@/types/debug";
+import type { DebugState, DebugLogState, ResourceObject } from "@/types";
+import type { Debug, DebugPatch, DebugLog } from "@/types/debug";
-function convert(debug: ResourceObject): Debug {
+function convertDebugState(debug: ResourceObject): Debug {
return { ...(debug.attributes as Omit<Debug, "">) };
}
+function convertDebugLogList(debugLogList: ResourceObject[]): DebugLog[] {
+ return debugLogList.map(
+ (debugLog) => debugLog.attributes.errorRecord as DebugLog
+ );
+}
+
export const useDebugStore = defineStore("debug", {
state: (): DebugState => ({
isDebug: false,
@@ -17,12 +24,12 @@ export const useDebugStore = defineStore("debug", {
},
async fetchDebug() {
const res = (await axios.get("/api/debug")).data;
- const debug = convert(res.data);
+ const debug = convertDebugState(res.data);
this.setDebug(debug);
return debug;
},
async patchDebug(debugPatch: DebugPatch) {
- const debugState = convert(
+ const debugState = convertDebugState(
(
await axios.patch("/api/debug", {
data: {
@@ -36,3 +43,27 @@ export const useDebugStore = defineStore("debug", {
},
},
});
+
+export const useDebugLogStore = defineStore("debugLog", {
+ state: (): DebugLogState => ({
+ debugLogList: [],
+ }),
+ actions: {
+ setDebugLogList(debugLogList: DebugLog[]) {
+ this.debugLogList = debugLogList;
+ },
+ async fetchDebugLogList() {
+ const res = (await axios.get("/api/debug/log")).data.data;
+ const list = convertDebugLogList(res);
+ this.setDebugLogList(list);
+ return list;
+ },
+ },
+});
+
+export const useDebugLogList = () => {
+ const store = useDebugLogStore();
+ watchEffect(() => store.fetchDebugLogList());
+
+ return storeToRefs(store).debugLogList;
+};
diff --git a/frontend/src/types/debug.ts b/frontend/src/types/debug.ts
index b04d3eb649..cbc013ac18 100644
--- a/frontend/src/types/debug.ts
+++ b/frontend/src/types/debug.ts
@@ -5,3 +5,12 @@ export type Debug = {
export type DebugPatch = {
isDebug: boolean;
};
+
+export type DebugLog = {
+ RecordTs: number;
+ Method: string;
+ RequestPath: string;
+ Role: string;
+ Error: string;
+ StackTrace: string;
+};
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index d282937556..f29e11b7c1 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -8,6 +8,7 @@ export * from "./column";
export * from "./common";
export * from "./database";
export * from "./dataSource";
+export * from "./debug";
export * from "./environment";
export * from "./error";
export * from "./errorList";
diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.ts
index 96cc1d2f2f..523d423940 100644
--- a/frontend/src/types/store.ts
+++ b/frontend/src/types/store.ts
@@ -48,6 +48,7 @@ import { VCS } from "./vcs";
import { Label } from "./label";
import { ConnectionAtom, ConnectionContext } from "./sqlEditor";
import { TabInfo } from "./tab";
+import type { DebugLog } from "@/types/debug";
export interface ActuatorState {
serverInfo?: ServerInfo;
@@ -220,6 +221,9 @@ export interface SheetState {
export interface DebugState {
isDebug: boolean;
}
+export interface DebugLogState {
+ debugLogList: DebugLog[];
+}
export interface OnboardingGuideState {
guideName?: OnboardingGuideType;
diff --git a/frontend/src/views/SettingSidebar.vue b/frontend/src/views/SettingSidebar.vue
index 9bf42437a1..520ed45d86 100644
--- a/frontend/src/views/SettingSidebar.vue
+++ b/frontend/src/views/SettingSidebar.vue
@@ -83,6 +83,12 @@
class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
>{{ $t("settings.sidebar.subscription") }}</router-link
>
+ <router-link
+ v-if="showOwnerOrDBAItem"
+ to="/setting/debug-log"
+ class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
+ >{{ $t("settings.sidebar.debug-log") }}</router-link
+ >
<!-- <router-link
to="/setting/billing"
class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
diff --git a/frontend/src/views/SettingWorkspaceDebugLog.vue b/frontend/src/views/SettingWorkspaceDebugLog.vue
new file mode 100644
index 0000000000..eae62bd410
--- /dev/null
+++ b/frontend/src/views/SettingWorkspaceDebugLog.vue
@@ -0,0 +1,124 @@
+<template>
+ <div class="space-y-4">
+ <div v-if="debugLogList.length > 0">
+ <div class="flex flex-row justify-between items-center textinfolabel">
+ {{
+ $t("debug-log.count-of-logs", {
+ count: debugLogList.length,
+ })
+ }}
+ <button
+ class="group btn-normal items-center !border-0 !bg-accent !text-white hover:!bg-indigo-500"
+ @click="handleExport"
+ >
+ <heroicons-outline:document-arrow-down class="h-4 w-4 mr-1" />
+ {{ $t("debug-log.table.operation.export") }}
+ </button>
+ </div>
+ <DebugLogTable
+ :debug-log-list="debugLogList"
+ @view-detail="
+ (log: any) => {
+ state.modalContent = log
+ state.showModal = true;
+ dialog!.open();
+ }
+ "
+ />
+ <BBDialog
+ ref="dialog"
+ :title="$t('debug-log.debug-log-detail')"
+ :negative-text="$t('common.close')"
+ :positive-text="$t('debug-log.table.operation.copy')"
+ data-label="bb-migration-mode-dialog"
+ @before-positive-click="handleCopy"
+ >
+ <div class="w-192 font-mono">
+ <dl>
+ <dd
+ v-for="(value, key) in state.modalContent"
+ :key="key"
+ class="flex items-start text-sm md:mr-4 mb-1"
+ >
+ <NGrid x-gap="20" :cols="20">
+ <NGi span="3">
+ <span class="textlabel whitespace-nowrap">{{
+ logKeyMap[key]
+ }}</span
+ ><span class="mr-1">:</span>
+ </NGi>
+ <NGi span="17">
+ <span v-if="value !== ''">
+ {{
+ key === "RecordTs"
+ ? dayjs.unix(value as number).format("YYYY-MM-DD HH:mm:ss Z")
+ : value
+ }}
+ </span>
+ <span v-else class="italic text-gray-500">
+ {{ $t("debug-log.table.empty") }}
+ </span>
+ </NGi>
+ </NGrid>
+ </dd>
+ </dl>
+ </div>
+ </BBDialog>
+ </div>
+ <DebugLogsEmptyView v-else />
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { reactive, ref, computed } from "vue";
+import { NGrid, NGi } from "naive-ui";
+import { useI18n } from "vue-i18n";
+import download from "downloadjs";
+import dayjs from "dayjs";
+import { useClipboard } from "@vueuse/core";
+import { BBDialog } from "@/bbkit";
+import { useDebugLogList, useNotificationStore } from "@/store";
+
+const dialog = ref<InstanceType<typeof BBDialog> | null>(null);
+const state = reactive({
+ showModal: false,
+ modalContent: {},
+});
+const logString = computed(() => {
+ return JSON.stringify(state.modalContent);
+});
+
+const { t } = useI18n();
+const { copy } = useClipboard({
+ source: logString,
+});
+const notificationStore = useNotificationStore();
+const debugLogList = useDebugLogList();
+
+const logKeyMap = {
+ RecordTs: t("debug-log.table.record-ts"),
+ Method: t("debug-log.table.method"),
+ RequestPath: t("debug-log.table.request-path"),
+ Role: t("debug-log.table.role"),
+ Error: t("debug-log.table.error"),
+ StackTrace: t("debug-log.table.stack-trace"),
+};
+
+const handleExport = () => {
+ download(
+ JSON.stringify(debugLogList.value, null, 2),
+ `debuglog_${dayjs().format("YYYYMMDD")}.json`,
+ "text/plain"
+ );
+};
+
+const handleCopy = () => {
+ copy();
+ notificationStore.pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("debug-log.table.operation.copied"),
+ });
+ return true;
+};
+</script>
diff --git a/server/debug.go b/server/debug.go
index 2cf5e8831f..317495db83 100644
--- a/server/debug.go
+++ b/server/debug.go
@@ -36,6 +36,12 @@ func (s *Server) registerDebugRoutes(g *echo.Group) {
// incrementID is used as primary key in jsonapi.
var incrementID int
+ // Only Owner and DBA can see debug logs.
+ role := c.Get(getRoleContextKey()).(api.Role)
+ if role != api.Owner && role != api.DBA {
+ return echo.NewHTTPError(http.StatusForbidden, "Not allowed to fetch debug logs")
+ }
+
s.errorRecordRing.RWMutex.RLock()
defer s.errorRecordRing.RWMutex.RUnlock()