feat: update list

This commit is contained in:
Fine 2023-06-03 19:29:50 +08:00
parent c19f9000a0
commit db7de72417
8 changed files with 91 additions and 68 deletions

View File

@ -199,58 +199,64 @@ export async function useExpressionsQueryPodsMetrics(
const metricConfigArr: MetricConfigOpt[] = []; const metricConfigArr: MetricConfigOpt[] = [];
const metricTypesArr: string[] = []; const metricTypesArr: string[] = [];
const data = pods.map((d: any, idx: number) => { 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 c: any = (config.metricConfig && config.metricConfig[index]) || {};
const k = "expression" + idx + index; const k = "expression" + idx + index;
const results = (resp.data[k] && resp.data[k].results) || []; 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) { if (results.length > 1) {
const labels = (c.label || "").split(",").map((item: string) => item.replace(/^\s*|\s*$/g, "")); 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, "")); const labelsIdx = (c.labelsIndex || "").split(",").map((item: string) => item.replace(/^\s*|\s*$/g, ""));
for (let i = 0; i < results.length; i++) { for (let i = 0; i < results.length; i++) {
let name = results[i].metric.name || ""; let name = results[i].metric.labels[0].value || "";
const values = results[i].values.map((d: { value: unknown }) => d.value); const values = results[i].values.map((d: { value: unknown }) => d.value);
const indexNum = labelsIdx.findIndex((d: string) => d === results[i].metric.labels[0].value); const num = labelsIdx.findIndex((d: string) => d === results[i].metric.labels[0].value);
if (labels[indexNum] && indexNum > -1) {
name = labels[indexNum]; if (labels[num]) {
name = labels[num];
} }
if (!d[name]) { if (!d[name]) {
d[name] = {}; d[name] = {};
} }
if ([Calculations.Average, Calculations.ApdexAvg, Calculations.PercentageAvg].includes(c.calculation)) { if (config.typesOfMQE[index] === ExpressionResultType.SINGLE_VALUE) {
d[name]["avg"] = calculateExp(results[i].values, c); d[name]["avg"] = results[i].values[0].value;
} } else {
d[name]["values"] = values; d[name]["values"] = values;
if (idx === 0) { }
const j = names.findIndex((d: string) => d === name);
if (j < 0) {
names.push(name); names.push(name);
metricConfigArr.push({ ...c, index: i }); metricConfigArr.push({ ...c, index: i });
metricTypesArr.push(config.typesOfMQE[index]); metricTypesArr.push(config.typesOfMQE[index]);
} else {
metricConfigArr[j] = { ...metricConfigArr[j], ...c };
} }
} }
return; } else {
if (!results[0]) {
return d;
} }
const name = results[0].metric.name || ""; const name = results[0].metric.name || "";
if (!d[name]) {
d[name] = {}; d[name] = {};
if ([Calculations.Average, Calculations.ApdexAvg, Calculations.PercentageAvg].includes(c.calculation)) {
d[name]["avg"] = calculateExp(results[0].values, c);
} }
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); d[name]["values"] = results[0].values.map((d: { value: number }) => d.value);
if (idx === 0) { }
const j = names.findIndex((d: string) => d === name);
if (j < 0) {
names.push(name); names.push(name);
metricConfigArr.push(c); metricConfigArr.push(c);
metricTypesArr.push(config.typesOfMQE[index]); metricTypesArr.push(config.typesOfMQE[index]);
} else {
metricConfigArr[j] = { ...metricConfigArr[j], ...c };
}
} }
} }
});
return d; return d;
}); });

View File

@ -15,24 +15,25 @@
* limitations under the License. * limitations under the License.
*/ */
import { MetricQueryTypes, Calculations } from "./data"; import { MetricQueryTypes, Calculations } from "./data";
import { ExpressionResultType } from "@/views/dashboard/data"; import { MetricModes } from "@/views/dashboard/data";
export function useListConfig(config: Indexable, index: string) { export function useListConfig(config: Indexable, index: string) {
if (config.metricModes === MetricModes.Expression) {
return {
isLinear: false,
isAvg: true,
};
}
const i = Number(index); const i = Number(index);
const types = [Calculations.Average, Calculations.ApdexAvg, Calculations.PercentageAvg]; const types = [Calculations.Average, Calculations.ApdexAvg, Calculations.PercentageAvg];
const calculation = config.metricConfig && config.metricConfig[i] && config.metricConfig[i].calculation; const calculation = config.metricConfig && config.metricConfig[i] && config.metricConfig[i].calculation;
const isLinear = const isLinear =
[ [MetricQueryTypes.ReadMetricsValues, MetricQueryTypes.ReadLabeledMetricsValues].includes(config.metricTypes[i]) &&
MetricQueryTypes.ReadMetricsValues, !types.includes(calculation);
MetricQueryTypes.ReadLabeledMetricsValues,
ExpressionResultType.TIME_SERIES_VALUES,
].includes(config.metricTypes[i]) && !types.includes(calculation);
const isAvg = const isAvg =
[ [MetricQueryTypes.ReadMetricsValues, MetricQueryTypes.ReadLabeledMetricsValues].includes(config.metricTypes[i]) &&
MetricQueryTypes.ReadMetricsValues, types.includes(calculation);
MetricQueryTypes.ReadLabeledMetricsValues,
ExpressionResultType.TIME_SERIES_VALUES,
].includes(config.metricTypes[i]) && types.includes(calculation);
return { return {
isLinear, isLinear,
isAvg, isAvg,

View File

@ -35,13 +35,6 @@ limitations under the License. -->
@change="changeMetricMode" @change="changeMetricMode"
/> />
<div v-for="(metric, index) in states.metrics" :key="index" class="metric-item"> <div v-for="(metric, index) in states.metrics" :key="index" class="metric-item">
<!-- <el-input
v-if="isExpression"
class="selectors"
size="small"
placeholder="Please input a expression"
@change="changeExpression"
/> -->
<div v-if="isExpression" id="expression-param" contenteditable="true" @blur="changeExpression($event, index)"> <div v-if="isExpression" id="expression-param" contenteditable="true" @blur="changeExpression($event, index)">
{{ metric }} {{ metric }}
</div> </div>
@ -505,7 +498,8 @@ limitations under the License. -->
queryMetrics(); queryMetrics();
} }
async function changeExpression(event: any, index: number) { async function changeExpression(event: any, index: number) {
const params = event.target.textContent; const params = (event.target.textContent || "").replace(/\s+/g, "");
if (params) { if (params) {
const resp = await dashboardStore.getTypeOfMQE(params); const resp = await dashboardStore.getTypeOfMQE(params);
states.metrics[index] = params; states.metrics[index] = params;

View File

@ -44,7 +44,10 @@ limitations under the License. -->
</div> </div>
<div <div
class="item mb-10" class="item mb-10"
v-if="[ProtocolTypes.ReadLabeledMetricsValues, ExpressionResultType.TIME_SERIES_VALUES].includes(metricType)" v-if="
[ProtocolTypes.ReadLabeledMetricsValues].includes(metricType) ||
dashboardStore.selectedGrid.metricMode === MetricModes.Expression
"
> >
<span class="label">{{ t("labelsIndex") }}</span> <span class="label">{{ t("labelsIndex") }}</span>
<el-input <el-input
@ -113,7 +116,7 @@ limitations under the License. -->
const { t } = useI18n(); const { t } = useI18n();
const emit = defineEmits(["update"]); const emit = defineEmits(["update"]);
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const isExpression = ref<boolean>(dashboardStore.selectedGrid.metricMode === MetricModes.Expression ? true : false); const isExpression = ref<boolean>(dashboardStore.selectedGrid.metricMode === MetricModes.Expression);
const currentMetric = ref<MetricConfigOpt>({ const currentMetric = ref<MetricConfigOpt>({
...props.currentMetricConfig, ...props.currentMetricConfig,
topN: props.currentMetricConfig.topN || 10, topN: props.currentMetricConfig.topN || 10,
@ -138,10 +141,7 @@ limitations under the License. -->
metricTypes.value[props.index], metricTypes.value[props.index],
), ),
); );
const isExec = computed(() => { const isExec = computed(() => dashboardStore.selectedGrid.metricMode === MetricModes.General);
const graph = dashboardStore.selectedGrid.graph || {};
return dashboardStore.selectedGrid.metricMode === MetricModes.General || ListChartTypes.includes(graph.type);
});
function updateConfig(index: number, param: { [key: string]: string }) { function updateConfig(index: number, param: { [key: string]: string }) {
const key = Object.keys(param)[0]; const key = Object.keys(param)[0];
if (!key) { if (!key) {

View File

@ -41,6 +41,7 @@ limitations under the License. -->
metrics: colMetrics, metrics: colMetrics,
metricConfig, metricConfig,
metricTypes, metricTypes,
metricMode,
}" }"
v-if="colMetrics.length" v-if="colMetrics.length"
/> />
@ -102,6 +103,7 @@ limitations under the License. -->
const colMetrics = ref<string[]>([]); const colMetrics = ref<string[]>([]);
const metricConfig = ref<MetricConfigOpt[]>(props.config.metricConfig || []); const metricConfig = ref<MetricConfigOpt[]>(props.config.metricConfig || []);
const metricTypes = ref<string[]>(props.config.metricTypes || []); const metricTypes = ref<string[]>(props.config.metricTypes || []);
const metricMode = ref<string>(props.config.metricMode);
if (props.needQuery) { if (props.needQuery) {
queryEndpoints(); queryEndpoints();
@ -213,6 +215,7 @@ limitations under the License. -->
return; return;
} }
metricConfig.value = props.config.metricConfig; metricConfig.value = props.config.metricConfig;
metricMode.value = props.config.metricMode;
queryEndpointMetrics(endpoints.value); queryEndpointMetrics(endpoints.value);
}, },
); );

View File

@ -40,6 +40,7 @@ limitations under the License. -->
metrics: colMetrics, metrics: colMetrics,
metricConfig, metricConfig,
metricTypes, metricTypes,
metricMode,
}" }"
v-if="colMetrics.length" v-if="colMetrics.length"
/> />
@ -130,6 +131,7 @@ limitations under the License. -->
const metricConfig = ref<MetricConfigOpt[]>(props.config.metricConfig || []); const metricConfig = ref<MetricConfigOpt[]>(props.config.metricConfig || []);
const metricTypes = ref<string[]>(props.config.metricTypes || []); const metricTypes = ref<string[]>(props.config.metricTypes || []);
const pods = ref<Instance[]>([]); // all instances const pods = ref<Instance[]>([]); // all instances
const metricMode = ref<string>(props.config.metricMode);
if (props.needQuery) { if (props.needQuery) {
queryInstance(); queryInstance();
} }
@ -264,6 +266,7 @@ limitations under the License. -->
return; return;
} }
metricConfig.value = props.config.metricConfig; metricConfig.value = props.config.metricConfig;
metricMode.value = props.config.metricMode;
queryInstanceMetrics(instances.value); queryInstanceMetrics(instances.value);
}, },
); );

View File

@ -52,6 +52,7 @@ limitations under the License. -->
metrics: colMetrics, metrics: colMetrics,
metricConfig, metricConfig,
metricTypes, metricTypes,
metricMode,
}" }"
v-if="colMetrics.length" v-if="colMetrics.length"
/> />
@ -123,6 +124,7 @@ limitations under the License. -->
const sortServices = ref<(Service & { merge: boolean })[]>([]); const sortServices = ref<(Service & { merge: boolean })[]>([]);
const metricConfig = ref<MetricConfigOpt[]>(props.config.metricConfig || []); const metricConfig = ref<MetricConfigOpt[]>(props.config.metricConfig || []);
const metricTypes = ref<string[]>(props.config.metricTypes || []); const metricTypes = ref<string[]>(props.config.metricTypes || []);
const metricMode = ref<string>(props.config.metricMode);
queryServices(); queryServices();
@ -309,6 +311,7 @@ limitations under the License. -->
return; return;
} }
metricConfig.value = props.config.metricConfig; metricConfig.value = props.config.metricConfig;
metricMode.value = props.config.metricMode;
queryServiceMetrics(services.value); queryServiceMetrics(services.value);
}, },
); );

View File

@ -23,7 +23,7 @@ limitations under the License. -->
<template #default="scope"> <template #default="scope">
<div class="chart"> <div class="chart">
<Line <Line
v-if="useListConfig(config, index).isLinear" v-if="useListConfig(config, index).isLinear && config.metricMode !== MetricModes.Expression"
:data="{ :data="{
[metric]: scope.row[metric] && scope.row[metric].values, [metric]: scope.row[metric] && scope.row[metric].values,
}" }"
@ -35,7 +35,10 @@ limitations under the License. -->
showlabels: false, showlabels: false,
}" }"
/> />
<span class="item flex-h" v-else-if="useListConfig(config, index).isAvg"> <span
class="item flex-h"
v-else-if="useListConfig(config, index).isAvg || config.metricMode === MetricModes.Expression"
>
<el-popover placement="left" :width="400" trigger="click"> <el-popover placement="left" :width="400" trigger="click">
<template #reference> <template #reference>
<span class="trend"> <span class="trend">
@ -79,6 +82,7 @@ limitations under the License. -->
import Line from "../Line.vue"; import Line from "../Line.vue";
import Card from "../Card.vue"; import Card from "../Card.vue";
import { MetricQueryTypes } from "@/hooks/data"; import { MetricQueryTypes } from "@/hooks/data";
import { ExpressionResultType, MetricModes } from "@/views/dashboard/data";
/*global defineProps */ /*global defineProps */
const props = defineProps({ const props = defineProps({
@ -89,6 +93,7 @@ limitations under the License. -->
metrics: string[]; metrics: string[];
metricTypes: string[]; metricTypes: string[];
metricConfig: MetricConfigOpt[]; metricConfig: MetricConfigOpt[];
metricMode: string;
}>, }>,
default: () => ({}), default: () => ({}),
}, },
@ -107,7 +112,15 @@ limitations under the License. -->
const i = Number(index); const i = Number(index);
const label = props.config.metricConfig && props.config.metricConfig[i] && props.config.metricConfig[i].label; const label = props.config.metricConfig && props.config.metricConfig[i] && props.config.metricConfig[i].label;
if (label) { if (label) {
if (props.config.metricTypes[i] === MetricQueryTypes.ReadLabeledMetricsValues) { if (
(
[
MetricQueryTypes.ReadLabeledMetricsValues,
ExpressionResultType.TIME_SERIES_VALUES,
ExpressionResultType.SINGLE_VALUE,
] as string[]
).includes(props.config.metricTypes[i])
) {
const name = (label || "").split(",").map((item: string) => item.replace(/^\s*|\s*$/g, ""))[ const name = (label || "").split(",").map((item: string) => item.replace(/^\s*|\s*$/g, ""))[
props.config.metricConfig[i].index || 0 props.config.metricConfig[i].index || 0
]; ];