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
Vincent Quanwei Huang (PSP) authored and Vincent Quanwei Huang (PSP) committed Dec 10, 2024
1 parent 90ad22e commit fd160ef
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 fd160ef

Please sign in to comment.