From 9556ca2ce93e6cdbed7e3cb501aea2278aff355b Mon Sep 17 00:00:00 2001 From: Qiuxia Fan Date: Sun, 27 Mar 2022 14:16:00 +0800 Subject: [PATCH] update topn metrics --- src/hooks/useProcessor.ts | 27 ++++++++++++++++++- .../configuration/widget/metric/Index.vue | 11 +++++--- src/views/dashboard/controls/Widget.vue | 10 +++++-- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/hooks/useProcessor.ts b/src/hooks/useProcessor.ts index f91f4515..e977bdde 100644 --- a/src/hooks/useProcessor.ts +++ b/src/hooks/useProcessor.ts @@ -22,6 +22,7 @@ import { useSelectorStore } from "@/store/modules/selectors"; import { useAppStoreWithOut } from "@/store/modules/app"; import { Instance, Endpoint, Service } from "@/types/selector"; import { MetricConfigOpt } from "@/types/dashboard"; +import { MetricCatalog } from "@/views/dashboard/data"; export function useQueryProcessor(config: any) { if (!(config.metrics && config.metrics[0])) { @@ -62,7 +63,7 @@ export function useQueryProcessor(config: any) { ? null : selectorStore.currentService.value, normal: selectorStore.currentService.normal, - scope: dashboardStore.entity, + scope: config.catalog || dashboardStore.entity, topN: 10, order: c.sortOrder || "DES", }; @@ -340,3 +341,27 @@ export function aggregation(val: number, config: any): number | string { return data; } + +export async function useGetMetricEntity(metric: string, metricType: any) { + if (!metric || !metricType) { + return; + } + let catalog = ""; + const dashboardStore = useDashboardStore(); + if ( + [ + MetricQueryTypes.ReadSampledRecords, + MetricQueryTypes.SortMetrics, + ].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 any)[c]; + } + + return catalog; +} diff --git a/src/views/dashboard/configuration/widget/metric/Index.vue b/src/views/dashboard/configuration/widget/metric/Index.vue index e1182702..c0d9f5e7 100644 --- a/src/views/dashboard/configuration/widget/metric/Index.vue +++ b/src/views/dashboard/configuration/widget/metric/Index.vue @@ -111,7 +111,11 @@ import { } from "../../../data"; import { ElMessage } from "element-plus"; import Icon from "@/components/Icon.vue"; -import { useQueryProcessor, useSourceProcessor } from "@/hooks/useProcessor"; +import { + useQueryProcessor, + useSourceProcessor, + useGetMetricEntity, +} from "@/hooks/useProcessor"; import { useI18n } from "vue-i18n"; import { DashboardItem, MetricConfigOpt } from "@/types/dashboard"; import Standard from "./Standard.vue"; @@ -343,8 +347,9 @@ async function queryMetrics() { if (states.isList) { return; } - const { metricConfig } = dashboardStore.selectedGrid; - const params = useQueryProcessor({ ...states, metricConfig }); + const { metricConfig, metricTypes, metrics } = dashboardStore.selectedGrid; + const catalog = await useGetMetricEntity(metrics[0], metricTypes[0]); + const params = useQueryProcessor({ ...states, metricConfig, catalog }); if (!params) { emit("update", {}); return; diff --git a/src/views/dashboard/controls/Widget.vue b/src/views/dashboard/controls/Widget.vue index 2d71bf22..57e8f3b5 100644 --- a/src/views/dashboard/controls/Widget.vue +++ b/src/views/dashboard/controls/Widget.vue @@ -81,7 +81,11 @@ import { useAppStoreWithOut } from "@/store/modules/app"; import { useSelectorStore } from "@/store/modules/selectors"; import graphs from "../graphs"; import { useI18n } from "vue-i18n"; -import { useQueryProcessor, useSourceProcessor } from "@/hooks/useProcessor"; +import { + useQueryProcessor, + useSourceProcessor, + useGetMetricEntity, +} from "@/hooks/useProcessor"; import { EntityType, ListChartTypes } from "../data"; const props = { @@ -113,7 +117,9 @@ export default defineComponent({ } async function queryMetrics() { - const params = await useQueryProcessor(props.data); + const { metricTypes, metrics } = props.data; + const catalog = await useGetMetricEntity(metrics[0], metricTypes[0]); + const params = await useQueryProcessor({ ...props.data, catalog }); if (!params) { state.source = {};