Skip to content

Commit

Permalink
fixing up lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbellamy committed Jan 8, 2016
1 parent 477c0a8 commit 239a83d
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 47 deletions.
4 changes: 2 additions & 2 deletions app/api_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type APITopology struct {

// APINode is returned by the /api/topology/{name}/{id} handler.
type APINode struct {
Node detailed.DetailedNode `json:"node"`
Node detailed.Node `json:"node"`
}

// Full topology.
Expand Down Expand Up @@ -62,7 +62,7 @@ func handleNode(rep Reporter, renderer render.Renderer, w http.ResponseWriter, r
http.NotFound(w, r)
return
}
respondWith(w, http.StatusOK, APINode{Node: detailed.MakeDetailedNode(rpt, node)})
respondWith(w, http.StatusOK, APINode{Node: detailed.MakeNode(rpt, node)})
}

var upgrader = websocket.Upgrader{
Expand Down
1 change: 1 addition & 0 deletions render/detailed/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
})
)

// MetadataRow is a row for the metadata table.
type MetadataRow struct {
ID string `json:"id"`
Label string `json:"label"`
Expand Down
2 changes: 2 additions & 0 deletions render/detailed/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (
percentFormat = "percent"
)

// MetricRow is a tuple of data used to render a metric as a sparkline and
// accoutrements.
type MetricRow struct {
ID string
Label string
Expand Down
85 changes: 44 additions & 41 deletions render/detailed/detailed_node.go → render/detailed/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,37 @@ import (
"github.com/weaveworks/scope/report"
)

// DetailedNode is the data type that's yielded to the JavaScript layer when
// Node is the data type that's yielded to the JavaScript layer when
// we want deep information about an individual node.
type DetailedNode struct {
ID string `json:"id"`
Label string `json:"label"`
Rank string `json:"rank,omitempty"`
Pseudo bool `json:"pseudo,omitempty"`
Controls []ControlInstance `json:"controls"`
Metadata []MetadataRow `json:"metadata,omitempty"`
Metrics []MetricRow `json:"metrics,omitempty"`
Children []NodeSummaryGroup `json:"children,omitempty"`
Parents []Parent `json:"parents,omitempty"`
type Node struct {
ID string `json:"id"`
Label string `json:"label"`
Rank string `json:"rank,omitempty"`
Pseudo bool `json:"pseudo,omitempty"`
Controls []ControlInstance `json:"controls"`
Metadata []MetadataRow `json:"metadata,omitempty"`
Metrics []MetricRow `json:"metrics,omitempty"`
Children []ChildGroup `json:"children,omitempty"`
Parents []Parent `json:"parents,omitempty"`
}

type NodeSummaryGroup struct {
Label string `json:"label"`
Nodes []NodeSummary `json:"nodes"`
TopologyID string `json:"topologyId"`
// ChildGroup is a topology-typed group of children for a Node.
type ChildGroup struct {
Label string `json:"label"`
Nodes []ChildSummary `json:"nodes"`
TopologyID string `json:"topologyId"`
}

type NodeSummary struct {
// ChildSummary is summary information about a child for a Node.
type ChildSummary struct {
ID string `json:"id"`
Label string `json:"label"`
Linkable bool `json:"linkable"` // Whether this node can be linked-to
Metadata []MetadataRow `json:"metadata,omitempty"`
Metrics []MetricRow `json:"metrics,omitempty"`
}

// Parent is the information needed to build a link to the parent of a Node.
type Parent struct {
ID string `json:"id"`
Label string `json:"label"`
Expand All @@ -53,46 +56,46 @@ type ControlInstance struct {
report.Control
}

// MakeDetailedNode transforms a renderable node to a detailed node. It uses
// MakeNode transforms a renderable node to a detailed node. It uses
// aggregate metadata, plus the set of origin node IDs, to produce tables.
func MakeDetailedNode(r report.Report, n render.RenderableNode) DetailedNode {
var hosts, pods, containerImages, containers, applications []NodeSummary
func MakeNode(r report.Report, n render.RenderableNode) Node {
var hosts, pods, containerImages, containers, applications []ChildSummary
for id, child := range n.Children {
if id == n.ID {
continue
}

switch child.Topology {
case "process":
applications = append(applications, processNodeSummary(child))
applications = append(applications, processChildSummary(child))
case "container":
containers = append(containers, containerNodeSummary(child))
containers = append(containers, containerChildSummary(child))
case "container_image":
containerImages = append(containerImages, containerImageNodeSummary(child))
containerImages = append(containerImages, containerImageChildSummary(child))
case "pod":
pods = append(pods, podNodeSummary(child))
pods = append(pods, podChildSummary(child))
case "host":
hosts = append(hosts, hostNodeSummary(child))
hosts = append(hosts, hostChildSummary(child))
}
}
children := []NodeSummaryGroup{}
children := []ChildGroup{}
if len(hosts) > 0 {
children = append(children, NodeSummaryGroup{TopologyID: "hosts", Label: "Hosts", Nodes: hosts})
children = append(children, ChildGroup{TopologyID: "hosts", Label: "Hosts", Nodes: hosts})
}
if len(pods) > 0 {
children = append(children, NodeSummaryGroup{TopologyID: "pods", Label: "Pods", Nodes: pods})
children = append(children, ChildGroup{TopologyID: "pods", Label: "Pods", Nodes: pods})
}
if len(containerImages) > 0 {
children = append(children, NodeSummaryGroup{TopologyID: "containers-by-image", Label: "Container Images", Nodes: containerImages})
children = append(children, ChildGroup{TopologyID: "containers-by-image", Label: "Container Images", Nodes: containerImages})
}
if len(containers) > 0 {
children = append(children, NodeSummaryGroup{TopologyID: "containers", Label: "Containers", Nodes: containers})
children = append(children, ChildGroup{TopologyID: "containers", Label: "Containers", Nodes: containers})
}
if len(applications) > 0 {
children = append(children, NodeSummaryGroup{TopologyID: "applications", Label: "Applications", Nodes: applications})
children = append(children, ChildGroup{TopologyID: "applications", Label: "Applications", Nodes: applications})
}

return DetailedNode{
return Node{
ID: n.ID,
Label: n.LabelMajor,
Rank: n.Rank,
Expand Down Expand Up @@ -238,7 +241,7 @@ func parents(r report.Report, n render.RenderableNode) (result []Parent) {
return result
}

func processNodeSummary(nmd report.Node) NodeSummary {
func processChildSummary(nmd report.Node) ChildSummary {
var (
id string
label = nmd.Metadata[process.Comm]
Expand All @@ -250,7 +253,7 @@ func processNodeSummary(nmd report.Node) NodeSummary {
id = render.MakeProcessID(report.ExtractHostID(nmd), pid)
}
_, isConnected := nmd.Metadata[render.IsConnected]
return NodeSummary{
return ChildSummary{
ID: id,
Label: label,
Linkable: isConnected,
Expand All @@ -259,9 +262,9 @@ func processNodeSummary(nmd report.Node) NodeSummary {
}
}

func containerNodeSummary(nmd report.Node) NodeSummary {
func containerChildSummary(nmd report.Node) ChildSummary {
label, _ := render.GetRenderableContainerName(nmd)
return NodeSummary{
return ChildSummary{
ID: render.MakeContainerID(nmd.Metadata[docker.ContainerID]),
Label: label,
Linkable: true,
Expand All @@ -270,26 +273,26 @@ func containerNodeSummary(nmd report.Node) NodeSummary {
}
}

func podNodeSummary(nmd report.Node) NodeSummary {
return NodeSummary{
func podChildSummary(nmd report.Node) ChildSummary {
return ChildSummary{
ID: render.MakePodID(nmd.Metadata[kubernetes.PodID]),
Label: nmd.Metadata[kubernetes.PodName],
Linkable: true,
Metadata: podNodeMetadata(nmd),
}
}

func containerImageNodeSummary(nmd report.Node) NodeSummary {
return NodeSummary{
func containerImageChildSummary(nmd report.Node) ChildSummary {
return ChildSummary{
ID: render.MakeContainerImageID(nmd.Metadata[docker.ImageID]),
Label: nmd.Metadata[docker.ImageName],
Linkable: true,
Metadata: containerImageNodeMetadata(nmd),
}
}

func hostNodeSummary(nmd report.Node) NodeSummary {
return NodeSummary{
func hostChildSummary(nmd report.Node) ChildSummary {
return ChildSummary{
ID: render.MakeHostID(nmd.Metadata[host.HostName]),
Label: nmd.Metadata[host.HostName],
Linkable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

func TestMakeDetailedHostNode(t *testing.T) {
renderableNode := render.HostRenderer.Render(fixture.Report)[render.MakeHostID(fixture.ClientHostID)]
have := detailed.MakeDetailedNode(fixture.Report, renderableNode)
want := render.DetailedNode{
have := detailed.MakeNode(fixture.Report, renderableNode)
want := detailed.Node{
ID: render.MakeHostID(fixture.ClientHostID),
Label: "client",
Rank: "hostname.com",
Expand Down Expand Up @@ -94,8 +94,8 @@ func TestMakeDetailedContainerNode(t *testing.T) {
if !ok {
t.Fatalf("Node not found: %s", id)
}
have := detailed.MakeDetailedNode(fixture.Report, renderableNode)
want := render.DetailedNode{
have := detailed.MakeNode(fixture.Report, renderableNode)
want := detailed.Node{
ID: id,
Label: "server",
Rank: "imageid456",
Expand Down
4 changes: 4 additions & 0 deletions render/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@ func MakeAddressID(hostID, addr string) string {
return makeID("address", hostID, addr)
}

// MakeContainerID makes a container node ID for rendered nodes.
func MakeContainerID(containerID string) string {
return makeID("container", containerID)
}

// MakeContainerImageID makes a container image node ID for rendered nodes.
func MakeContainerImageID(imageID string) string {
return makeID("container_image", imageID)
}

// MakePodID makes a pod node ID for rendered nodes.
func MakePodID(podID string) string {
return makeID("pod", podID)
}

// MakeServiceID makes a service node ID for rendered nodes.
func MakeServiceID(serviceID string) string {
return makeID("service", serviceID)
}
Expand Down
4 changes: 4 additions & 0 deletions render/renderable_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,17 @@ func (rn RenderableNode) Prune() RenderableNode {
return cp
}

// Children is a set of the children of a Node.
type Children map[string]report.Node

// Add adds a child to the set of children and return the new set.
func (c Children) Add(id string, child report.Node) Children {
result := c.Copy()
result[id] = child
return result
}

// Copy returns a value copy of the set of children.
func (c Children) Copy() Children {
result := Children{}
for id, child := range c {
Expand All @@ -176,6 +179,7 @@ func (c Children) Copy() Children {
return result
}

// Merge returns the union of two sets of children.
func (c Children) Merge(other Children) Children {
result := c.Copy()
for id, child := range other {
Expand Down

0 comments on commit 239a83d

Please sign in to comment.