Skip to content

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

feat: slow query guide improvements (#6871)

Liu Jib817b7ebdac7
diff --git a/frontend/src/components/SlowQuery/Panel/LogFilter.vue b/frontend/src/components/SlowQuery/Panel/LogFilter.vue
index 2637858733..275dbe49e4 100644
--- a/frontend/src/components/SlowQuery/Panel/LogFilter.vue
+++ b/frontend/src/components/SlowQuery/Panel/LogFilter.vue
@@ -17,7 +17,7 @@
/>
</div>
- <div class="flex items-center justify-end">
+ <div class="flex items-center justify-end gap-x-3">
<slot name="suffix" />
</div>
</div>
diff --git a/frontend/src/components/SlowQuery/Panel/LogTable.vue b/frontend/src/components/SlowQuery/Panel/LogTable.vue
index d1e8b66ff9..cd0e76cdc7 100644
--- a/frontend/src/components/SlowQuery/Panel/LogTable.vue
+++ b/frontend/src/components/SlowQuery/Panel/LogTable.vue
@@ -99,6 +99,17 @@
/>
</div>
</template>
+
+ <template #placeholder-content>
+ <div class="py-8 px-8 text-center">
+ <p v-if="allowAdmin">
+ {{ $t("slow-query.no-log-placeholder.admin") }}
+ </p>
+ <p v-else>
+ {{ $t("slow-query.no-log-placeholder.developer") }}
+ </p>
+ </div>
+ </template>
</BBGrid>
</template>
@@ -126,6 +137,7 @@ const props = withDefaults(
showEnvironmentColumn?: boolean;
showInstanceColumn?: boolean;
showDatabaseColumn?: boolean;
+ allowAdmin: boolean;
}>(),
{
slowQueryLogList: () => [],
diff --git a/frontend/src/components/SlowQuery/Panel/SlowQueryPanel.vue b/frontend/src/components/SlowQuery/Panel/SlowQueryPanel.vue
index a0d755b07b..bec71e6806 100644
--- a/frontend/src/components/SlowQuery/Panel/SlowQueryPanel.vue
+++ b/frontend/src/components/SlowQuery/Panel/SlowQueryPanel.vue
@@ -8,7 +8,15 @@
@update:params="$emit('update:filter', $event)"
>
<template #suffix>
- <NButton type="default" :loading="syncing" @click="syncNow">
+ <NButton v-if="allowAdmin" type="default" @click="goConfig">
+ {{ $t("common.configure") }}
+ </NButton>
+ <NButton
+ type="default"
+ :disabled="!allowSync"
+ :loading="syncing"
+ @click="syncNow"
+ >
{{ $t("common.sync-now") }}
</NButton>
</template>
@@ -22,6 +30,7 @@
:show-environment-column="showEnvironmentColumn"
:show-instance-column="showInstanceColumn"
:show-database-column="showDatabaseColumn"
+ :allow-admin="allowAdmin"
@select="selectSlowQueryLog"
/>
<div
@@ -47,7 +56,9 @@ import { useI18n } from "vue-i18n";
import { ComposedSlowQueryLog } from "@/types";
import {
pushNotification,
+ useCurrentUserV1,
useGracefulRequest,
+ useSlowQueryPolicyList,
useSlowQueryPolicyStore,
useSlowQueryStore,
} from "@/store";
@@ -60,7 +71,8 @@ import {
import LogFilter from "./LogFilter.vue";
import LogTable from "./LogTable.vue";
import DetailPanel from "./DetailPanel.vue";
-import { extractInstanceResourceName } from "@/utils";
+import { extractInstanceResourceName, hasWorkspacePermissionV1 } from "@/utils";
+import { useRouter } from "vue-router";
const props = withDefaults(
defineProps<{
@@ -85,6 +97,8 @@ defineEmits<{
}>();
const { t } = useI18n();
+const router = useRouter();
+const currentUser = useCurrentUserV1();
const slowQueryStore = useSlowQueryStore();
const loading = shallowRef(false);
const slowQueryLogList = shallowRef<ComposedSlowQueryLog[]>([]);
@@ -95,6 +109,22 @@ const params = computed(() => {
return buildListSlowQueriesRequest(props.filter);
});
+const allowAdmin = computed(() => {
+ return hasWorkspacePermissionV1(
+ "bb.permission.workspace.manage-slow-query",
+ currentUser.value.userRole
+ );
+});
+
+const { list: slowQueryPolicyList } = useSlowQueryPolicyList();
+
+const allowSync = computed(() => {
+ return (
+ slowQueryPolicyList.value.filter((policy) => policy.slowQueryPolicy?.active)
+ .length > 0
+ );
+});
+
const fetchSlowQueryLogList = async () => {
loading.value = true;
try {
@@ -135,6 +165,12 @@ const syncNow = async () => {
}
};
+const goConfig = () => {
+ router.push({
+ name: "setting.workspace.slow-query",
+ });
+};
+
// Fetch the list while params changed.
watch(() => JSON.stringify(params.value), fetchSlowQueryLogList, {
immediate: true,
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 2d4dd33ba0..cc22846619 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2546,6 +2546,10 @@
"suggestion": "Suggestion",
"create-index": "Create Index",
"setup-openai-key-to-enable": "Setup OpenAI key to enable index advisor"
+ },
+ "no-log-placeholder": {
+ "admin": "Click the \"Configure\" button to fetch slow queries from the database instances or click the \"Sync Now\" button to sync slow query logs immediately",
+ "developer": "Click the \"Sync Now\" button to sync slow query logs immediately or contact Bytebase owners/DBAs to configure slow queries"
}
},
"principal": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 7d3c7b7b79..e133604508 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2525,6 +2525,10 @@
"suggestion": "Sugerencia",
"create-index": "Crear índice",
"setup-openai-key-to-enable": "Configure la clave de OpenAI para habilitar el asesor de índices"
+ },
+ "no-log-placeholder": {
+ "admin": "Haga clic en el botón \"Configurar\" para obtener consultas lentas de las instancias de la base de datos o haga clic en el botón \"Sincronizar ahora\" para sincronizar los registros de consultas lentas de inmediato",
+ "developer": "Haga clic en el botón \"Sincronizar ahora\" para sincronizar los registros de consultas lentas inmediatamente o comuníquese con los propietarios/DBA de Bytebase para configurar consultas lentas"
}
},
"principal": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 184b80eef5..f41204066a 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2539,6 +2539,10 @@
"suggestion": "建议",
"create-index": "创建索引",
"setup-openai-key-to-enable": "设置 OpenAI API Key 以开启索引建议功能。"
+ },
+ "no-log-placeholder": {
+ "admin": "点击「配置」按钮从数据库实例上抓取慢查询日志或点击「立即同步」按钮立即同步慢查询日志",
+ "developer": "点击「立即同步」按钮立即同步慢查询日志或联系工作空间所有者或 DBA 配置慢查询功能"
}
},
"principal": {