Exemple #1
0
func TestMakeDetailedHostNode(t *testing.T) {
	renderableNode := render.HostRenderer.Render(fixture.Report)[render.MakeHostID(fixture.ClientHostID)]
	have := render.MakeDetailedNode(fixture.Report, renderableNode)
	want := render.DetailedNode{
		ID:         render.MakeHostID(fixture.ClientHostID),
		LabelMajor: "client",
		LabelMinor: "hostname.com",
		Pseudo:     false,
		Controls:   []render.ControlInstance{},
		Tables: []render.Table{
			{
				Title:   fmt.Sprintf("Host %q", fixture.ClientHostName),
				Numeric: false,
				Rank:    1,
				Rows: []render.Row{
					{
						Key:        "Load",
						ValueMajor: "0.01 0.01 0.01",
						ValueMinor: "",
					},
					{
						Key:        "Operating system",
						ValueMajor: "Linux",
						ValueMinor: "",
					},
				},
			},
			{
				Title:   "Connections",
				Numeric: false,
				Rank:    0,
				Rows: []render.Row{
					{
						Key:        "TCP connections",
						ValueMajor: "3",
						ValueMinor: "",
					},
					{
						Key:        "Client",
						ValueMajor: "Server",
						ValueMinor: "",
						Expandable: true,
					},
					{
						Key:        "10.10.10.20",
						ValueMajor: "192.168.1.1",
						ValueMinor: "",
						Expandable: true,
					},
				},
			},
		},
	}
	if !reflect.DeepEqual(want, have) {
		t.Errorf("%s", test.Diff(want, have))
	}
}
Exemple #2
0
func hostParent(n report.Node) Parent {
	return Parent{
		ID:         render.MakeHostID(n.Metadata[host.HostName]),
		Label:      n.Metadata[host.HostName],
		TopologyID: "hosts",
	}
}
Exemple #3
0
func hostParent(n report.Node) Parent {
	hostName, _ := n.Latest.Lookup(host.HostName)
	return Parent{
		ID:         render.MakeHostID(hostName),
		Label:      hostName,
		TopologyID: "hosts",
	}
}
Exemple #4
0
func hostNodeSummary(nmd report.Node) NodeSummary {
	return NodeSummary{
		ID:       render.MakeHostID(nmd.Metadata[host.HostName]),
		Label:    nmd.Metadata[host.HostName],
		Linkable: true,
		Metadata: hostNodeMetadata(nmd),
		Metrics:  hostNodeMetrics(nmd),
	}
}
Exemple #5
0
			LabelMinor: test.ServerHostName,
			Rank:       "",
			Pseudo:     true,
			Adjacency:  report.MakeIDList(render.TheInternetID),
			Origins: report.MakeIDList(
				test.NonContainerNodeID,
				test.NonContainerProcessNodeID,
				test.ServerHostNodeID,
			),
			NodeMetadata: report.MakeNodeMetadata(),
			EdgeMetadata: report.EdgeMetadata{},
		},
		render.TheInternetID: theInternetNode(report.MakeIDList(test.ServerContainerImageName)),
	}

	ServerHostRenderedID = render.MakeHostID(test.ServerHostID)
	ClientHostRenderedID = render.MakeHostID(test.ClientHostID)
	pseudoHostID1        = render.MakePseudoNodeID("10.10.10.10", "192.168.1.1", "")
	pseudoHostID2        = render.MakePseudoNodeID("10.10.10.11", "192.168.1.1", "")

	RenderedHosts = render.RenderableNodes{
		ServerHostRenderedID: {
			ID:         ServerHostRenderedID,
			LabelMajor: "server",       // before first .
			LabelMinor: "hostname.com", // after first .
			Rank:       "hostname.com",
			Pseudo:     false,
			Adjacency:  report.MakeIDList(),
			Origins: report.MakeIDList(
				test.ServerHostNodeID,
				test.ServerAddressNodeID,
Exemple #6
0
func TestMakeDetailedHostNode(t *testing.T) {
	renderableNode := render.HostRenderer.Render(fixture.Report)[render.MakeHostID(fixture.ClientHostID)]
	have := detailed.MakeNode(fixture.Report, renderableNode)

	containerImageNodeSummary, _ := detailed.MakeNodeSummary(
		render.ContainerImageRenderer.Render(fixture.Report)[render.MakeContainerImageID(fixture.ClientContainerImageName)].Node,
	)
	containerNodeSummary, _ := detailed.MakeNodeSummary(fixture.Report.Container.Nodes[fixture.ClientContainerNodeID])
	process1NodeSummary, _ := detailed.MakeNodeSummary(fixture.Report.Process.Nodes[fixture.ClientProcess1NodeID])
	process1NodeSummary.Linkable = true
	process2NodeSummary, _ := detailed.MakeNodeSummary(fixture.Report.Process.Nodes[fixture.ClientProcess2NodeID])
	process2NodeSummary.Linkable = true
	want := detailed.Node{
		NodeSummary: detailed.NodeSummary{
			ID:       render.MakeHostID(fixture.ClientHostID),
			Label:    "client",
			Linkable: true,
			Metadata: []detailed.MetadataRow{
				{
					ID:    "host_name",
					Value: "client.hostname.com",
				},
				{
					ID:    "os",
					Value: "Linux",
				},
				{
					ID:    "local_networks",
					Value: "10.10.10.0/24",
				},
			},
			Metrics: []detailed.MetricRow{
				{
					ID:     host.CPUUsage,
					Format: "percent",
					Value:  0.07,
					Metric: &fixture.ClientHostCPUMetric,
				},
				{
					ID:     host.MemoryUsage,
					Format: "filesize",
					Value:  0.08,
					Metric: &fixture.ClientHostMemoryMetric,
				},
				{
					ID:     host.Load1,
					Group:  "load",
					Value:  0.09,
					Metric: &fixture.ClientHostLoad1Metric,
				},
				{
					ID:     host.Load5,
					Group:  "load",
					Value:  0.10,
					Metric: &fixture.ClientHostLoad5Metric,
				},
				{
					ID:     host.Load15,
					Group:  "load",
					Value:  0.11,
					Metric: &fixture.ClientHostLoad15Metric,
				},
			},
		},
		Rank:     "hostname.com",
		Pseudo:   false,
		Controls: []detailed.ControlInstance{},
		Children: []detailed.NodeSummaryGroup{
			{
				Label:      "Containers",
				TopologyID: "containers",
				Columns:    []detailed.Column{docker.CPUTotalUsage, docker.MemoryUsage},
				Nodes:      []detailed.NodeSummary{containerNodeSummary},
			},
			{
				Label:      "Processes",
				TopologyID: "processes",
				Columns:    []detailed.Column{process.PID, process.CPUUsage, process.MemoryUsage},
				Nodes:      []detailed.NodeSummary{process1NodeSummary, process2NodeSummary},
			},
			{
				Label:      "Container Images",
				TopologyID: "containers-by-image",
				Columns:    []detailed.Column{render.ContainersKey},
				Nodes:      []detailed.NodeSummary{containerImageNodeSummary},
			},
		},
	}
	if !reflect.DeepEqual(want, have) {
		t.Errorf("%s", test.Diff(want, have))
	}
}
Exemple #7
0
func TestMakeDetailedContainerNode(t *testing.T) {
	id := render.MakeContainerID(fixture.ServerContainerID)
	renderableNode, ok := render.ContainerRenderer.Render(fixture.Report)[id]
	if !ok {
		t.Fatalf("Node not found: %s", id)
	}
	have := detailed.MakeNode(fixture.Report, renderableNode)
	want := detailed.Node{
		NodeSummary: detailed.NodeSummary{
			ID:       id,
			Label:    "server",
			Linkable: true,
			Metadata: []detailed.MetadataRow{
				{ID: "docker_container_id", Value: fixture.ServerContainerID, Prime: true},
				{ID: "docker_container_state", Value: "running", Prime: true},
				{ID: "docker_image_id", Value: fixture.ServerContainerImageID},
			},
			DockerLabels: []detailed.MetadataRow{
				{ID: "label_" + render.AmazonECSContainerNameLabel, Value: `server`},
				{ID: "label_foo1", Value: `bar1`},
				{ID: "label_foo2", Value: `bar2`},
				{ID: "label_io.kubernetes.pod.name", Value: "ping/pong-b"},
			},
			Metrics: []detailed.MetricRow{
				{
					ID:     docker.CPUTotalUsage,
					Format: "percent",
					Value:  0.05,
					Metric: &fixture.ServerContainerCPUMetric,
				},
				{
					ID:     docker.MemoryUsage,
					Format: "filesize",
					Value:  0.06,
					Metric: &fixture.ServerContainerMemoryMetric,
				},
			},
		},
		Rank:     "imageid456",
		Pseudo:   false,
		Controls: []detailed.ControlInstance{},
		Children: []detailed.NodeSummaryGroup{
			{
				Label:      "Processes",
				TopologyID: "processes",
				Columns:    []detailed.Column{process.PID, process.CPUUsage, process.MemoryUsage},
				Nodes: []detailed.NodeSummary{
					{
						ID:       fmt.Sprintf("process:%s:%s", "server.hostname.com", fixture.ServerPID),
						Label:    "apache",
						Linkable: true,
						Metadata: []detailed.MetadataRow{
							{ID: process.PID, Value: fixture.ServerPID, Prime: true},
						},
						Metrics: []detailed.MetricRow{},
					},
				},
			},
		},
		Parents: []detailed.Parent{
			{
				ID:         render.MakeContainerImageID(fixture.ServerContainerImageName),
				Label:      fixture.ServerContainerImageName,
				TopologyID: "containers-by-image",
			},
			{
				ID:         render.MakeHostID(fixture.ServerHostName),
				Label:      fixture.ServerHostName,
				TopologyID: "hosts",
			},
		},
	}
	if !reflect.DeepEqual(want, have) {
		t.Errorf("%s", test.Diff(want, have))
	}
}
Exemple #8
0
		uncontainedServerID: {
			ID:         uncontainedServerID,
			LabelMajor: render.UncontainedMajor,
			LabelMinor: fixture.ServerHostName,
			Rank:       "",
			Pseudo:     true,
			Children: report.MakeNodeSet(
				fixture.Report.Process.Nodes[fixture.NonContainerProcessNodeID],
			),
			Node:         report.MakeNode().WithAdjacent(render.TheInternetID),
			EdgeMetadata: report.EdgeMetadata{},
		},
		render.TheInternetID: theInternetNode(ServerContainerImageRenderedName),
	}).Prune()

	ServerHostRenderedID = render.MakeHostID(fixture.ServerHostID)
	ClientHostRenderedID = render.MakeHostID(fixture.ClientHostID)
	pseudoHostID1        = render.MakePseudoNodeID(fixture.UnknownClient1IP, fixture.ServerIP)
	pseudoHostID2        = render.MakePseudoNodeID(fixture.UnknownClient3IP, fixture.ServerIP)

	RenderedHosts = (render.RenderableNodes{
		ServerHostRenderedID: {
			ID:         ServerHostRenderedID,
			LabelMajor: "server",       // before first .
			LabelMinor: "hostname.com", // after first .
			Rank:       "hostname.com",
			Pseudo:     false,
			Children: report.MakeNodeSet(
				fixture.Report.Container.Nodes[fixture.ServerContainerNodeID],
				fixture.Report.Container.Nodes[fixture.ServerProcessNodeID],
			),
Exemple #9
0
func hostNodeSummary(nmd report.Node) NodeSummary {
	hostName, _ := nmd.Latest.Lookup(host.HostName)
	return baseNodeSummary(render.MakeHostID(hostName), hostName, true, nmd)
}