Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: add feature guard for index advisor (#5914)
boojack04ceec4ef367
diff --git a/frontend/src/bbkit/BBNotification.vue b/frontend/src/bbkit/BBNotification.vueindex 487826c6c7..b74266fc33 100644--- a/frontend/src/bbkit/BBNotification.vue+++ b/frontend/src/bbkit/BBNotification.vue@@ -1,6 +1,6 @@<template><div- class="fixed inset-0 px-4 py-6 pointer-events-none sm:p-6 z-50"+ class="fixed inset-0 px-4 py-6 pointer-events-none sm:p-6 z-[9999]":class="placementClass"><templatediff --git a/frontend/src/components/SlowQuery/Panel/DetailPanel.vue b/frontend/src/components/SlowQuery/Panel/DetailPanel.vueindex 61208272b8..7a9e369661 100644--- a/frontend/src/components/SlowQuery/Panel/DetailPanel.vue+++ b/frontend/src/components/SlowQuery/Panel/DetailPanel.vue@@ -3,6 +3,7 @@:show="slowQueryLog !== undefined":auto-focus="false"width="auto"+ :z-index="30"@update:show="(show) => !show && $emit('close')"><NDrawerContent@@ -61,7 +62,7 @@</div></div></div>- <AdviseIndex v-if="slowQueryLog" :slow-query-log="slowQueryLog" />+ <IndexAdvisor v-if="slowQueryLog" :slow-query-log="slowQueryLog" /><divv-if="instanceHasSlowQueryDetail(database.instance)"class="flex-1 overflow-auto border"@@ -136,7 +137,7 @@ import {ProjectName,} from "@/components/v2";import HighlightCodeBlock from "@/components/HighlightCodeBlock";-import AdviseIndex from "./AdviseIndex.vue";+import IndexAdvisor from "./IndexAdvisor.vue";export type SlowQueryDetailsRow = BBGridRow<SlowQueryDetails>;diff --git a/frontend/src/components/SlowQuery/Panel/AdviseIndex.vue b/frontend/src/components/SlowQuery/Panel/IndexAdvisor.vuesimilarity index 63%rename from frontend/src/components/SlowQuery/Panel/AdviseIndex.vuerename to frontend/src/components/SlowQuery/Panel/IndexAdvisor.vueindex 39eab11fa6..ab7c089abe 100644--- a/frontend/src/components/SlowQuery/Panel/AdviseIndex.vue+++ b/frontend/src/components/SlowQuery/Panel/IndexAdvisor.vue@@ -1,5 +1,6 @@<template><div+ v-if="showIndexAdvisor"class="w-full min-w-[128px] flex flex-row justify-start items-start gap-4"><div class="w-1/4 flex flex-col justify-start items-start gap-2">@@ -9,53 +10,91 @@<span class="font-mono">{{ state.currentIndex }}</span></div><div class="w-3/4 flex flex-col justify-start items-start gap-2">- <div>+ <div class="flex flex-row justify-start items-center"><span class="font-medium capitalize whitespace-nowrap">{{$t("slow-query.advise-index.suggestion")}}</span>- <button class="ml-2 normal-link underline" @click="handleCreateIndex">+ <BBSpin v-if="state.isLoading" class="ml-2" />+ <button+ v-else+ class="ml-2 normal-link underline"+ @click="handleCreateIndex"+ >{{ $t("slow-query.advise-index.create-index") }}</button>- <!--TODO(boojack): add a FeatureBadge for bb.feature.plugin.openai here--></div><span class="w-full font-mono">{{ state.suggestion }}</span></div></div>+ <div v-else-if="!hasIndexAdvisorFeature">+ <div class="btn btn-primary !w-auto" @click="state.showFeatureModal = true">+ {{ $t("subscription.features.bb-feature-index-advisor.title") }}+ <FeatureBadge class="ml-1" feature="bb.feature.index-advisor" />+ </div>+ </div>+ <div v-else-if="!hasOpenAIKeySetup">+ <router-link class="normal-link" to="/setting/general">{{+ $t("slow-query.advise-index.setup-openai-key-to-enable")+ }}</router-link>+ </div>++ <FeatureModal+ v-if="state.showFeatureModal"+ feature="bb.feature.index-advisor"+ @cancel="state.showFeatureModal = false"+ /></template><script lang="ts" setup>-import { computed } from "vue";-import { ComposedSlowQueryLog } from "@/types";-import { reactive } from "vue";-import { watch } from "vue";import dayjs from "dayjs";+import { computed, reactive, watch } from "vue";+import { ComposedSlowQueryLog } from "@/types";import { useRouter } from "vue-router";import { databaseServiceClient } from "@/grpcweb";import { getErrorCode } from "@/utils/grpcweb";import { Status } from "nice-grpc-common";-import { hasFeature } from "@/store";+import { featureToRef, hasFeature, useSettingStore } from "@/store";+import FeatureBadge from "@/components/FeatureBadge.vue";const props = defineProps<{slowQueryLog: ComposedSlowQueryLog;}>();interface LocalState {+ isLoading: boolean;currentIndex: string;suggestion: string;createIndexStatement: string;+ showFeatureModal: boolean;}const router = useRouter();const state = reactive<LocalState>({+ isLoading: false,currentIndex: "",suggestion: "",createIndexStatement: "",+ showFeatureModal: false,+});+const settingStore = useSettingStore();+const hasIndexAdvisorFeature = featureToRef("bb.feature.index-advisor");+const hasOpenAIKeySetup = computed(() => {+ const openAIKeySetting = settingStore.getSettingByName(+ "bb.plugin.openai.key"+ );+ if (openAIKeySetting) {+ return openAIKeySetting.value !== "";+ }+ return false;});const log = computed(() => props.slowQueryLog.log);const database = computed(() => props.slowQueryLog.database);const sqlFingerprint = computed(() => log.value.statistics?.sqlFingerprint || "");+const showIndexAdvisor = computed(() => {+ return hasIndexAdvisorFeature.value && hasOpenAIKeySetup.value;+});const handleCreateIndex = () => {const query: Record<string, any> = {@@ -91,7 +130,8 @@ const generateIssueName = () => {watch(() => props.slowQueryLog,async () => {- if (hasFeature("bb.feature.plugin.openai")) {+ if (hasFeature("bb.feature.plugin.openai") && hasOpenAIKeySetup.value) {+ state.isLoading = true;try {const response = await databaseServiceClient.adviseIndex({parent: log.value.resource,@@ -103,9 +143,11 @@ watch(state.createIndexStatement = response.createIndexStatement;} catch (error) {if (getErrorCode(error) !== Status.NOT_FOUND) {+ state.isLoading = false;throw error;}}+ state.isLoading = false;} else {state.currentIndex = "";state.suggestion = "";diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 91267ef4d9..1731670a8d 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1929,6 +1929,10 @@"title": "Read replica connection","desc": "Connect to a read replica for the read-only data source."},+ "bb-feature-index-advisor": {+ "title": "Index advisor",+ "desc": "Index advisor can help you to find the missing indexes in slow queries."+ },"bb-feature-sso": {"title": "Single Sign-On (SSO)","desc": "Enables users to securely authenticate with multiple applications and websites via a single set of credentials."@@ -2413,7 +2417,8 @@"advise-index": {"current-index": "Current Index","suggestion": "Suggestion",- "create-index": "Create Index"+ "create-index": "Create Index",+ "setup-openai-key-to-enable": "Setup OpenAI key to enable index advisor"}},"principal": {diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex d121189156..e73bb5c8a3 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1920,6 +1920,10 @@"title": "Conexión a réplica de lectura","desc": "Conéctate a una réplica de lectura para obtener una fuente de datos de solo lectura."},+ "bb-feature-index-advisor": {+ "title": "Asesor de índice",+ "desc": "El asesor de índices puede ayudarle a encontrar los índices que faltan en las consultas lentas."+ },"bb-feature-sso": {"title": "Inicio de sesión único (SSO)","desc": "Permite a los usuarios autenticarse de manera segura en varias aplicaciones y sitios web mediante un único conjunto de credenciales."@@ -2404,7 +2408,8 @@"advise-index": {"current-index": "Índice actual","suggestion": "Sugerencia",- "create-index": "Crear índice"+ "create-index": "Crear índice",+ "setup-openai-key-to-enable": "Configure la clave de OpenAI para habilitar el asesor de índices"}},"principal": {diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex e61311b4a0..618887a571 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1926,6 +1926,10 @@"title": "Read replica connection","desc": "使用只读副本连接到只读数据源。"},+ "bb-feature-index-advisor": {+ "title": "索引建议",+ "desc": "索引建议可以找到导致慢查询的索引,并提供相关的优化建议。"+ },"bb-feature-sso": {"title": "Single Sign-On (SSO)","desc": "使得用户能够通过 SSO 安全地进行登录 Bytebase。"@@ -2408,7 +2412,8 @@"advise-index": {"current-index": "当前索引","suggestion": "建议",- "create-index": "创建索引"+ "create-index": "创建索引",+ "setup-openai-key-to-enable": "设置 OpenAI API Key 以开启索引建议功能。"}},"principal": {