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

Add container names to process minor label if possible. #366

Merged
merged 3 commits into from
Aug 19, 2015
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions app/api_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func TestAPITopologyApplications(t *testing.T) {
defer ts.Close()
is404(t, ts, "/api/topology/applications/foobar")
{
body := getRawJSON(t, ts, "/api/topology/applications")
body := getRawJSON(t, ts, "/api/topology/containers")

This comment was marked as abuse.

var topo APITopology
if err := json.Unmarshal(body, &topo); err != nil {
t.Fatal(err)
}

if want, have := render.OnlyConnected(expected.RenderedProcesses), fixNodeMetadatas(topo.Nodes); !reflect.DeepEqual(want, have) {
if want, have := expected.RenderedContainers, fixNodeMetadatas(topo.Nodes); !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
Expand All @@ -85,7 +85,7 @@ func TestAPITopologyApplications(t *testing.T) {
}
equals(t, expected.ServerProcessID, node.Node.ID)
equals(t, "apache", node.Node.LabelMajor)
equals(t, fmt.Sprintf("%s (%s)", test.ServerHostID, test.ServerPID), node.Node.LabelMinor)
equals(t, fmt.Sprintf("%s (server:%s)", test.ServerHostID, test.ServerPID), node.Node.LabelMinor)
equals(t, false, node.Node.Pseudo)
// Let's not unit-test the specific content of the detail tables
}
Expand Down
2 changes: 1 addition & 1 deletion app/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var topologyRegistry = map[string]topologyView{
"applications": {
human: "Applications",
parent: "",
renderer: render.FilterUnconnected{Renderer: render.ProcessRenderer},
renderer: render.FilterUnconnected{Renderer: render.ProcessWithContainerNameRenderer{}},

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

},
"applications-by-name": {
human: "by name",
Expand Down
43 changes: 43 additions & 0 deletions render/topologies.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package render

import (
"fmt"

"github.com/weaveworks/scope/probe/docker"
"github.com/weaveworks/scope/probe/process"
"github.com/weaveworks/scope/report"
)

Expand All @@ -25,6 +29,45 @@ var ProcessRenderer = MakeReduce(
},
)

// ProcessWithContainerNameRenderer is a Renderer which produces a process
// graph enriched with container names where appropriate
type ProcessWithContainerNameRenderer struct{}

// Render produces a process graph where the minor labels contain the
// container name, if found.
func (r ProcessWithContainerNameRenderer) Render(rpt report.Report) RenderableNodes {
var processes = ProcessRenderer.Render(rpt)
var containers = LeafMap{

This comment was marked as abuse.

Selector: report.SelectContainer,
Mapper: MapContainerIdentity,
Pseudo: PanicPseudoNode,
}.Render(rpt)

for id, p := range processes {
pid, ok := p.NodeMetadata.Metadata[process.PID]
if !ok {
continue
}
containerID, ok := p.NodeMetadata.Metadata[docker.ContainerID]
if !ok {
continue
}
container, ok := containers[containerID]
if !ok {
continue
}
p.LabelMinor = fmt.Sprintf("%s (%s:%s)", report.ExtractHostID(p.NodeMetadata), container.LabelMajor, pid)

This comment was marked as abuse.

This comment was marked as abuse.

processes[id] = p
}

return processes
}

// EdgeMetadata produces an EdgeMetadata for a given edge.
func (r ProcessWithContainerNameRenderer) EdgeMetadata(rpt report.Report, localID, remoteID string) report.EdgeMetadata {
return ProcessRenderer.EdgeMetadata(rpt, localID, remoteID)
}

// ProcessRenderer is a Renderer which produces a renderable process
// name graph by munging the progess graph.
var ProcessNameRenderer = Map{
Expand Down