From 8f919b458377ac82410916ffbf06edd5c7873fb7 Mon Sep 17 00:00:00 2001 From: Fine Date: Fri, 2 Jun 2023 12:21:00 +0800 Subject: [PATCH] refactor: remove scope in metric query --- src/hooks/useMetricsProcessor.ts | 27 ------------------- src/views/dashboard/Widget.vue | 7 ++--- .../configuration/widget/metric/Index.vue | 9 +++---- src/views/dashboard/controls/Widget.vue | 7 ++--- 4 files changed, 7 insertions(+), 43 deletions(-) diff --git a/src/hooks/useMetricsProcessor.ts b/src/hooks/useMetricsProcessor.ts index 3f8e7692..305171b0 100644 --- a/src/hooks/useMetricsProcessor.ts +++ b/src/hooks/useMetricsProcessor.ts @@ -57,13 +57,11 @@ export function useQueryProcessor(config: Indexable) { name, parentService: ["All"].includes(dashboardStore.entity) ? null : selectorStore.currentService.value, normal: selectorStore.currentService ? selectorStore.currentService.normal : true, - scope: config.catalog, topN: Number(c.topN) || 10, order: c.sortOrder || "DES", }; } else { const entity = { - scope: config.catalog, serviceName: dashboardStore.entity === "All" ? undefined : selectorStore.currentService.value, normal: dashboardStore.entity === "All" ? undefined : selectorStore.currentService.normal, serviceInstanceName: ["ServiceInstance", "ServiceInstanceRelation", "ProcessRelation"].includes( @@ -99,7 +97,6 @@ export function useQueryProcessor(config: Indexable) { order: c.sortOrder || "DES", }; } else { - entity.scope = dashboardStore.entity; if (metricType === MetricQueryTypes.ReadLabeledMetricsValues) { const labels = (c.labelsIndex || "").split(",").map((item: string) => item.replace(/^\s*|\s*$/g, "")); variables.push(`$labels${index}: [String!]!`); @@ -233,7 +230,6 @@ export function useQueryPodsMetrics( const currentService = selectorStore.currentService || {}; const fragmentList = pods.map((d: (Instance | Endpoint | Service) & Indexable, index: number) => { const param = { - scope, serviceName: scope === "Service" ? d.label : currentService.label, serviceInstanceName: scope === "ServiceInstance" ? d.label : undefined, endpointName: scope === "Endpoint" ? d.label : undefined, @@ -440,26 +436,3 @@ export function aggregation(val: number, config: { calculation?: string }): numb return data; } - -export async function useGetMetricEntity(metric: string, metricType: string) { - if (!metric || !metricType) { - return; - } - let catalog = ""; - const dashboardStore = useDashboardStore(); - if ( - ([MetricQueryTypes.ReadSampledRecords, MetricQueryTypes.SortMetrics, MetricQueryTypes.ReadRecords] as any).includes( - metricType, - ) - ) { - const res = await dashboardStore.fetchMetricList(metric); - if (res.errors) { - ElMessage.error(res.errors); - return; - } - const c: string = res.data.metrics[0].catalog; - catalog = (MetricCatalog as Indexable)[c]; - } - - return catalog; -} diff --git a/src/views/dashboard/Widget.vue b/src/views/dashboard/Widget.vue index e3f480bb..7c9216b4 100644 --- a/src/views/dashboard/Widget.vue +++ b/src/views/dashboard/Widget.vue @@ -51,7 +51,7 @@ limitations under the License. --> import { useRoute } from "vue-router"; import { useSelectorStore } from "@/store/modules/selectors"; import { useDashboardStore } from "@/store/modules/dashboard"; - import { useQueryProcessor, useSourceProcessor, useGetMetricEntity } from "@/hooks/useMetricsProcessor"; + import { useQueryProcessor, useSourceProcessor } from "@/hooks/useMetricsProcessor"; import graphs from "./graphs"; import { EntityType } from "./data"; import timeFormat from "@/utils/timeFormat"; @@ -122,10 +122,7 @@ limitations under the License. --> } } async function queryMetrics() { - const metricTypes = config.value.metricTypes || []; - const metrics = config.value.metrics || []; - const catalog = await useGetMetricEntity(metrics[0], metricTypes[0]); - const params = await useQueryProcessor({ ...config.value, catalog }); + const params = await useQueryProcessor({ ...config.value }); if (!params) { source.value = {}; return; diff --git a/src/views/dashboard/configuration/widget/metric/Index.vue b/src/views/dashboard/configuration/widget/metric/Index.vue index f57c0bc4..ac788a81 100644 --- a/src/views/dashboard/configuration/widget/metric/Index.vue +++ b/src/views/dashboard/configuration/widget/metric/Index.vue @@ -108,12 +108,10 @@ limitations under the License. --> ChartTypes, PodsChartTypes, MetricsType, - ProtocolTypes, - ExpressionResultType, } from "../../../data"; import { ElMessage } from "element-plus"; import Icon from "@/components/Icon.vue"; - import { useQueryProcessor, useSourceProcessor, useGetMetricEntity } from "@/hooks/useMetricsProcessor"; + import { useQueryProcessor, useSourceProcessor } from "@/hooks/useMetricsProcessor"; import { useExpressionsQueryProcessor, useExpressionsSourceProcessor } from "@/hooks/useExpressionsProcessor"; import { useI18n } from "vue-i18n"; import type { DashboardItem, MetricConfigOpt } from "@/types/dashboard"; @@ -185,7 +183,7 @@ limitations under the License. --> } arr = json.data.metrics; } - states.metricList = (arr || []).filter((d: { catalog: string; type: string }) => { + states.metricList = (arr || []).filter((d: { type: string }) => { if (states.isList) { if (d.type === MetricsType.REGULAR_VALUE || d.type === MetricsType.LABELED_VALUE) { return d; @@ -335,8 +333,7 @@ limitations under the License. --> if (!(metrics && metrics[0] && metricTypes && metricTypes[0])) { return; } - const catalog = await useGetMetricEntity(metrics[0], metricTypes[0]); - const params = useQueryProcessor({ ...states, metricConfig, catalog }); + const params = useQueryProcessor({ ...states, metricConfig }); if (!params) { emit("update", {}); return; diff --git a/src/views/dashboard/controls/Widget.vue b/src/views/dashboard/controls/Widget.vue index d52ebc96..52f1101e 100644 --- a/src/views/dashboard/controls/Widget.vue +++ b/src/views/dashboard/controls/Widget.vue @@ -76,7 +76,7 @@ limitations under the License. --> import { useSelectorStore } from "@/store/modules/selectors"; import graphs from "../graphs"; import { useI18n } from "vue-i18n"; - import { useQueryProcessor, useSourceProcessor, useGetMetricEntity } from "@/hooks/useMetricsProcessor"; + import { useQueryProcessor, useSourceProcessor } from "@/hooks/useMetricsProcessor"; import { EntityType, ListChartTypes } from "../data"; import type { EventParams } from "@/types/dashboard"; import getDashboard from "@/hooks/useDashboardsSession"; @@ -113,10 +113,7 @@ limitations under the License. --> } async function queryMetrics() { - const metricTypes: string[] = props.data.metricTypes || []; - const metrics = props.data.metrics || []; - const catalog = await useGetMetricEntity(metrics[0], metricTypes[0]); - const params = await useQueryProcessor({ ...props.data, catalog }); + const params = await useQueryProcessor({ ...props.data }); if (!params) { state.source = {};