From 2d5f004ca279c48f48ab3b2f2a42b6cc27a2ce59 Mon Sep 17 00:00:00 2001 From: Fine Date: Mon, 21 Aug 2023 18:34:26 +0800 Subject: [PATCH] feat: add pod topology expression --- src/hooks/useExpressionsProcessor.ts | 42 ++++++++++++++++--- .../topology/components/PodTopology.vue | 14 +++++-- .../related/topology/components/Sankey.vue | 16 +++++-- 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/src/hooks/useExpressionsProcessor.ts b/src/hooks/useExpressionsProcessor.ts index 8b722051..da1f575b 100644 --- a/src/hooks/useExpressionsProcessor.ts +++ b/src/hooks/useExpressionsProcessor.ts @@ -15,7 +15,7 @@ * limitations under the License. */ import { RespFields } from "./data"; -import { ExpressionResultType } from "@/views/dashboard/data"; +import { EntityType, ExpressionResultType } from "@/views/dashboard/data"; import { ElMessage } from "element-plus"; import { useDashboardStore } from "@/store/modules/dashboard"; import { useSelectorStore } from "@/store/modules/selectors"; @@ -23,7 +23,6 @@ import { useAppStoreWithOut } from "@/store/modules/app"; import type { MetricConfigOpt } from "@/types/dashboard"; import type { Instance, Endpoint, Service } from "@/types/selector"; import type { Node, Call } from "@/types/topology"; -import { MetricCatalog } from "@/views/dashboard/data"; export async function useExpressionsQueryProcessor(config: Indexable) { function expressionsGraphqlPods() { @@ -315,8 +314,9 @@ export async function useExpressionsQueryPodsMetrics( return expressionParams; } -export function useQueryTopologyExpressionsProcessor(metrics: string[], instances: any[]) { +export function useQueryTopologyExpressionsProcessor(metrics: string[], instances: (Call | Node)[]) { const appStore = useAppStoreWithOut(); + const dashboardStore = useDashboardStore(); function getExpressionQuery() { const conditions: { [key: string]: unknown } = { @@ -324,11 +324,43 @@ export function useQueryTopologyExpressionsProcessor(metrics: string[], instance }; const variables: string[] = [`$duration: Duration!`]; const fragmentList = instances.map((d: any, index: number) => { + let serviceName; + let destServiceName; + let endpointName; + let serviceInstanceName; + let destServiceInstanceName; + let destEndpointName; + if (d.sourceObj && d.targetObj) { + // instances = Calls + serviceName = d.sourceObj.serviceName || d.sourceObj.name; + destServiceName = d.targetObj.serviceName || d.targetObj.name; + if (EntityType[4].value === dashboardStore.entity) { + serviceInstanceName = d.sourceObj.name; + destServiceInstanceName = d.targetObj.name; + } + if (EntityType[2].value === dashboardStore.entity) { + endpointName = d.sourceObj.name; + destEndpointName = d.targetObj.name; + } + } else { + // instances = Nodes + serviceName = d.serviceName || d.name; + if (EntityType[4].value === dashboardStore.entity) { + serviceInstanceName = d.name; + } + if (EntityType[2].value === dashboardStore.entity) { + endpointName = d.name; + } + } const entity = { - serviceName: d.sourceObj ? d.sourceObj.name : d.name, + serviceName, normal: true, + serviceInstanceName, + endpointName, + destServiceName, destNormal: true, - destServiceName: (d.targetObj && d.targetObj.name) || undefined, + destServiceInstanceName, + destEndpointName, }; variables.push(`$entity${index}: Entity!`); conditions[`entity${index}`] = entity; diff --git a/src/views/dashboard/related/topology/components/PodTopology.vue b/src/views/dashboard/related/topology/components/PodTopology.vue index fb5409da..8db56c0d 100644 --- a/src/views/dashboard/related/topology/components/PodTopology.vue +++ b/src/views/dashboard/related/topology/components/PodTopology.vue @@ -69,7 +69,7 @@ limitations under the License. --> import { useDashboardStore } from "@/store/modules/dashboard"; import { useSelectorStore } from "@/store/modules/selectors"; import { useAppStoreWithOut } from "@/store/modules/app"; - import { EntityType, DepthList } from "../../../data"; + import { EntityType, DepthList, MetricModes } from "../../../data"; import { ElMessage } from "element-plus"; import Sankey from "./Sankey.vue"; import Settings from "./Settings.vue"; @@ -119,9 +119,15 @@ limitations under the License. --> }; 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 || []); + if (settings.value.metricMode === MetricModes.Expression) { + topologyStore.queryNodeExpressions(settings.value.nodeExpressions || []); + topologyStore.getLinkExpressions(settings.value.linkClientExpressions || []); + topologyStore.getLinkExpressions(settings.value.linkServerExpressions || []); + } else { + topologyStore.getLinkClientMetrics(settings.value.linkClientMetrics || []); + topologyStore.getLinkServerMetrics(settings.value.linkServerMetrics || []); + topologyStore.queryNodeMetrics(settings.value.nodeMetrics || []); + } } function resize() { diff --git a/src/views/dashboard/related/topology/components/Sankey.vue b/src/views/dashboard/related/topology/components/Sankey.vue index e749f5b2..156b8302 100644 --- a/src/views/dashboard/related/topology/components/Sankey.vue +++ b/src/views/dashboard/related/topology/components/Sankey.vue @@ -23,6 +23,7 @@ limitations under the License. --> import type { Node, Call } from "@/types/topology"; import type { MetricConfigOpt } from "@/types/dashboard"; import { aggregation } from "@/hooks/useMetricsProcessor"; + import { MetricModes } from "../../../data"; /*global defineEmits, defineProps */ const props = defineProps({ @@ -75,8 +76,14 @@ limitations under the License. --> }; } function linkTooltip(data: Call) { - const clientMetrics: string[] = Object.keys(topologyStore.linkClientMetrics); - const serverMetrics: string[] = Object.keys(topologyStore.linkServerMetrics); + const clientMetrics: string[] = + props.settings.metricMode === MetricModes.Expression + ? props.settings.linkClientExpressions + : props.settings.linkClientMetrics; + const serverMetrics: string[] = + props.settings.metricMode === MetricModes.Expression + ? props.settings.linkServerExpressions + : props.settings.linkServerMetrics; const linkServerMetricConfig: MetricConfigOpt[] = props.settings.linkServerMetricConfig || []; const linkClientMetricConfig: MetricConfigOpt[] = props.settings.linkClientMetricConfig || []; @@ -108,7 +115,10 @@ limitations under the License. --> } function nodeTooltip(data: Node) { - const nodeMetrics: string[] = Object.keys(topologyStore.nodeMetricValue); + const nodeMetrics: string[] = + props.settings.metricMode === MetricModes.Expression + ? props.settings.nodeExpressions + : props.settings.nodeMetrics; const nodeMetricConfig = props.settings.nodeMetricConfig || []; const html = nodeMetrics.map((m, index) => { const metric =