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

refactor: banish TheInternet #3003

Merged
merged 1 commit into from
Dec 25, 2017
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
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