diff --git a/src/hooks/useExpressionsProcessor.ts b/src/hooks/useExpressionsProcessor.ts index debc048e..de30f249 100644 --- a/src/hooks/useExpressionsProcessor.ts +++ b/src/hooks/useExpressionsProcessor.ts @@ -199,58 +199,64 @@ export async function useExpressionsQueryPodsMetrics( const metricConfigArr: MetricConfigOpt[] = []; const metricTypesArr: string[] = []; const data = pods.map((d: any, idx: number) => { - config.expressions.map((exp: string, index: number) => { + for (let index = 0; index < config.expressions.length; index++) { const c: any = (config.metricConfig && config.metricConfig[index]) || {}; const k = "expression" + idx + index; const results = (resp.data[k] && resp.data[k].results) || []; - if (config.typesOfMQE[index] === ExpressionResultType.SINGLE_VALUE) { - const name = results[0].metric.name || ""; - d[name] = results[0].values[0].value; - if (idx === 0) { - names.push(name); - metricConfigArr.push(c); - metricTypesArr.push(config.typesOfMQE[index]); - } - } - if (config.typesOfMQE[index] === ExpressionResultType.TIME_SERIES_VALUES) { - if (results.length > 1) { - const labels = (c.label || "").split(",").map((item: string) => item.replace(/^\s*|\s*$/g, "")); - const labelsIdx = (c.labelsIndex || "").split(",").map((item: string) => item.replace(/^\s*|\s*$/g, "")); - for (let i = 0; i < results.length; i++) { - let name = results[i].metric.name || ""; - const values = results[i].values.map((d: { value: unknown }) => d.value); - const indexNum = labelsIdx.findIndex((d: string) => d === results[i].metric.labels[0].value); - if (labels[indexNum] && indexNum > -1) { - name = labels[indexNum]; - } - if (!d[name]) { - d[name] = {}; - } - if ([Calculations.Average, Calculations.ApdexAvg, Calculations.PercentageAvg].includes(c.calculation)) { - d[name]["avg"] = calculateExp(results[i].values, c); - } - d[name]["values"] = values; - if (idx === 0) { - names.push(name); - metricConfigArr.push({ ...c, index: i }); - metricTypesArr.push(config.typesOfMQE[index]); - } + if (results.length > 1) { + const labels = (c.label || "").split(",").map((item: string) => item.replace(/^\s*|\s*$/g, "")); + const labelsIdx = (c.labelsIndex || "").split(",").map((item: string) => item.replace(/^\s*|\s*$/g, "")); + for (let i = 0; i < results.length; i++) { + let name = results[i].metric.labels[0].value || ""; + const values = results[i].values.map((d: { value: unknown }) => d.value); + const num = labelsIdx.findIndex((d: string) => d === results[i].metric.labels[0].value); + + if (labels[num]) { + name = labels[num]; } - return; + if (!d[name]) { + d[name] = {}; + } + if (config.typesOfMQE[index] === ExpressionResultType.SINGLE_VALUE) { + d[name]["avg"] = results[i].values[0].value; + } else { + d[name]["values"] = values; + } + + const j = names.findIndex((d: string) => d === name); + + if (j < 0) { + names.push(name); + metricConfigArr.push({ ...c, index: i }); + metricTypesArr.push(config.typesOfMQE[index]); + } else { + metricConfigArr[j] = { ...metricConfigArr[j], ...c }; + } + } + } else { + if (!results[0]) { + return d; } const name = results[0].metric.name || ""; - d[name] = {}; - if ([Calculations.Average, Calculations.ApdexAvg, Calculations.PercentageAvg].includes(c.calculation)) { - d[name]["avg"] = calculateExp(results[0].values, c); + if (!d[name]) { + d[name] = {}; } - d[name]["values"] = results[0].values.map((d: { value: number }) => d.value); - if (idx === 0) { + if (config.typesOfMQE[index] === ExpressionResultType.SINGLE_VALUE) { + d[name]["avg"] = [results[0].values[0].value]; + } + if (config.typesOfMQE[index] === ExpressionResultType.TIME_SERIES_VALUES) { + d[name]["values"] = results[0].values.map((d: { value: number }) => d.value); + } + const j = names.findIndex((d: string) => d === name); + if (j < 0) { names.push(name); metricConfigArr.push(c); metricTypesArr.push(config.typesOfMQE[index]); + } else { + metricConfigArr[j] = { ...metricConfigArr[j], ...c }; } } - }); + } return d; }); diff --git a/src/hooks/useListConfig.ts b/src/hooks/useListConfig.ts index e8b13f6b..004cd594 100644 --- a/src/hooks/useListConfig.ts +++ b/src/hooks/useListConfig.ts @@ -15,24 +15,25 @@ * limitations under the License. */ import { MetricQueryTypes, Calculations } from "./data"; -import { ExpressionResultType } from "@/views/dashboard/data"; +import { MetricModes } from "@/views/dashboard/data"; export function useListConfig(config: Indexable, index: string) { + if (config.metricModes === MetricModes.Expression) { + return { + isLinear: false, + isAvg: true, + }; + } const i = Number(index); const types = [Calculations.Average, Calculations.ApdexAvg, Calculations.PercentageAvg]; const calculation = config.metricConfig && config.metricConfig[i] && config.metricConfig[i].calculation; const isLinear = - [ - MetricQueryTypes.ReadMetricsValues, - MetricQueryTypes.ReadLabeledMetricsValues, - ExpressionResultType.TIME_SERIES_VALUES, - ].includes(config.metricTypes[i]) && !types.includes(calculation); + [MetricQueryTypes.ReadMetricsValues, MetricQueryTypes.ReadLabeledMetricsValues].includes(config.metricTypes[i]) && + !types.includes(calculation); const isAvg = - [ - MetricQueryTypes.ReadMetricsValues, - MetricQueryTypes.ReadLabeledMetricsValues, - ExpressionResultType.TIME_SERIES_VALUES, - ].includes(config.metricTypes[i]) && types.includes(calculation); + [MetricQueryTypes.ReadMetricsValues, MetricQueryTypes.ReadLabeledMetricsValues].includes(config.metricTypes[i]) && + types.includes(calculation); + return { isLinear, isAvg, diff --git a/src/views/dashboard/configuration/widget/metric/Index.vue b/src/views/dashboard/configuration/widget/metric/Index.vue index 16193a7f..1bba354c 100644 --- a/src/views/dashboard/configuration/widget/metric/Index.vue +++ b/src/views/dashboard/configuration/widget/metric/Index.vue @@ -35,13 +35,6 @@ limitations under the License. --> @change="changeMetricMode" />
-
{{ metric }}
@@ -505,7 +498,8 @@ limitations under the License. --> queryMetrics(); } async function changeExpression(event: any, index: number) { - const params = event.target.textContent; + const params = (event.target.textContent || "").replace(/\s+/g, ""); + if (params) { const resp = await dashboardStore.getTypeOfMQE(params); states.metrics[index] = params; diff --git a/src/views/dashboard/configuration/widget/metric/Standard.vue b/src/views/dashboard/configuration/widget/metric/Standard.vue index ab02f3d4..d9bee424 100644 --- a/src/views/dashboard/configuration/widget/metric/Standard.vue +++ b/src/views/dashboard/configuration/widget/metric/Standard.vue @@ -44,7 +44,10 @@ limitations under the License. -->
{{ t("labelsIndex") }} const { t } = useI18n(); const emit = defineEmits(["update"]); const dashboardStore = useDashboardStore(); - const isExpression = ref(dashboardStore.selectedGrid.metricMode === MetricModes.Expression ? true : false); + const isExpression = ref(dashboardStore.selectedGrid.metricMode === MetricModes.Expression); const currentMetric = ref({ ...props.currentMetricConfig, topN: props.currentMetricConfig.topN || 10, @@ -138,10 +141,7 @@ limitations under the License. --> metricTypes.value[props.index], ), ); - const isExec = computed(() => { - const graph = dashboardStore.selectedGrid.graph || {}; - return dashboardStore.selectedGrid.metricMode === MetricModes.General || ListChartTypes.includes(graph.type); - }); + const isExec = computed(() => dashboardStore.selectedGrid.metricMode === MetricModes.General); function updateConfig(index: number, param: { [key: string]: string }) { const key = Object.keys(param)[0]; if (!key) { diff --git a/src/views/dashboard/graphs/EndpointList.vue b/src/views/dashboard/graphs/EndpointList.vue index fe61a09e..77dc5e15 100644 --- a/src/views/dashboard/graphs/EndpointList.vue +++ b/src/views/dashboard/graphs/EndpointList.vue @@ -41,6 +41,7 @@ limitations under the License. --> metrics: colMetrics, metricConfig, metricTypes, + metricMode, }" v-if="colMetrics.length" /> @@ -102,6 +103,7 @@ limitations under the License. --> const colMetrics = ref([]); const metricConfig = ref(props.config.metricConfig || []); const metricTypes = ref(props.config.metricTypes || []); + const metricMode = ref(props.config.metricMode); if (props.needQuery) { queryEndpoints(); @@ -213,6 +215,7 @@ limitations under the License. --> return; } metricConfig.value = props.config.metricConfig; + metricMode.value = props.config.metricMode; queryEndpointMetrics(endpoints.value); }, ); diff --git a/src/views/dashboard/graphs/InstanceList.vue b/src/views/dashboard/graphs/InstanceList.vue index 8d28e203..07de48a3 100644 --- a/src/views/dashboard/graphs/InstanceList.vue +++ b/src/views/dashboard/graphs/InstanceList.vue @@ -40,6 +40,7 @@ limitations under the License. --> metrics: colMetrics, metricConfig, metricTypes, + metricMode, }" v-if="colMetrics.length" /> @@ -130,6 +131,7 @@ limitations under the License. --> const metricConfig = ref(props.config.metricConfig || []); const metricTypes = ref(props.config.metricTypes || []); const pods = ref([]); // all instances + const metricMode = ref(props.config.metricMode); if (props.needQuery) { queryInstance(); } @@ -264,6 +266,7 @@ limitations under the License. --> return; } metricConfig.value = props.config.metricConfig; + metricMode.value = props.config.metricMode; queryInstanceMetrics(instances.value); }, ); diff --git a/src/views/dashboard/graphs/ServiceList.vue b/src/views/dashboard/graphs/ServiceList.vue index 53f4c684..4be93062 100644 --- a/src/views/dashboard/graphs/ServiceList.vue +++ b/src/views/dashboard/graphs/ServiceList.vue @@ -52,6 +52,7 @@ limitations under the License. --> metrics: colMetrics, metricConfig, metricTypes, + metricMode, }" v-if="colMetrics.length" /> @@ -123,6 +124,7 @@ limitations under the License. --> const sortServices = ref<(Service & { merge: boolean })[]>([]); const metricConfig = ref(props.config.metricConfig || []); const metricTypes = ref(props.config.metricTypes || []); + const metricMode = ref(props.config.metricMode); queryServices(); @@ -309,6 +311,7 @@ limitations under the License. --> return; } metricConfig.value = props.config.metricConfig; + metricMode.value = props.config.metricMode; queryServiceMetrics(services.value); }, ); diff --git a/src/views/dashboard/graphs/components/ColumnGraph.vue b/src/views/dashboard/graphs/components/ColumnGraph.vue index 06a4bef3..43299417 100644 --- a/src/views/dashboard/graphs/components/ColumnGraph.vue +++ b/src/views/dashboard/graphs/components/ColumnGraph.vue @@ -23,7 +23,7 @@ limitations under the License. -->