Skip to content

Commit

Permalink
refactor: banish TheInternet
Browse files Browse the repository at this point in the history
TheInternet hasn't existed as a single node for a long time.

We also move & export the IsInternetNode predicate so it can be used
in more places.
  • Loading branch information
rade committed Dec 25, 2017
1 parent ceb3539 commit 590fa55
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
14 changes: 5 additions & 9 deletions render/detailed/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (c *connectionCounters) add(outgoing bool, localNode, remoteNode, localEndp
}

func internetAddr(node report.Node, ep report.Node) (string, bool) {
if !isInternetNode(node) {
if !render.IsInternetNode(node) {
return "", true
}
_, addr, _, ok := report.ParseEndpointNodeID(ep.ID)
Expand Down Expand Up @@ -181,15 +181,15 @@ func incomingConnectionsSummary(topologyID string, r report.Report, n report.Nod
}

columnHeaders := NormalColumns
if isInternetNode(n) {
if render.IsInternetNode(n) {
columnHeaders = InternetColumns
}
return ConnectionsSummary{
ID: "incoming-connections",
TopologyID: topologyID,
Label: "Inbound",
Columns: columnHeaders,
Connections: counts.rows(r, ns, isInternetNode(n)),
Connections: counts.rows(r, ns, render.IsInternetNode(n)),
}
}

Expand All @@ -213,15 +213,15 @@ func outgoingConnectionsSummary(topologyID string, r report.Report, n report.Nod
}

columnHeaders := NormalColumns
if isInternetNode(n) {
if render.IsInternetNode(n) {
columnHeaders = InternetColumns
}
return ConnectionsSummary{
ID: "outgoing-connections",
TopologyID: topologyID,
Label: "Outbound",
Columns: columnHeaders,
Connections: counts.rows(r, ns, isInternetNode(n)),
Connections: counts.rows(r, ns, render.IsInternetNode(n)),
}
}

Expand Down Expand Up @@ -264,7 +264,3 @@ func canonicalEndpointID(copies map[string]string, id string) string {
}
return id
}

func isInternetNode(n report.Node) bool {
return n.ID == render.IncomingInternetID || n.ID == render.OutgoingInternetID
}
1 change: 0 additions & 1 deletion render/detailed/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ var renderers = map[string]func(NodeSummary, report.Node) (NodeSummary, bool){
}

var templates = map[string]struct{ Label, LabelMinor string }{
render.TheInternetID: {render.InboundMajor, ""},
render.IncomingInternetID: {render.InboundMajor, render.InboundMinor},
render.OutgoingInternetID: {render.OutboundMajor, render.OutboundMinor},
}
Expand Down
2 changes: 1 addition & 1 deletion render/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func DoesNotHaveLabel(labelKey string, labelValue string) FilterFunc {
// IsNotPseudo returns true if the node is not a pseudo node
// or internet/service nodes.
func IsNotPseudo(n report.Node) bool {
return n.Topology != Pseudo || strings.HasSuffix(n.ID, TheInternetID) || strings.HasPrefix(n.ID, ServiceNodeIDPrefix)
return n.Topology != Pseudo || IsInternetNode(n) || strings.HasPrefix(n.ID, ServiceNodeIDPrefix)
}

// IsNamespace checks if the node is a pod/service in the specified namespace
Expand Down
10 changes: 7 additions & 3 deletions render/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import (

// Constants are used in the tests.
const (
TheInternetID = "theinternet"
IncomingInternetID = "in-" + TheInternetID
OutgoingInternetID = "out-" + TheInternetID
IncomingInternetID = "in-theinternet"
OutgoingInternetID = "out-theinternet"
)

// IsInternetNode determines whether the node represents the Internet.
func IsInternetNode(n report.Node) bool {
return n.ID == IncomingInternetID || n.ID == OutgoingInternetID
}

// MakePseudoNodeID joins the parts of an id into the id of a pseudonode
func MakePseudoNodeID(parts ...string) string {
return strings.Join(append([]string{"pseudo"}, parts...), ":")
Expand Down
3 changes: 0 additions & 3 deletions report/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (
"strings"
)

// TheInternet is used as a node ID to indicate a remote IP.
const TheInternet = "theinternet"

// Delimiters are used to separate parts of node IDs, to guarantee uniqueness
// in particular contexts.
const (
Expand Down

0 comments on commit 590fa55

Please sign in to comment.