From 1a576650126a6ca8e93d57b5f149fea873fff886 Mon Sep 17 00:00:00 2001 From: Qiuxia Fan Date: Fri, 21 Jan 2022 14:50:27 +0800 Subject: [PATCH] feat: enhance processor --- src/hooks/useProcessor.ts | 54 ++++++++++++------- src/store/data.ts | 4 +- src/store/modules/dashboard.ts | 4 ++ .../dashboard/configuration/ConfigEdit.vue | 9 ++-- .../dashboard/configuration/MetricOptions.vue | 15 +++--- src/views/dashboard/controls/Widget.vue | 25 ++++----- src/views/dashboard/data.ts | 11 +++- 7 files changed, 69 insertions(+), 53 deletions(-) diff --git a/src/hooks/useProcessor.ts b/src/hooks/useProcessor.ts index 5a325b9c..09f10f56 100644 --- a/src/hooks/useProcessor.ts +++ b/src/hooks/useProcessor.ts @@ -16,6 +16,7 @@ */ import { Duration } from "@/types/app"; import { RespFields } from "./data"; +import { ElMessage } from "element-plus"; export function useQueryProcessor( config: any, @@ -26,26 +27,28 @@ export function useQueryProcessor( if (!(config.metrics && config.metrics.length)) { return; } - const conditions: any = { + const conditions: { [key: string]: unknown } = { duration: durationTime, }; const variables: string[] = [`$duration: Duration!`]; const { currentPod, currentService, currentDestPod, currentDestService } = selectorStore; + const { normal, destNormal, entity } = dashboardStore; const isRelation = [ "ServiceRelation", "ServiceInstanceRelation", "EndpointRelation", - ].includes(dashboardStore.entity); + ].includes(entity); const fragment = config.metrics.map((name: string, index: number) => { const metricTypes = config.metricTypes[index] || ""; + // const labels = config.metricType === 'LABELED_VALUE' ? labelsIndex : undefined; if (["readSampledRecords", "sortMetrics"].includes(metricTypes)) { variables.push(`$condition${index}: TopNCondition!`); conditions[`condition${index}`] = { name, - parentService: currentService, - normal: true, - scope: dashboardStore.entity, + parentService: entity === "All" ? null : currentService, + normal: normal, + scope: entity, topN: Number(config.standard.maxItemNum || 10), order: config.standard.sortOrder || "DES", }; @@ -54,25 +57,19 @@ export function useQueryProcessor( conditions[`condition${index}`] = { name, entity: { - scope: dashboardStore.entity, - serviceName: currentService, + scope: entity, + serviceName: entity === "All" ? undefined : currentService, normal: true, - serviceInstanceName: dashboardStore.entity.includes("ServiceInstance") + serviceInstanceName: entity.includes("ServiceInstance") ? currentPod : undefined, - endpointName: dashboardStore.entity.includes("Endpoint") - ? currentPod - : undefined, - destNormal: true, + endpointName: entity.includes("Endpoint") ? currentPod : undefined, + destNormal: entity === "All" ? undefined : destNormal, destServiceName: isRelation ? currentDestService : undefined, destServiceInstanceName: - dashboardStore.entity === "ServiceInstanceRelation" - ? currentDestPod - : undefined, + entity === "ServiceInstanceRelation" ? currentDestPod : undefined, destEndpointName: - dashboardStore.entity === "EndpointRelation" - ? currentDestPod - : undefined, + entity === "EndpointRelation" ? currentDestPod : undefined, }, }; } @@ -85,5 +82,22 @@ export function useQueryProcessor( conditions, }; } -// export function useSourceProcessor() { -// } +export function useSourceProcessor( + resp: { errors: string; data: { [key: string]: any } }, + config: { metrics: string[] } +) { + const source: { [key: string]: unknown } = {}; + if (resp.errors) { + ElMessage.error(resp.errors); + return {}; + } + const keys = Object.keys(resp.data); + keys.forEach((key: string, index) => { + const m = config.metrics[index]; + source[m] = resp.data[key].values.values.map( + (d: { value: number }) => d.value + ); + }); + + return source; +} diff --git a/src/store/data.ts b/src/store/data.ts index 3a0a63a0..62fcee64 100644 --- a/src/store/data.ts +++ b/src/store/data.ts @@ -26,8 +26,8 @@ export const NewControl = { }, graph: {}, standard: {}, - metrics: [], - metricTypes: [], + metrics: [""], + metricTypes: [""], }; export const ConfigData: any = { x: 0, diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index 732bfa33..fc1f1c6d 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -34,6 +34,8 @@ interface DashboardState { activedGridItem: string; durationTime: Duration; selectorStore: any; + normal: boolean; + destNormal: boolean; } export const dashboardStore = defineStore({ @@ -47,6 +49,8 @@ export const dashboardStore = defineStore({ activedGridItem: "", durationTime: useAppStoreWithOut().durationTime, selectorStore: useSelectorStore(), + normal: true, + destNormal: true, }), actions: { setLayout(data: LayoutConfig[]) { diff --git a/src/views/dashboard/configuration/ConfigEdit.vue b/src/views/dashboard/configuration/ConfigEdit.vue index ac7fc9e3..4845d9da 100644 --- a/src/views/dashboard/configuration/ConfigEdit.vue +++ b/src/views/dashboard/configuration/ConfigEdit.vue @@ -91,7 +91,6 @@ limitations under the License. -->