fix: remove metrics for unreal nodes (#385)

This commit is contained in:
Fine0830 2024-04-12 13:25:34 +08:00 committed by GitHub
parent 03f321b62a
commit e0bbe99b6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 15 deletions

View File

@ -226,11 +226,12 @@ export const topologyStore = defineStore({
this.nodeMetricValue = m; this.nodeMetricValue = m;
}, },
setLegendValues(expressions: string, data: { [key: string]: any }) { setLegendValues(expressions: string, data: { [key: string]: any }) {
for (let idx = 0; idx < this.nodes.length; idx++) { const nodeArr = this.nodes.filter((d: Node) => d.isReal);
for (let idx = 0; idx < nodeArr.length; idx++) {
for (let index = 0; index < expressions.length; index++) { for (let index = 0; index < expressions.length; index++) {
const k = "expression" + idx + index; const k = "expression" + idx + index;
if (expressions[index]) { if (expressions[index]) {
this.nodes[idx][expressions[index]] = Number(data[k].results[0].values[0].value); nodeArr[idx][expressions[index]] = Number(data[k].results[0].values[0].value);
} }
} }
} }
@ -485,7 +486,7 @@ export const topologyStore = defineStore({
} }
const { getExpressionQuery, handleExpressionValues } = useQueryTopologyExpressionsProcessor( const { getExpressionQuery, handleExpressionValues } = useQueryTopologyExpressionsProcessor(
expressions, expressions,
this.nodes, this.nodes.filter((d: Node) => d.isReal),
); );
const param = getExpressionQuery(); const param = getExpressionQuery();
const res = await this.getNodeExpressionValue(param); const res = await this.getNodeExpressionValue(param);

View File

@ -163,6 +163,7 @@ limitations under the License. -->
import type { Option } from "@/types/app"; import type { Option } from "@/types/app";
import { useQueryTopologyExpressionsProcessor } from "@/hooks/useExpressionsProcessor"; import { useQueryTopologyExpressionsProcessor } from "@/hooks/useExpressionsProcessor";
import type { DashboardItem, MetricConfigOpt } from "@/types/dashboard"; import type { DashboardItem, MetricConfigOpt } from "@/types/dashboard";
import type { Node } from "@/types/topology";
import Metrics from "./Metrics.vue"; import Metrics from "./Metrics.vue";
/*global defineEmits */ /*global defineEmits */
@ -243,7 +244,10 @@ limitations under the License. -->
async function setLegend() { async function setLegend() {
updateSettings(); updateSettings();
const expression = dashboardStore.selectedGrid.legendMQE && dashboardStore.selectedGrid.legendMQE.expression; const expression = dashboardStore.selectedGrid.legendMQE && dashboardStore.selectedGrid.legendMQE.expression;
const { getExpressionQuery } = useQueryTopologyExpressionsProcessor([expression], topologyStore.nodes); const { getExpressionQuery } = useQueryTopologyExpressionsProcessor(
[expression],
topologyStore.nodes.filter((d: Node) => d.isReal),
);
const param = getExpressionQuery(); const param = getExpressionQuery();
const res = await topologyStore.getNodeExpressionValue(param); const res = await topologyStore.getNodeExpressionValue(param);
if (res.errors) { if (res.errors) {

View File

@ -285,7 +285,10 @@ limitations under the License. -->
if (!expression) { if (!expression) {
return; return;
} }
const { getExpressionQuery } = useQueryTopologyExpressionsProcessor([expression], topologyStore.nodes); const { getExpressionQuery } = useQueryTopologyExpressionsProcessor(
[expression],
topologyStore.nodes.filter((d: Node) => d.isReal),
);
const param = getExpressionQuery(); const param = getExpressionQuery();
const res = await topologyStore.getNodeExpressionValue(param); const res = await topologyStore.getNodeExpressionValue(param);
if (res.errors) { if (res.errors) {
@ -314,17 +317,16 @@ limitations under the License. -->
topologyStore.nodeMetricValue[m].values.find((val: { id: string; value: unknown }) => val.id === data.id)) || topologyStore.nodeMetricValue[m].values.find((val: { id: string; value: unknown }) => val.id === data.id)) ||
{}; {};
const opt: MetricConfigOpt = nodeMetricConfig[index] || {}; const opt: MetricConfigOpt = nodeMetricConfig[index] || {};
return ` <div class="mb-5"><span class="grey">${opt.label || m}: </span>${metric.value} ${ return ` <div class="mb-5"><span class="grey">${opt.label || m}: </span>${metric.value || NaN} ${
opt.unit || "unknown" opt.unit || "unknown"
}</div>`; }</div>`;
}); });
const tipHtml = [ let tipHtml = `<div class="mb-5"><span class="grey">name: </span>${
`<div class="mb-5"><span class="grey">name: </span>${
data.name data.name
}</div><div class="mb-5"><span class="grey">type: </span>${data.type || "UNKNOWN"}</div>`, }</div><div class="mb-5"><span class="grey">type: </span>${data.type || "UNKNOWN"}</div>`;
...html, if (data.isReal) {
].join(" "); tipHtml = [tipHtml, ...html].join(" ");
}
tooltip.value tooltip.value
.style("top", event.offsetY + 10 + "px") .style("top", event.offsetY + 10 + "px")
.style("left", event.offsetX + 10 + "px") .style("left", event.offsetX + 10 + "px")
@ -520,14 +522,21 @@ limitations under the License. -->
} }
function initNodeMenus() { function initNodeMenus() {
items.value = [ items.value = [
{ id: "hierarchyServices", title: "Hierarchy Services", func: handleHierarchyRelatedServices }, {
id: "hierarchyServices",
title: "Hierarchy Services",
func: handleHierarchyRelatedServices,
},
{ id: "inspect", title: "Inspect", func: handleInspect }, { id: "inspect", title: "Inspect", func: handleInspect },
{ id: "alerting", title: "Alerting", func: handleGoAlerting }, { id: "alerting", title: "Alerting", func: handleGoAlerting },
]; ];
if (!currentNode.value) { if (!currentNode.value) {
return; return;
} }
const diffLayers = currentNode.value.layers.filter((l: string) => l !== dashboardStore.layerId); const diffLayers = currentNode.value.layers.filter(
(l: string) => l !== dashboardStore.layerId && l !== "UNDEFINED",
);
for (const l of diffLayers) { for (const l of diffLayers) {
items.value.push({ items.value.push({
id: l, id: l,