Skip to content

Commit

Permalink
When processing a sample, empty or IPs can result in invalid nodes be…
Browse files Browse the repository at this point in the history
…ing added to the graph, causing downstream errors or unnecessary node creation.
  • Loading branch information
vvhuang-ll committed Dec 10, 2024
1 parent 2d9605d commit a0ab5b8
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions pkg/controller/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a0ab5b8

Please sign in to comment.