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

don't render any metrics/metadata for uncontained node #956

Merged
merged 1 commit into from
Feb 12, 2016
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
4 changes: 3 additions & 1 deletion render/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,10 @@ func MapProcess2Container(n RenderableNode, _ report.Networks) RenderableNodes {
id = MakeContainerID(containerID)
node = NewDerivedNode(id, n)
} else {
nCopy := n.Copy()
nCopy.Node = nCopy.Node.WithID("").WithTopology("") // Wipe the ID so it cannot be rendered.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

id = MakePseudoNodeID(UncontainedID, hostID)
node = newDerivedPseudoNode(id, UncontainedMajor, n)
node = newDerivedPseudoNode(id, UncontainedMajor, nCopy)
node.LabelMinor = hostID
}

Expand Down
62 changes: 39 additions & 23 deletions render/mapping_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package render_test

import (
"fmt"
"net"
"testing"

Expand All @@ -18,82 +19,93 @@ func nrn(nmd report.Node) render.RenderableNode {

func TestMapEndpointIdentity(t *testing.T) {
for _, input := range []testcase{
{nrn(report.MakeNode()), false},
{nrn(report.MakeNodeWith(map[string]string{endpoint.Addr: "1.2.3.4", endpoint.Procspied: "true"})), false},
{nrn(report.MakeNodeWith(map[string]string{endpoint.Port: "1234", endpoint.Procspied: "true"})), false},
{nrn(report.MakeNodeWith(map[string]string{endpoint.Addr: "1.2.3.4", endpoint.Port: "1234", endpoint.Procspied: "true"})), true},
{nrn(report.MakeNodeWith(map[string]string{endpoint.Addr: "1.2.3.4", endpoint.Port: "40000", endpoint.Procspied: "true"})), true},
{nrn(report.MakeNodeWith(map[string]string{report.HostNodeID: report.MakeHostNodeID("foo"), endpoint.Addr: "10.0.0.1", endpoint.Port: "20001", endpoint.Procspied: "true"})), true},
{"empty", nrn(report.MakeNode()), false},
{"", nrn(report.MakeNodeWith(map[string]string{endpoint.Addr: "1.2.3.4", endpoint.Procspied: "true"})), false},
{"", nrn(report.MakeNodeWith(map[string]string{endpoint.Port: "1234", endpoint.Procspied: "true"})), false},
{"", nrn(report.MakeNodeWith(map[string]string{endpoint.Addr: "1.2.3.4", endpoint.Port: "1234", endpoint.Procspied: "true"})), true},
{"", nrn(report.MakeNodeWith(map[string]string{endpoint.Addr: "1.2.3.4", endpoint.Port: "40000", endpoint.Procspied: "true"})), true},
{"", nrn(report.MakeNodeWith(map[string]string{report.HostNodeID: report.MakeHostNodeID("foo"), endpoint.Addr: "10.0.0.1", endpoint.Port: "20001", endpoint.Procspied: "true"})), true},
} {
testMap(t, render.MapEndpointIdentity, input)
}
}

func TestMapProcessIdentity(t *testing.T) {
for _, input := range []testcase{
{nrn(report.MakeNode()), false},
{nrn(report.MakeNodeWith(map[string]string{process.PID: "201"})), true},
{"empty", nrn(report.MakeNode()), false},
{"basic process", nrn(report.MakeNodeWith(map[string]string{process.PID: "201"})), true},
} {
testMap(t, render.MapProcessIdentity, input)
}
}

func TestMapProcess2Container(t *testing.T) {
for _, input := range []testcase{
{"empty", nrn(report.MakeNode()), true},
{"basic process", nrn(report.MakeNodeWith(map[string]string{process.PID: "201", docker.ContainerID: "a1b2c3"})), true},
{"uncontained", nrn(report.MakeNodeWith(map[string]string{process.PID: "201", report.HostNodeID: report.MakeHostNodeID("foo")})), true},
} {
testMap(t, render.MapProcess2Container, input)
}
}

func TestMapContainerIdentity(t *testing.T) {
for _, input := range []testcase{
{nrn(report.MakeNode()), false},
{nrn(report.MakeNodeWith(map[string]string{docker.ContainerID: "a1b2c3"})), true},
{"empty", nrn(report.MakeNode()), false},
{"basic container", nrn(report.MakeNodeWith(map[string]string{docker.ContainerID: "a1b2c3"})), true},
} {
testMap(t, render.MapContainerIdentity, input)
}
}

func TestMapContainerImageIdentity(t *testing.T) {
for _, input := range []testcase{
{nrn(report.MakeNode()), false},
{nrn(report.MakeNodeWith(map[string]string{docker.ImageID: "a1b2c3"})), true},
{"empty", nrn(report.MakeNode()), false},
{"basic image", nrn(report.MakeNodeWith(map[string]string{docker.ImageID: "a1b2c3"})), true},
} {
testMap(t, render.MapContainerImageIdentity, input)
}
}

func TestMapAddressIdentity(t *testing.T) {
for _, input := range []testcase{
{nrn(report.MakeNode()), false},
{nrn(report.MakeNodeWith(map[string]string{endpoint.Addr: "192.168.1.1"})), true},
{"empty", nrn(report.MakeNode()), false},
{"basic address", nrn(report.MakeNodeWith(map[string]string{endpoint.Addr: "192.168.1.1"})), true},
} {
testMap(t, render.MapAddressIdentity, input)
}
}

func TestMapHostIdentity(t *testing.T) {
for _, input := range []testcase{
{nrn(report.MakeNode()), true}, // TODO it's questionable if this is actually correct
{"empty", nrn(report.MakeNode()), true}, // TODO it's questionable if this is actually correct
} {
testMap(t, render.MapHostIdentity, input)
}
}

func TestMapPodIdentity(t *testing.T) {
for _, input := range []testcase{
{nrn(report.MakeNode()), false},
{nrn(report.MakeNodeWith(map[string]string{kubernetes.PodID: "ping/pong", kubernetes.PodName: "pong"})), true},
{"empty", nrn(report.MakeNode()), false},
{"basic pod", nrn(report.MakeNodeWith(map[string]string{kubernetes.PodID: "ping/pong", kubernetes.PodName: "pong"})), true},
} {
testMap(t, render.MapPodIdentity, input)
}
}

func TestMapServiceIdentity(t *testing.T) {
for _, input := range []testcase{
{nrn(report.MakeNode()), false},
{nrn(report.MakeNodeWith(map[string]string{kubernetes.ServiceID: "ping/pong", kubernetes.ServiceName: "pong"})), true},
{"empty", nrn(report.MakeNode()), false},
{"basic service", nrn(report.MakeNodeWith(map[string]string{kubernetes.ServiceID: "ping/pong", kubernetes.ServiceName: "pong"})), true},
} {
testMap(t, render.MapServiceIdentity, input)
}
}

type testcase struct {
md render.RenderableNode
ok bool
name string
n render.RenderableNode
ok bool
}

func testMap(t *testing.T, f render.MapFunc, input testcase) {
Expand All @@ -102,7 +114,11 @@ func testMap(t *testing.T, f render.MapFunc, input testcase) {
t.Fatalf(err.Error())
}
localNetworks := report.Networks([]*net.IPNet{ipNet})
if have := f(input.md, localNetworks); input.ok != (len(have) > 0) {
t.Errorf("%v: want %v, have %v", input.md, input.ok, have)
if have := f(input.n, localNetworks); input.ok != (len(have) > 0) {
name := input.name
if name == "" {
name = fmt.Sprintf("%v", input.n)
}
t.Errorf("%s: want %v, have %v", name, input.ok, have)
}
}