From 0de66abb3b57186ce896d238dfcdb2193be7b94a Mon Sep 17 00:00:00 2001 From: Fine Date: Sat, 3 Jun 2023 10:47:14 +0800 Subject: [PATCH] feat: add expressions for instance list --- src/views/dashboard/graphs/InstanceList.vue | 35 ++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/views/dashboard/graphs/InstanceList.vue b/src/views/dashboard/graphs/InstanceList.vue index 0be09631..acbae744 100644 --- a/src/views/dashboard/graphs/InstanceList.vue +++ b/src/views/dashboard/graphs/InstanceList.vue @@ -87,6 +87,7 @@ limitations under the License. --> import type { InstanceListConfig } from "@/types/dashboard"; import type { Instance } from "@/types/selector"; import { useQueryPodsMetrics, usePodsSource } from "@/hooks/useMetricsProcessor"; + import { useExpressionsQueryPodsMetrics } from "@/hooks/useExpressionsProcessor"; import { EntityType } from "../data"; import router from "@/router"; import getDashboard from "@/hooks/useDashboardsSession"; @@ -102,6 +103,9 @@ limitations under the License. --> metrics: string[]; metricTypes: string[]; isEdit: boolean; + metricMode: string; + expressions: string[]; + typesOfMQE: string[]; } & { metricConfig: MetricConfigOpt[] } >, default: () => ({ @@ -150,6 +154,10 @@ limitations under the License. --> if (!currentInstances.length) { return; } + if (props.config.metricMode === "Expression") { + queryInstanceExpressions(currentInstances); + return; + } const metrics = props.config.metrics || []; const types = props.config.metricTypes || []; @@ -174,6 +182,26 @@ limitations under the License. --> instances.value = currentInstances; } + async function queryInstanceExpressions(currentInstances: Instance[]) { + const expressions = props.config.expressions || []; + const typesOfMQE = props.config.typesOfMQE || []; + + if (expressions.length && expressions[0] && typesOfMQE.length && typesOfMQE[0]) { + const params = await useExpressionsQueryPodsMetrics( + currentInstances, + { ...props.config, metricConfig: metricConfig.value || [], typesOfMQE, expressions }, + EntityType[3].value, + ); + instances.value = params.data; + colMetrics.value = params.names; + metricTypes.value = params.metricTypesArr; + metricConfig.value = params.metricConfigArr; + + return; + } + instances.value = currentInstances; + } + function clickInstance(scope: any) { const { dashboard } = getDashboard({ name: props.config.dashboardName, @@ -207,7 +235,12 @@ limitations under the License. --> } watch( - () => [...(props.config.metricTypes || []), ...(props.config.metrics || []), ...(props.config.metricConfig || [])], + () => [ + ...(props.config.metricTypes || []), + ...(props.config.metrics || []), + ...(props.config.metricConfig || []), + ...(props.config.expressions || []), + ], (data, old) => { if (JSON.stringify(data) === JSON.stringify(old)) { return;