Skip to content

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

feat: custom instance scan interval (#7968)

Liu Jie0573f6f150d
diff --git a/backend/legacyapi/plan.go b/backend/legacyapi/plan.go
index e9689de690..d9cf1cdf75 100644
--- a/backend/legacyapi/plan.go
+++ b/backend/legacyapi/plan.go
@@ -143,6 +143,8 @@ const (
FeatureReadReplicaConnection FeatureType = "bb.feature.read-replica-connection"
// FeatureInstanceSSHConnection provides SSH connection for instances.
FeatureInstanceSSHConnection FeatureType = "bb.feature.instance-ssh-connection"
+ // FeatureCustomInstanceScanInterval allows user to customize schema and anomaly scan interval per instance.
+ FeatureCustomInstanceScanInterval FeatureType = "bb.feature.custom-instance-scan-interval"
// FeatureSyncSchemaAllVersions allows user to sync the base database schema all versions into target database.
FeatureSyncSchemaAllVersions FeatureType = "bb.feature.sync-schema-all-versions"
// FeatureIndexAdvisor provides the index advisor for databases.
@@ -247,6 +249,8 @@ func (e FeatureType) Name() string {
return "Read replica connection"
case FeatureInstanceSSHConnection:
return "Instance SSH connection"
+ case FeatureCustomInstanceScanInterval:
+ return "Custom instance scan interval"
case FeatureSyncSchemaAllVersions:
return "Synchronize schema all versions"
case FeatureIndexAdvisor:
@@ -324,11 +328,12 @@ var FeatureMatrix = map[FeatureType][3]bool{
FeatureVCSSheetSync: {false, true, true},
FeatureVCSSQLReviewWorkflow: {true, true, true},
// Database management
- FeaturePITR: {false, true, true},
- FeatureReadReplicaConnection: {false, false, true},
- FeatureInstanceSSHConnection: {false, false, true},
- FeatureSyncSchemaAllVersions: {false, true, true},
- FeatureIndexAdvisor: {false, false, true},
+ FeaturePITR: {false, true, true},
+ FeatureReadReplicaConnection: {false, false, true},
+ FeatureInstanceSSHConnection: {false, false, true},
+ FeatureCustomInstanceScanInterval: {false, false, true},
+ FeatureSyncSchemaAllVersions: {false, true, true},
+ FeatureIndexAdvisor: {false, false, true},
// Policy Control
FeatureApprovalPolicy: {false, true, true},
FeatureBackupPolicy: {false, true, true},
@@ -355,12 +360,13 @@ var InstanceLimitFeature = map[FeatureType]bool{
FeatureVCSSQLReviewWorkflow: true,
FeatureMybatisSQLReview: true,
// Database management
- FeaturePITR: true,
- FeatureReadReplicaConnection: true,
- FeatureInstanceSSHConnection: true,
- FeatureDatabaseGrouping: true,
- FeatureSyncSchemaAllVersions: true,
- FeatureIndexAdvisor: true,
+ FeaturePITR: true,
+ FeatureReadReplicaConnection: true,
+ FeatureInstanceSSHConnection: true,
+ FeatureCustomInstanceScanInterval: true,
+ FeatureDatabaseGrouping: true,
+ FeatureSyncSchemaAllVersions: true,
+ FeatureIndexAdvisor: true,
// Policy Control
FeatureSensitiveData: true,
FeatureCustomApproval: true,
diff --git a/frontend/src/components/InstanceForm/InstanceForm.vue b/frontend/src/components/InstanceForm/InstanceForm.vue
index 2a6f6a91b5..a80438eb79 100644
--- a/frontend/src/components/InstanceForm/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm/InstanceForm.vue
@@ -210,6 +210,13 @@
</label>
</div>
+ <ScanIntervalInput
+ v-if="!isCreating"
+ :scan-interval="basicInfo.options?.syncInterval"
+ :allow-edit="allowEdit"
+ @update:scan-interval="changeScanInterval"
+ />
+
<!--Do not show external link on create to reduce cognitive load-->
<div v-if="!isCreating" class="sm:col-span-3 sm:col-start-1">
<label for="external-link" class="textlabel inline-flex">
@@ -390,6 +397,7 @@ import {
unknownEnvironment,
ComposedInstance,
} from "@/types";
+import { Duration } from "@/types/proto/google/protobuf/duration";
import { Engine } from "@/types/proto/v1/common";
import {
DataSource,
@@ -409,6 +417,7 @@ import {
import { extractGrpcErrorMessage, getErrorCode } from "@/utils/grpcweb";
import DataSourceSection from "./DataSourceSection/DataSourceSection.vue";
import OracleSyncModeInput from "./OracleSyncModeInput.vue";
+import ScanIntervalInput from "./ScanIntervalInput.vue";
import SpannerHostInput from "./SpannerHostInput.vue";
import { EditDataSource, extractDataSourceEditState } from "./common";
import { extractBasicInfo } from "./common";
@@ -650,6 +659,12 @@ const changeSyncMode = (schemaTenantMode: boolean) => {
}
basicInfo.value.options.schemaTenantMode = schemaTenantMode;
};
+const changeScanInterval = (duration: Duration | undefined) => {
+ if (!basicInfo.value.options) {
+ basicInfo.value.options = InstanceOptions.fromPartial({});
+ }
+ basicInfo.value.options.syncInterval = duration;
+};
const trimInputValue = (target: Event["target"]) => {
return ((target as HTMLInputElement)?.value ?? "").trim();
@@ -813,6 +828,12 @@ const doUpdate = async () => {
) {
updateMask.push("options.schema_tenant_mode");
}
+ if (
+ instancePatch.options?.syncInterval?.seconds !==
+ instance.options?.syncInterval?.seconds
+ ) {
+ updateMask.push("options.sync_interval");
+ }
return await instanceV1Store.updateInstance(instancePatch, updateMask);
};
const updateDataSource = async (
diff --git a/frontend/src/components/InstanceForm/ScanIntervalInput.vue b/frontend/src/components/InstanceForm/ScanIntervalInput.vue
new file mode 100644
index 0000000000..8fa287ea1e
--- /dev/null
+++ b/frontend/src/components/InstanceForm/ScanIntervalInput.vue
@@ -0,0 +1,141 @@
+<template>
+ <div class="sm:col-span-4 sm:col-start-1 flex flex-col gap-y-2">
+ <label class="textlabel">
+ {{ $t("instance.scan-interval.self") }}
+ </label>
+ <div class="textinfolabel">
+ {{ $t("instance.scan-interval.description") }}
+ </div>
+ <div class="flex items-center gap-x-6">
+ <NRadio
+ :checked="mode === 'DEFAULT'"
+ :disabled="!allowEdit"
+ value="DEFAULT"
+ @update:checked="handleModeChange('DEFAULT')"
+ >
+ {{ $t("instance.scan-interval.default-daily") }}
+ </NRadio>
+
+ <NRadio
+ :checked="mode === 'CUSTOM'"
+ :disabled="!allowEdit"
+ value="CUSTOM"
+ class="!items-center"
+ @update:checked="handleModeChange('CUSTOM')"
+ >
+ <div class="flex items-center gap-x-1.5">
+ <span>{{ $t("common.custom") }}</span>
+ <NInputNumber
+ v-model:value="minutes"
+ :show-button="false"
+ :min="30"
+ placeholder=""
+ size="small"
+ style="width: 4rem"
+ :disabled="mode !== 'CUSTOM'"
+ />
+ <span>{{ $t("common.minutes") }}</span>
+ <FeatureBadgeForInstanceLicense
+ feature="bb.feature.custom-instance-scan-interval"
+ :instance="instance"
+ />
+ </div>
+ </NRadio>
+ </div>
+
+ <InstanceAssignment
+ :show="showInstanceAssignment"
+ @dismiss="showInstanceAssignment = false"
+ />
+ </div>
+</template>
+
+<script setup lang="ts">
+import { NInputNumber, NRadio } from "naive-ui";
+import { computed, reactive, ref } from "vue";
+import { useSubscriptionV1Store } from "@/store";
+import { Duration } from "@/types/proto/google/protobuf/duration";
+import FeatureBadgeForInstanceLicense from "../FeatureGuard/FeatureBadgeForInstanceLicense.vue";
+import InstanceAssignment from "../InstanceAssignment.vue";
+import { useInstanceFormContext } from "./context";
+
+type Mode = "DEFAULT" | "CUSTOM";
+
+const props = defineProps<{
+ scanInterval?: Duration | undefined;
+ allowEdit: boolean;
+}>();
+
+const emit = defineEmits<{
+ (event: "update:scan-interval", interval: Duration | undefined): void;
+}>();
+
+const subscriptionStore = useSubscriptionV1Store();
+const { instance } = useInstanceFormContext();
+const showInstanceAssignment = ref(false);
+
+const mode = computed(() => {
+ const duration = props.scanInterval;
+ if (!duration) return "DEFAULT";
+ if (duration.seconds === 0) return "DEFAULT";
+ return "CUSTOM";
+});
+
+const state = reactive({
+ minutes: undefined as number | undefined, // Local input state
+});
+
+const minutes = computed({
+ get() {
+ const duration = props.scanInterval;
+ if (!duration) return undefined;
+ if (duration.seconds === 0) return undefined;
+ return Math.floor(duration.seconds / 60);
+ },
+ set(value) {
+ if (!value) {
+ emit(
+ "update:scan-interval",
+ Duration.fromPartial({
+ seconds: 0,
+ })
+ );
+ return;
+ }
+
+ if (
+ !subscriptionStore.hasInstanceFeature(
+ "bb.feature.custom-instance-scan-interval",
+ instance.value
+ )
+ ) {
+ showInstanceAssignment.value = true;
+ return;
+ }
+
+ state.minutes = value;
+ const duration = Duration.fromPartial({
+ seconds: value * 60,
+ });
+ emit("update:scan-interval", duration);
+ },
+});
+
+const handleModeChange = (mode: Mode) => {
+ if (mode === "DEFAULT") {
+ minutes.value = undefined;
+ } else {
+ if (
+ !subscriptionStore.hasInstanceFeature(
+ "bb.feature.custom-instance-scan-interval",
+ instance.value
+ )
+ ) {
+ showInstanceAssignment.value = true;
+ return;
+ }
+
+ minutes.value = state.minutes ?? 1440;
+ }
+};
+</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 8554c9dcc8..636f7906d4 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -261,7 +261,8 @@
"search-user": "Search user",
"branches": "Branches",
"merge": "Merge",
- "info": "Info"
+ "info": "Info",
+ "minutes": "Minutes"
},
"error-page": {
"go-back-home": "Go back home"
@@ -1096,6 +1097,11 @@
"self": "Manage based on schema",
"description": "Each schema is treated as a managed object. (Only supports non-CDB mode)"
}
+ },
+ "scan-interval": {
+ "self": "Scan Interval",
+ "default-daily": "Default (daily)",
+ "description": "Bytebase periodically syncs instance schema and detects anomalies."
}
},
"environment": {
@@ -1502,7 +1508,7 @@
},
"anomaly": {
"attention-title": "Anomaly detection",
- "attention-desc": "Bytebase periodically scans the managed resources and list the detected anomalies here. The list is refreshed roughly every 10 minutes.",
+ "attention-desc": "Bytebase periodically detects anomalies based on the instance scan interval, and surfaces the findings here.",
"table-search-placeholder": "Search {type} or environment",
"table-placeholder": "Hooray, no {type} anomaly detected!",
"tooltip": "{env} has {criticalCount} CRITICAL, {highCount} HIGH and {mediumCount} MEDIUM anomalies",
@@ -2241,6 +2247,10 @@
"title": "Instance SSH connection",
"desc": "Connect to a instance over SSH."
},
+ "bb-feature-custom-instance-scan-interval": {
+ "title": "Custom instance scan interval",
+ "desc": "Customize schema and anomaly scan interval for instance"
+ },
"bb-feature-index-advisor": {
"title": "Index advisor",
"desc": "Index advisor can help you to find the missing indexes in slow queries."
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 0275b3e577..5bc278875c 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -261,7 +261,8 @@
"search-user": "Buscar usuario",
"branches": "Ramas",
"merge": "Combinar",
- "info": "Información"
+ "info": "Información",
+ "minutes": "Minutos"
},
"error-page": {
"go-back-home": "Volver al inicio"
@@ -1095,6 +1096,11 @@
"self": "Administrar según el esquema",
"description": "Cada esquema se trata como un objeto administrado. (Solo es compatible con el modo no CDB)"
}
+ },
+ "scan-interval": {
+ "self": "Intervalo de escaneo",
+ "default-daily": "Predeterminado (diario)",
+ "description": "Bytebase sincroniza periódicamente el esquema de instancia y detecta anomalías."
}
},
"environment": {
@@ -1501,7 +1507,7 @@
},
"anomaly": {
"attention-title": "Detección de anomalías",
- "attention-desc": "Bytebase escanea periódicamente los recursos administrados y lista las anomalías detectadas aquí. La lista se actualiza aproximadamente cada 10 minutos.",
+ "attention-desc": "Bytebase detecta periódicamente anomalías según el intervalo de escaneo de la instancia y muestra los hallazgos aquí.",
"table-search-placeholder": "Buscar {type} o entorno",
"table-placeholder": "¡Hurra, no se detectaron anomalías de {type}!",
"tooltip": "{env} tiene {criticalCount} anomalías CRÍTICAS, {highCount} anomalías ALTAS y {mediumCount} anomalías MEDIA",
@@ -2284,6 +2290,10 @@
"bb-feature-issue-advanced-search": {
"title": "Búsqueda avanzada de problemas",
"desc": "Acceda a un historial de problemas ilimitado con búsqueda avanzada de problemas."
+ },
+ "bb-feature-custom-instance-scan-interval": {
+ "title": "Intervalo de escaneo de instancia personalizado",
+ "desc": "Personalice el esquema y el intervalo de escaneo de anomalías, por ejemplo"
}
}
},
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 1956039203..56ebcd1be8 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -259,7 +259,8 @@
"search-user": "搜索用户",
"branches": "分支",
"merge": "合并",
- "info": "信息"
+ "info": "信息",
+ "minutes": "分钟"
},
"error-page": {
"go-back-home": "回到主页"
@@ -1093,6 +1094,11 @@
"self": "按 Schema 管理",
"description": "将每个 Schema 作为管理对象。(仅支持非 CDB 模式)"
}
+ },
+ "scan-interval": {
+ "self": "扫描间隔",
+ "default-daily": "默认(每天)",
+ "description": "Bytebase 会定期同步实例的 schema 以及进行异常检测。"
}
},
"environment": {
@@ -1497,7 +1503,7 @@
},
"anomaly": {
"attention-title": "异常检测",
- "attention-desc": "Bytebase 会定期扫描托管的资源,并在这里列出检测到的异常。\n该列表大约每 10 分钟刷新一次。",
+ "attention-desc": "Bytebase 会根据实例配置的扫描间隔检测异常,并且展示在这里。",
"table-search-placeholder": "搜索{type}或者环境",
"table-placeholder": "很棒,没有检测到{type}异常!",
"tooltip": "{env} 环境有 {criticalCount} 个严重异常, {highCount} 个高等级异常和 {mediumCount} 个中等级异常",
@@ -2283,6 +2289,10 @@
"bb-feature-issue-advanced-search": {
"title": "工单高级搜索",
"desc": "通过高级搜索来访问无限制的历史工单。"
+ },
+ "bb-feature-custom-instance-scan-interval": {
+ "title": "自定义实例扫描间隔",
+ "desc": "自定义实例的 schema 和异常扫描间隔"
}
},
"feature-require-subscription": "{feature} 需要 {requiredPlan}。"
diff --git a/frontend/src/types/plan.ts b/frontend/src/types/plan.ts
index 75dfe91b49..32474db562 100644
--- a/frontend/src/types/plan.ts
+++ b/frontend/src/types/plan.ts
@@ -41,6 +41,7 @@ export type FeatureType =
// Database management
| "bb.feature.pitr"
| "bb.feature.read-replica-connection"
+ | "bb.feature.custom-instance-scan-interval"
| "bb.feature.instance-ssh-connection"
| "bb.feature.sync-schema-all-versions"
| "bb.feature.index-advisor"
@@ -67,6 +68,7 @@ export const instanceLimitFeature = new Set<FeatureType>([
"bb.feature.pitr",
"bb.feature.read-replica-connection",
"bb.feature.instance-ssh-connection",
+ "bb.feature.custom-instance-scan-interval",
"bb.feature.sync-schema-all-versions",
"bb.feature.index-advisor",
"bb.feature.database-grouping",