Skip to content

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

Show anomaly table in the database detail overview tab if it contains any anomalies

天舟f286dfca3023
diff --git a/frontend/src/components/AnomalyTable.vue b/frontend/src/components/AnomalyTable.vue
new file mode 100644
index 0000000000..e20cda099c
--- /dev/null
+++ b/frontend/src/components/AnomalyTable.vue
@@ -0,0 +1,63 @@
+<template>
+ <BBTable
+ :columnList="COLUMN_LIST"
+ :dataSource="anomalyList"
+ :showHeader="true"
+ :leftBordered="true"
+ :rightBordered="true"
+ >
+ <template v-slot:body="{ rowData: column }">
+ <BBTableCell :leftPadding="4" class="w-16">
+ {{ column.type }}
+ </BBTableCell>
+ <BBTableCell class="w-48"> </BBTableCell>
+ <BBTableCell class="w-16">
+ {{ humanizeTs(column.updatedTs) }}
+ </BBTableCell>
+ <BBTableCell class="w-16">
+ {{ humanizeTs(column.createdTs) }}
+ </BBTableCell>
+ </template>
+ </BBTable>
+</template>
+
+<script lang="ts">
+import { PropType } from "vue";
+import { BBTableColumn } from "../bbkit/types";
+import { Anomaly, Column } from "../types";
+
+const COLUMN_LIST: BBTableColumn[] = [
+ {
+ title: "Type",
+ },
+ {
+ title: "Detail",
+ },
+ {
+ title: "Last seen",
+ },
+ {
+ title: "First seen",
+ },
+];
+
+export default {
+ name: "AnomalyTable",
+ components: {},
+ props: {
+ columnList: {
+ required: true,
+ type: Object as PropType<Column[]>,
+ },
+ anomalyList: {
+ required: true,
+ type: Object as PropType<Anomaly[]>,
+ },
+ },
+ setup(props, ctx) {
+ return {
+ COLUMN_LIST,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/components/DatabaseOverviewPanel.vue b/frontend/src/components/DatabaseOverviewPanel.vue
index 25a3d2b784..4b2a49ffd4 100644
--- a/frontend/src/components/DatabaseOverviewPanel.vue
+++ b/frontend/src/components/DatabaseOverviewPanel.vue
@@ -1,7 +1,12 @@
<template>
<div class="space-y-6 divide-y divide-block-border">
+ <div v-if="database.anomalyList.length > 0">
+ <div class="text-lg leading-6 font-medium text-main mb-4">Anomalies</div>
+ <AnomalyTable :anomalyList="database.anomalyList" />
+ </div>
+
<!-- Description list -->
- <dl class="grid grid-cols-1 gap-x-4 gap-y-4 sm:grid-cols-2">
+ <dl class="grid grid-cols-1 gap-x-4 gap-y-4 sm:grid-cols-2 pt-4">
<div class="col-span-1 col-start-1">
<dt class="text-sm font-medium text-control-light">Character set</dt>
<dd class="mt-1 text-sm text-main">
@@ -170,6 +175,7 @@
import { computed, reactive, watchEffect, PropType } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
+import AnomalyTable from "../components/AnomalyTable.vue";
import DataSourceTable from "../components/DataSourceTable.vue";
import DataSourceConnectionPanel from "../components/DataSourceConnectionPanel.vue";
import TableTable from "../components/TableTable.vue";
@@ -190,6 +196,7 @@ export default {
},
},
components: {
+ AnomalyTable,
DataSourceConnectionPanel,
DataSourceTable,
TableTable,
diff --git a/frontend/src/store/index.ts b/frontend/src/store/index.ts
index 7e02b3e9bd..d5e31900d8 100644
--- a/frontend/src/store/index.ts
+++ b/frontend/src/store/index.ts
@@ -3,6 +3,7 @@ import { createStore, Store } from "vuex";
import activity from "./modules/activity";
// Actuator module
import actuator from "./modules/actuator";
+import anomaly from "./modules/anomaly";
import auth from "./modules/auth";
import backup from "./modules/backup";
import bookmark from "./modules/bookmark";
@@ -70,6 +71,7 @@ export const store: Store<any> = createStore({
task,
uistate,
vcs,
+ anomaly,
},
strict: !isProd,
});
diff --git a/frontend/src/store/modules/anomaly.ts b/frontend/src/store/modules/anomaly.ts
new file mode 100644
index 0000000000..8f6c158aea
--- /dev/null
+++ b/frontend/src/store/modules/anomaly.ts
@@ -0,0 +1,32 @@
+import { Anomaly, AnomalyState, ResourceObject } from "../../types";
+
+function convert(
+ anomaly: ResourceObject,
+ includedList: ResourceObject[],
+ rootGetters: any
+): Anomaly {
+ return {
+ ...(anomaly.attributes as Omit<Anomaly, "id" | "payload">),
+ id: parseInt(anomaly.id),
+ payload: JSON.parse((anomaly.attributes.payload as string) || "{}"),
+ };
+}
+
+const state: () => AnomalyState = () => ({});
+
+const getters = {
+ convert:
+ (state: AnomalyState, getters: any, rootState: any, rootGetters: any) =>
+ (anomaly: ResourceObject): Anomaly => {
+ // Pass includedList with [] here, otherwise, it may cause cyclic dependency
+ // e.g. Database calls this to convert its dataSourceList, while data source here
+ // also tries to convert its database.
+ return convert(anomaly, [], rootGetters);
+ },
+};
+
+export default {
+ namespaced: true,
+ state,
+ getters,
+};
diff --git a/frontend/src/store/modules/database.ts b/frontend/src/store/modules/database.ts
index 4e7184e6e2..f7138265d7 100644
--- a/frontend/src/store/modules/database.ts
+++ b/frontend/src/store/modules/database.ts
@@ -1,5 +1,6 @@
import axios from "axios";
import {
+ Anomaly,
Backup,
Database,
DatabaseCreate,
@@ -52,6 +53,15 @@ function convert(
: undefined;
let sourceBackup: Backup | undefined = undefined;
+ const anomalyIdList = database.relationships!.anomaly
+ .data as ResourceIdentifier[];
+ const anomalyList: Anomaly[] = [];
+ for (const item of anomalyIdList) {
+ const anomaly = unknown("ANOMALY") as Anomaly;
+ anomaly.id = parseInt(item.id);
+ anomalyList.push(anomaly);
+ }
+
for (const item of includedList || []) {
if (item.type == "instance" && item.id == instanceId) {
instance = rootGetters["instance/convert"](item, includedList);
@@ -64,25 +74,30 @@ function convert(
}
}
- // Only able to assign an empty data source list, otherwise would cause circular dependency.
- // This should be fine as we shouldn't access data source via dataSource.database.dataSourceList
- const databaseWithoutDataSourceList = {
+ // Only able to assign an empty data source list / anomaly list, otherwise would cause circular dependency.
+ // This should be fine as e.g. we shouldn't access data source via dataSource.database.dataSourceList
+ const databaseWPartial = {
...(database.attributes as Omit<
Database,
- "id" | "instance" | "project" | "dataSourceList" | "sourceBackup"
+ | "id"
+ | "instance"
+ | "project"
+ | "dataSourceList"
+ | "sourceBackup"
+ | "anomalyList"
>),
id: parseInt(database.id),
instance,
project,
dataSourceList: [],
sourceBackup,
+ anomalyList: [],
};
for (const item of includedList || []) {
if (
item.type == "data-source" &&
- (item.relationships!.database.data as ResourceIdentifier).id ==
- database.id
+ item.attributes.databaseId == database.id
) {
const i = dataSourceList.findIndex(
(dataSource: DataSource) => parseInt(item.id) == dataSource.id
@@ -90,14 +105,26 @@ function convert(
if (i != -1) {
dataSourceList[i] = rootGetters["dataSource/convert"](item);
dataSourceList[i].instance = instance;
- dataSourceList[i].database = databaseWithoutDataSourceList;
+ dataSourceList[i].database = databaseWPartial;
+ }
+ }
+
+ if (item.type == "anomaly" && item.attributes.databaseId == database.id) {
+ const i = anomalyList.findIndex(
+ (anomaly: Anomaly) => parseInt(item.id) == anomaly.id
+ );
+ if (i != -1) {
+ anomalyList[i] = rootGetters["anomaly/convert"](item);
+ anomalyList[i].instance = instance;
+ anomalyList[i].database = databaseWPartial;
}
}
}
return {
+ ...(databaseWPartial as Omit<Database, "dataSourceList" | "anomalyList">),
dataSourceList,
- ...(databaseWithoutDataSourceList as Omit<Database, "dataSourceList">),
+ anomalyList,
};
}
diff --git a/frontend/src/types/anomaly.ts b/frontend/src/types/anomaly.ts
new file mode 100644
index 0000000000..77cf7a176d
--- /dev/null
+++ b/frontend/src/types/anomaly.ts
@@ -0,0 +1,41 @@
+import {
+ AnomalyId,
+ BackupPlanPolicySchedule,
+ Database,
+ DatabaseId,
+ EnvironmentId,
+ Instance,
+ InstanceId,
+ Principal,
+} from ".";
+
+export type AnomalyType =
+ | "bb.anomaly.backup.policy-violation"
+ | "bb.anomaly.backup.missing";
+
+export type AnomalyBackupPolicyViolationPayload = {
+ environmentId: EnvironmentId;
+ expectedSchedule: BackupPlanPolicySchedule;
+ actualSchedule: BackupPlanPolicySchedule;
+};
+
+export type AnomalyPayload = AnomalyBackupPolicyViolationPayload;
+
+export type Anomaly = {
+ id: AnomalyId;
+
+ // Related fields
+ instanceId: InstanceId;
+ instance: Instance;
+ databaseId: DatabaseId;
+ database: Database;
+
+ // Standard fields
+ creator: Principal;
+ createdTs: number;
+ updater: Principal;
+ updatedTs: number;
+
+ type: AnomalyType;
+ payload: AnomalyPayload;
+};
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index 513b452917..0b248df597 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -1,5 +1,6 @@
import { Policy } from ".";
import { Activity } from "./activity";
+import { Anomaly } from "./anomaly";
import { BackupSetting } from "./backup";
import { Bookmark } from "./bookmark";
import { Database } from "./database";
@@ -115,7 +116,8 @@ export type ResourceType =
| "INBOX"
| "BOOKMARK"
| "VCS"
- | "REPOSITORY";
+ | "REPOSITORY"
+ | "ANOMALY";
export const unknown = (
type: ResourceType
@@ -139,7 +141,8 @@ export const unknown = (
| Inbox
| Bookmark
| VCS
- | Repository => {
+ | Repository
+ | Anomaly => {
// Have to omit creator and updater to avoid recursion.
const UNKNOWN_PRINCIPAL: Principal = {
id: UNKNOWN_ID,
@@ -232,6 +235,7 @@ export const unknown = (
instance: UNKNOWN_INSTANCE,
project: UNKNOWN_PROJECT,
dataSourceList: [],
+ anomalyList: [],
creator: UNKNOWN_PRINCIPAL,
createdTs: 0,
updater: UNKNOWN_PRINCIPAL,
@@ -399,6 +403,24 @@ export const unknown = (
externalId: UNKNOWN_ID.toString(),
};
+ const UNKNOWN_ANOMALY: Anomaly = {
+ id: UNKNOWN_ID,
+ creator: UNKNOWN_PRINCIPAL,
+ createdTs: 0,
+ updater: UNKNOWN_PRINCIPAL,
+ updatedTs: 0,
+ instanceId: UNKNOWN_ID,
+ instance: UNKNOWN_INSTANCE,
+ databaseId: UNKNOWN_ID,
+ database: UNKNOWN_DATABASE,
+ type: "bb.anomaly.backup.policy-violation",
+ payload: {
+ environmentId: UNKNOWN_ID,
+ expectedSchedule: "DAILY",
+ actualSchedule: "UNSET",
+ },
+ };
+
switch (type) {
case "PRINCIPAL":
return UNKNOWN_PRINCIPAL;
@@ -440,6 +462,8 @@ export const unknown = (
return UNKNOWN_VCS;
case "REPOSITORY":
return UNKONWN_REPOSITORY;
+ case "ANOMALY":
+ return UNKNOWN_ANOMALY;
}
};
@@ -466,7 +490,8 @@ export const empty = (
| Inbox
| Bookmark
| VCS
- | Repository => {
+ | Repository
+ | Anomaly => {
// Have to omit creator and updater to avoid recursion.
const EMPTY_PRINCIPAL: Principal = {
id: EMPTY_ID,
@@ -557,6 +582,7 @@ export const empty = (
instance: EMPTY_INSTANCE,
project: EMPTY_PROJECT,
dataSourceList: [],
+ anomalyList: [],
creator: EMPTY_PRINCIPAL,
createdTs: 0,
updater: EMPTY_PRINCIPAL,
@@ -724,6 +750,24 @@ export const empty = (
externalId: EMPTY_ID.toString(),
};
+ const EMPTY_ANOMALY: Anomaly = {
+ id: EMPTY_ID,
+ creator: EMPTY_PRINCIPAL,
+ createdTs: 0,
+ updater: EMPTY_PRINCIPAL,
+ updatedTs: 0,
+ instanceId: EMPTY_ID,
+ instance: EMPTY_INSTANCE,
+ databaseId: EMPTY_ID,
+ database: EMPTY_DATABASE,
+ type: "bb.anomaly.backup.policy-violation",
+ payload: {
+ environmentId: EMPTY_ID,
+ expectedSchedule: "DAILY",
+ actualSchedule: "UNSET",
+ },
+ };
+
switch (type) {
case "PRINCIPAL":
return EMPTY_PRINCIPAL;
@@ -765,5 +809,7 @@ export const empty = (
return EMPTY_VCS;
case "REPOSITORY":
return EMPTY_REPOSITORY;
+ case "ANOMALY":
+ return EMPTY_ANOMALY;
}
};
diff --git a/frontend/src/types/database.ts b/frontend/src/types/database.ts
index 3a70cb8b14..6aff1c6ae8 100644
--- a/frontend/src/types/database.ts
+++ b/frontend/src/types/database.ts
@@ -2,6 +2,7 @@
// in the "database" object.
// Physically, a database belongs to an instance. Logically, it belongs to a project.
+import { Anomaly } from ".";
import { Backup } from "./backup";
import { DataSource } from "./dataSource";
import { DatabaseId, InstanceId, IssueId, ProjectId } from "./id";
@@ -21,6 +22,7 @@ export type Database = {
project: Project;
dataSourceList: DataSource[];
sourceBackup?: Backup;
+ anomalyList: Anomaly[];
// Standard fields
creator: Principal;
diff --git a/frontend/src/types/id.ts b/frontend/src/types/id.ts
index eed98c15fb..aa74f7b8bc 100644
--- a/frontend/src/types/id.ts
+++ b/frontend/src/types/id.ts
@@ -61,6 +61,8 @@ export type BackupId = IdType;
export type BackupSettingId = IdType;
+export type AnomalyId = IdType;
+
export type CommandId = IdType;
export type CommandRegisterId = IdType;
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index 21a27f459b..ba1a302282 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -1,5 +1,6 @@
export * from "./activity";
export * from "./actuator";
+export * from "./anomaly";
export * from "./auth";
export * from "./backup";
export * from "./bookmark";
diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.ts
index 79cffb85b3..8eb4f23392 100644
--- a/frontend/src/types/store.ts
+++ b/frontend/src/types/store.ts
@@ -147,6 +147,8 @@ export interface RepositoryState {
repositoryByProjectId: Map<ProjectId, Repository>;
}
+export interface AnomalyState {}
+
export interface NotificationState {
notificationByModule: Map<string, Notification[]>;
}