From 604ec266c28b0c180c6e57c1eb5ece5c5ea2c737 Mon Sep 17 00:00:00 2001 From: Qiuxia Fan Date: Mon, 21 Mar 2022 23:09:55 +0800 Subject: [PATCH] save topology templates --- src/store/modules/topology.ts | 33 ++++++++ .../related/topology/components/Graph.vue | 9 ++- .../topology/components/PodTopology.vue | 9 ++- .../related/topology/components/Sankey.vue | 1 - .../related/topology/components/Settings.vue | 79 +++++++++---------- 5 files changed, 85 insertions(+), 46 deletions(-) diff --git a/src/store/modules/topology.ts b/src/store/modules/topology.ts index 9de0316e..69ced307 100644 --- a/src/store/modules/topology.ts +++ b/src/store/modules/topology.ts @@ -23,6 +23,8 @@ import { useSelectorStore } from "@/store/modules/selectors"; import { useAppStoreWithOut } from "@/store/modules/app"; import { AxiosResponse } from "axios"; import query from "@/graphql/fetch"; +import { useQueryTopologyMetrics } from "@/hooks/useProcessor"; +import { ElMessage } from "element-plus"; interface MetricVal { [key: string]: { values: { id: string; value: unknown }[] }; @@ -400,6 +402,37 @@ export const topologyStore = defineStore({ this.setNodeMetrics(res.data.data); return res.data; }, + async getLinkClientMetrics(linkClientMetrics: string[]) { + const idsC = this.calls + .filter((i: Call) => i.detectPoints.includes("CLIENT")) + .map((b: Call) => b.id); + const param = await useQueryTopologyMetrics(linkClientMetrics, idsC); + const res = await this.getCallClientMetrics(param); + + if (res.errors) { + ElMessage.error(res.errors); + } + }, + async getLinkServerMetrics(linkServerMetrics: string[]) { + const idsS = this.calls + .filter((i: Call) => i.detectPoints.includes("SERVER")) + .map((b: Call) => b.id); + const param = await useQueryTopologyMetrics(linkServerMetrics, idsS); + const res = await this.getCallServerMetrics(param); + + if (res.errors) { + ElMessage.error(res.errors); + } + }, + async queryNodeMetrics(nodeMetrics: string[]) { + const ids = this.nodes.map((d: Node) => d.id); + const param = await useQueryTopologyMetrics(nodeMetrics, ids); + const res = await this.getNodeMetrics(param); + + if (res.errors) { + ElMessage.error(res.errors); + } + }, async getLegendMetrics(param: { queryStr: string; conditions: { [key: string]: unknown }; diff --git a/src/views/dashboard/related/topology/components/Graph.vue b/src/views/dashboard/related/topology/components/Graph.vue index f6765b47..3d95ad55 100644 --- a/src/views/dashboard/related/topology/components/Graph.vue +++ b/src/views/dashboard/related/topology/components/Graph.vue @@ -20,7 +20,7 @@ limitations under the License. --> element-loading-background="rgba(0, 0, 0, 0)" :style="`height: ${height}px`" > -
+
@@ -118,7 +118,7 @@ const anchor = ref(null); const arrow = ref(null); const legend = ref(null); const showSetting = ref(false); -const settings = ref({}); +const settings = ref(props.config); const operationsPos = reactive<{ x: number; y: number }>({ x: NaN, y: NaN }); const items = ref< { id: string; title: string; func: any; dashboard?: string }[] @@ -135,6 +135,9 @@ onMounted(async () => { if (resp && resp.errors) { ElMessage.error(resp.errors); } + topologyStore.getLinkClientMetrics(settings.value.linkClientMetrics); + topologyStore.getLinkServerMetrics(settings.value.linkServerMetrics); + topologyStore.queryNodeMetrics(settings.value.nodeMetrics); const dom = document.querySelector(".topology")?.getBoundingClientRect() || { height: 40, width: 0, @@ -172,6 +175,7 @@ async function init() { event.preventDefault(); topologyStore.setNode(null); topologyStore.setLink(null); + dashboardStore.selectWidget(props.config); }); } function ticked() { @@ -460,6 +464,7 @@ async function getTopology() { } function setConfig() { showSetting.value = !showSetting.value; + dashboardStore.selectWidget(props.config); } function resize() { height.value = document.body.clientHeight; diff --git a/src/views/dashboard/related/topology/components/PodTopology.vue b/src/views/dashboard/related/topology/components/PodTopology.vue index c951eb5f..f61d621e 100644 --- a/src/views/dashboard/related/topology/components/PodTopology.vue +++ b/src/views/dashboard/related/topology/components/PodTopology.vue @@ -43,7 +43,7 @@ limitations under the License. --> > -
+
@@ -109,7 +109,7 @@ const loading = ref(false); const height = ref(100); const width = ref(100); const showSettings = ref(false); -const settings = ref({}); +const settings = ref(props.config); const operationsPos = reactive<{ x: number; y: number }>({ x: NaN, y: NaN }); const depth = ref(props.config.graph.depth || 3); const items = [ @@ -135,6 +135,9 @@ async function loadTopology(id: string) { }; height.value = dom.height - 70; width.value = dom.width - 5; + topologyStore.getLinkClientMetrics(settings.value.linkClientMetrics); + topologyStore.getLinkServerMetrics(settings.value.linkServerMetrics); + topologyStore.queryNodeMetrics(settings.value.nodeMetrics); } function inspect() { @@ -172,6 +175,7 @@ function goDashboard() { function setConfig() { topologyStore.setNode(null); showSettings.value = !showSettings.value; + dashboardStore.selectWidget(props.config); } function updateConfig(config: any) { @@ -236,6 +240,7 @@ function handleClick(event: any) { if (event.target.nodeName === "svg") { topologyStore.setNode(null); topologyStore.setLink(null); + dashboardStore.selectWidget(props.config); } } watch( diff --git a/src/views/dashboard/related/topology/components/Sankey.vue b/src/views/dashboard/related/topology/components/Sankey.vue index 3740a4d7..4aa6a656 100644 --- a/src/views/dashboard/related/topology/components/Sankey.vue +++ b/src/views/dashboard/related/topology/components/Sankey.vue @@ -26,7 +26,6 @@ const emit = defineEmits(["click"]); const topologyStore = useTopologyStore(); const option = computed(() => getOption()); -console.log(topologyStore.nodes); function getOption() { return { tooltip: { diff --git a/src/views/dashboard/related/topology/components/Settings.vue b/src/views/dashboard/related/topology/components/Settings.vue index 5e08b82f..76cd1148 100644 --- a/src/views/dashboard/related/topology/components/Settings.vue +++ b/src/views/dashboard/related/topology/components/Settings.vue @@ -176,6 +176,11 @@ limitations under the License. --> {{ t("setLegend") }}
+
+ + {{ t("apply") }} + +