Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancing dot view for exposure analysis graphs #353

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/netpol/connlist/connlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,4 +913,9 @@ var goodPathTests = []struct {
focusWorkload: "ratings-v1-b6994bb9",
outputFormats: ExposureValidFormats,
},
{
testDirName: "test_exposure_minimal_netpol_analysis",
exposureAnalysis: true,
outputFormats: []string{output.DOTFormat},
},
}
11 changes: 7 additions & 4 deletions pkg/netpol/connlist/conns_formatter_dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ const (
peerLineClosing = "]"
allPeersLbl = "all pods"
allNamespacesLbl = "all namespaces"
edgeWeightLabel = " weight="
ingWeight = "1"
egWeight = "0.5"
)

var edgeLineFormat = fmt.Sprintf("\t%%q -> %%q [label=%%q color=\"gold2\" fontcolor=\"darkgreen\"]")
var edgeLineFormat = fmt.Sprintf("\t%%q -> %%q [label=%%q color=\"gold2\" fontcolor=\"darkgreen\"%%s]")
var peerLineFormatPrefix = fmt.Sprintf("\t%%q [label=%%q color=%%q fontcolor=%%q")

// formatDOT: implements the connsFormatter interface for dot output format
Expand All @@ -35,7 +38,7 @@ type formatDOT struct {
// getEdgeLine formats an edge line from a Peer2PeerConnection struct , to be used for dot graph
func getEdgeLine(c Peer2PeerConnection) string {
connStr := common.ConnStrFromConnProperties(c.AllProtocolsAndPorts(), c.ProtocolsAndPorts())
return fmt.Sprintf(edgeLineFormat, c.Src().String(), c.Dst().String(), connStr)
return fmt.Sprintf(edgeLineFormat, c.Src().String(), c.Dst().String(), connStr, "")
}

// peerNameAndColorByType returns the peer label and color to be represented in the graph, and whether the peer is
Expand Down Expand Up @@ -179,9 +182,9 @@ func getEntireClusterLine() string {
// getExposureEdgeLine formats an exposure connection edge line for dot graph
func getExposureEdgeLine(realPeerStr, repPeerStr string, isIngress bool, conn *common.ConnectionSet) string {
if isIngress {
return fmt.Sprintf(edgeLineFormat, repPeerStr, realPeerStr, conn.String())
return fmt.Sprintf(edgeLineFormat, repPeerStr, realPeerStr, conn.String(), edgeWeightLabel+ingWeight)
}
return fmt.Sprintf(edgeLineFormat, realPeerStr, repPeerStr, conn.String())
return fmt.Sprintf(edgeLineFormat, realPeerStr, repPeerStr, conn.String(), edgeWeightLabel+egWeight)
}

// getRepPeerLine formats a representative peer line for dot graph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ digraph {
"{ingress-controller}" [label="{ingress-controller}" color="blue" fontcolor="blue"]
"backend/checkout[Deployment]" -> "backend/notification[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
"backend/checkout[Deployment]" -> "backend/recommendation[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
"backend/checkout[Deployment]" -> "entire-cluster" [label="UDP 5353" color="gold2" fontcolor="darkgreen"]
"backend/checkout[Deployment]" -> "entire-cluster" [label="UDP 5353" color="gold2" fontcolor="darkgreen" weight=0.5]
"backend/checkout[Deployment]" -> "payments/gateway[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
"backend/recommendation[Deployment]" -> "backend/catalog[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
"backend/recommendation[Deployment]" -> "entire-cluster" [label="UDP 5353" color="gold2" fontcolor="darkgreen"]
"backend/recommendation[Deployment]" -> "entire-cluster" [label="UDP 5353" color="gold2" fontcolor="darkgreen" weight=0.5]
"backend/reports[Deployment]" -> "backend/catalog[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
"backend/reports[Deployment]" -> "backend/recommendation[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
"backend/reports[Deployment]" -> "entire-cluster" [label="UDP 5353" color="gold2" fontcolor="darkgreen"]
"entire-cluster" -> "frontend/asset-cache[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
"entire-cluster" -> "frontend/webapp[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
"backend/reports[Deployment]" -> "entire-cluster" [label="UDP 5353" color="gold2" fontcolor="darkgreen" weight=0.5]
"entire-cluster" -> "frontend/asset-cache[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen" weight=1]
"entire-cluster" -> "frontend/webapp[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen" weight=1]
"frontend/webapp[Deployment]" -> "backend/checkout[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
"frontend/webapp[Deployment]" -> "backend/recommendation[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
"frontend/webapp[Deployment]" -> "backend/reports[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
"frontend/webapp[Deployment]" -> "backend/shipping[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
"frontend/webapp[Deployment]" -> "entire-cluster" [label="UDP 5353" color="gold2" fontcolor="darkgreen"]
"payments/gateway[Deployment]" -> "entire-cluster" [label="UDP 5353" color="gold2" fontcolor="darkgreen"]
"frontend/webapp[Deployment]" -> "entire-cluster" [label="UDP 5353" color="gold2" fontcolor="darkgreen" weight=0.5]
"payments/gateway[Deployment]" -> "entire-cluster" [label="UDP 5353" color="gold2" fontcolor="darkgreen" weight=0.5]
"payments/gateway[Deployment]" -> "payments/mastercard-processor[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
"payments/gateway[Deployment]" -> "payments/visa-processor[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
"{ingress-controller}" -> "frontend/asset-cache[Deployment]" [label="TCP 8080" color="gold2" fontcolor="darkgreen"]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading