From a0ab5b86a540e6d8d21bcc0c65bbff5ffdfff357 Mon Sep 17 00:00:00 2001 From: vvhuang-ll <13680846391@163.com> Date: Tue, 10 Dec 2024 17:33:34 +0800 Subject: [PATCH] When processing a sample, empty or IPs can result in invalid nodes being added to the graph, causing downstream errors or unnecessary node creation. --- pkg/controller/graph/graph.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/pkg/controller/graph/graph.go b/pkg/controller/graph/graph.go index 2a57a239..ea4c226c 100644 --- a/pkg/controller/graph/graph.go +++ b/pkg/controller/graph/graph.go @@ -105,19 +105,23 @@ func (g *FlowGraph) AddNodesFromVector(v model.Vector) { } func (g *FlowGraph) AddNodesFromSample(v *model.Sample) { - ip := string(v.Metric["src"]) - t := string(v.Metric["src_type"]) - podName := string(v.Metric["src_pod"]) - podNamespace := string(v.Metric["src_namespace"]) - nodeName := string(v.Metric["src_node"]) - g.AddNode(createNode(t, ip, podNamespace, podName, nodeName)) - - ip = string(v.Metric["dst"]) - t = string(v.Metric["dst_type"]) - podName = string(v.Metric["dst_pod"]) - podNamespace = string(v.Metric["dst_namespace"]) - nodeName = string(v.Metric["dst_node"]) - g.AddNode(createNode(t, ip, podNamespace, podName, nodeName)) + srcIP := string(v.Metric["src"]) + if srcIP != "" { + t := string(v.Metric["src_type"]) + podName := string(v.Metric["src_pod"]) + podNamespace := string(v.Metric["src_namespace"]) + nodeName := string(v.Metric["src_node"]) + g.AddNode(createNode(t, srcIP, podNamespace, podName, nodeName)) + } + + dstIP := string(v.Metric["dst"]) + if dstIP != "" { + t := string(v.Metric["dst_type"]) + podName := string(v.Metric["dst_pod"]) + podNamespace := string(v.Metric["dst_namespace"]) + nodeName := string(v.Metric["dst_node"]) + g.AddNode(createNode(t, dstIP, podNamespace, podName, nodeName)) + } } func (g *FlowGraph) AddNode(n Node) {