use constants for the topology names in Parents/metadata/metrics

This commit is contained in:
Paul Bellamy
2016-01-18 10:56:36 +00:00
committed by Simon Howe
parent 3cda328976
commit e30c9dc264
18 changed files with 76 additions and 63 deletions

View File

@@ -70,11 +70,11 @@ func (m MetadataRow) Copy() MetadataRow {
// an origin ID, which is (optimistically) a node ID in one of our topologies.
func NodeMetadata(n report.Node) []MetadataRow {
renderers := map[string]func(report.Node) []MetadataRow{
"process": processNodeMetadata,
"container": containerNodeMetadata,
"container_image": containerImageNodeMetadata,
"pod": podNodeMetadata,
"host": hostNodeMetadata,
report.Process: processNodeMetadata,
report.Container: containerNodeMetadata,
report.ContainerImage: containerImageNodeMetadata,
report.Pod: podNodeMetadata,
report.Host: hostNodeMetadata,
}
if renderer, ok := renderers[n.Topology]; ok {
return renderer(n)

View File

@@ -22,7 +22,7 @@ func TestNodeMetadata(t *testing.T) {
node: report.MakeNodeWith(map[string]string{
docker.ContainerID: fixture.ClientContainerID,
docker.LabelPrefix + "label1": "label1value",
}).WithTopology("container").WithSets(report.Sets{
}).WithTopology(report.Container).WithSets(report.Sets{
docker.ContainerIPs: report.MakeStringSet("10.10.10.0/24", "10.10.10.1/24"),
}).WithLatest(docker.ContainerState, fixture.Now, docker.StateRunning),
want: []detailed.MetadataRow{

View File

@@ -85,9 +85,9 @@ func toFixed(num float64, precision int) float64 {
// an origin ID, which is (optimistically) a node ID in one of our topologies.
func NodeMetrics(n report.Node) []MetricRow {
renderers := map[string]func(report.Node) []MetricRow{
"process": processNodeMetrics,
"container": containerNodeMetrics,
"host": hostNodeMetrics,
report.Process: processNodeMetrics,
report.Container: containerNodeMetrics,
report.Host: hostNodeMetrics,
}
if renderer, ok := renderers[n.Topology]; ok {
return renderer(n)

View File

@@ -93,11 +93,11 @@ var (
topologyID string
NodeSummaryGroup
}{
{"host", NodeSummaryGroup{TopologyID: "hosts", Label: "Hosts", Columns: []string{host.CPUUsage, host.MemUsage}}},
{"pod", NodeSummaryGroup{TopologyID: "pods", Label: "Pods", Columns: []string{}}},
{"container_image", NodeSummaryGroup{TopologyID: "containers-by-image", Label: "Container Images", Columns: []string{}}},
{"container", NodeSummaryGroup{TopologyID: "containers", Label: "Containers", Columns: []string{docker.CPUTotalUsage, docker.MemoryUsage}}},
{"process", NodeSummaryGroup{TopologyID: "applications", Label: "Applications", Columns: []string{process.PID, process.CPUUsage, process.MemoryUsage}}},
{report.Host, NodeSummaryGroup{TopologyID: "hosts", Label: "Hosts", Columns: []string{host.CPUUsage, host.MemUsage}}},
{report.Pod, NodeSummaryGroup{TopologyID: "pods", Label: "Pods", Columns: []string{}}},
{report.ContainerImage, NodeSummaryGroup{TopologyID: "containers-by-image", Label: "Container Images", Columns: []string{}}},
{report.Container, NodeSummaryGroup{TopologyID: "containers", Label: "Containers", Columns: []string{docker.CPUTotalUsage, docker.MemoryUsage}}},
{report.Process, NodeSummaryGroup{TopologyID: "applications", Label: "Applications", Columns: []string{process.PID, process.CPUUsage, process.MemoryUsage}}},
}
)
@@ -140,11 +140,11 @@ func parents(r report.Report, n render.RenderableNode) (result []Parent) {
report.Topology
render func(report.Node) Parent
}{
"container": {r.Container, containerParent},
"pod": {r.Pod, podParent},
"service": {r.Service, serviceParent},
"container_image": {r.ContainerImage, containerImageParent},
"host": {r.Host, hostParent},
report.Container: {r.Container, containerParent},
report.Pod: {r.Pod, podParent},
report.Service: {r.Service, serviceParent},
report.ContainerImage: {r.ContainerImage, containerImageParent},
report.Host: {r.Host, hostParent},
}
topologyIDs := []string{}
for topologyID := range topologies {

View File

@@ -37,13 +37,13 @@ var (
endpoint.Addr: randomIP,
endpoint.Port: randomPort,
endpoint.Conntracked: "true",
}).WithAdjacent(serverEndpointNodeID).WithID(randomEndpointNodeID).WithTopology("endpoint"),
}).WithAdjacent(serverEndpointNodeID).WithID(randomEndpointNodeID).WithTopology(report.Endpoint),
serverEndpointNodeID: report.MakeNode().WithMetadata(map[string]string{
endpoint.Addr: serverIP,
endpoint.Port: serverPort,
endpoint.Conntracked: "true",
}).WithID(serverEndpointNodeID).WithTopology("endpoint"),
}).WithID(serverEndpointNodeID).WithTopology(report.Endpoint),
},
},
Container: report.Topology{
@@ -55,7 +55,7 @@ var (
}).WithSets(report.Sets{
docker.ContainerIPs: report.MakeStringSet(containerIP),
docker.ContainerPorts: report.MakeStringSet(fmt.Sprintf("%s:%s->%s/tcp", serverIP, serverPort, serverPort)),
}).WithID(containerNodeID).WithTopology("container"),
}).WithID(containerNodeID).WithTopology(report.Container),
},
},
Host: report.Topology{
@@ -64,7 +64,7 @@ var (
report.HostNodeID: serverHostNodeID,
}).WithSets(report.Sets{
host.LocalNetworks: report.MakeStringSet("192.168.0.0/16"),
}).WithID(serverHostNodeID).WithTopology("host"),
}).WithID(serverHostNodeID).WithTopology(report.Host),
},
},
}