diff --git a/src/hooks/useExpressionsProcessor.ts b/src/hooks/useExpressionsProcessor.ts index ecd74cfc..b4b54598 100644 --- a/src/hooks/useExpressionsProcessor.ts +++ b/src/hooks/useExpressionsProcessor.ts @@ -109,12 +109,12 @@ export async function useDashboardQueryProcessor(configList: Indexable[]) { return { source: {}, tips: [], typesOfMQE: [] }; } const tips: string[] = []; - const source: { [key: string]: unknown } = {}; + const source: Indexable = {}; const keys = Object.keys(resp.data); const typesOfMQE: string[] = []; for (let i = 0; i < config.metrics.length; i++) { - const c: MetricConfigOpt = (config.metricConfig && config.metricConfig[i]) || {}; + const metricConfig: MetricConfigOpt = (config.metricConfig && config.metricConfig[i]) || {}; const obj = resp.data[keys[i]] || {}; const results = obj.results || []; const name = config.metrics[i]; @@ -125,15 +125,15 @@ export async function useDashboardQueryProcessor(configList: Indexable[]) { if (!obj.error) { if ([ExpressionResultType.SINGLE_VALUE, ExpressionResultType.TIME_SERIES_VALUES].includes(type)) { for (const item of results) { - const label = + let label = item.metric && item.metric.labels.map((d: { key: string; value: string }) => `${d.key}=${d.value}`).join(","); const values = item.values.map((d: { value: unknown }) => d.value) || []; if (results.length === 1) { - source[label || c.label || name] = values; - } else { - source[label] = values; + // If the metrics label does not exist, use the configuration label or expression + label = label ? `${metricConfig.label || name}, ${label}` : metricConfig.label || name; } + source[label] = values; } } if (([ExpressionResultType.RECORD_LIST, ExpressionResultType.SORTED_LIST] as string[]).includes(type)) { @@ -148,7 +148,7 @@ export async function useDashboardQueryProcessor(configList: Indexable[]) { const appStore = useAppStoreWithOut(); const variables: string[] = [`$duration: Duration!`]; let fragments = ""; - let conditions: Recordable = { + let conditions: Recordable = { duration: appStore.durationTime, }; for (let i = 0; i < configArr.length; i++) { @@ -465,7 +465,7 @@ export function useQueryTopologyExpressionsProcessor(metrics: string[], instance return { queryStr, conditions }; } function handleExpressionValues(partMetrics: string[], resp: { [key: string]: any }) { - const obj: any = {}; + const obj: Indexable = {}; for (let idx = 0; idx < instances.length; idx++) { for (let index = 0; index < partMetrics.length; index++) { const k = "expression" + idx + index;