Add useful information to table titles in details pane

Title modifications:
* "Origin Process" -> "Process \"name\" (pid)"
* "Origin Container" -> "Container \"name\" (pid)"
* "Origin Host" -> "Host \"name\""
* "Origin Container Image" -> "Container Image \"name\""
This commit is contained in:
Alfonso Acosta
2015-08-21 16:03:45 +00:00
parent a01a7069b6
commit 75595a5519
2 changed files with 60 additions and 45 deletions

View File

@@ -230,8 +230,6 @@ func connectionDetailsRows(topology report.Topology, originID string) []Row {
func processOriginTable(nmd report.NodeMetadata, addHostTag bool) (Table, bool) {
rows := []Row{}
for _, tuple := range []struct{ key, human string }{
{process.Comm, "Name"},
{process.PID, "PID"},
{process.PPID, "Parent PID"},
{process.Cmdline, "Command"},
{process.Threads, "# Threads"},
@@ -243,19 +241,30 @@ func processOriginTable(nmd report.NodeMetadata, addHostTag bool) (Table, bool)
if addHostTag {
rows = append([]Row{{Key: "Host", ValueMajor: report.ExtractHostID(nmd)}}, rows...)
}
title := "Process"
var (
commFound, pidFound bool
name, pid string
)
if name, commFound = nmd.Metadata[process.Comm]; commFound {
title += ` "` + name + `"`
}
if pid, pidFound = nmd.Metadata[process.PID]; pidFound {
title += " (" + pid + ")"
}
return Table{
Title: "Origin Process",
Title: title,
Numeric: false,
Rows: rows,
Rank: processRank,
}, len(rows) > 0
}, len(rows) > 0 || commFound || pidFound
}
func containerOriginTable(nmd report.NodeMetadata, addHostTag bool) (Table, bool) {
rows := []Row{}
for _, tuple := range []struct{ key, human string }{
{docker.ContainerID, "ID"},
{docker.ContainerName, "Name"},
{docker.ImageID, "Image ID"},
{docker.ContainerPorts, "Ports"},
{docker.ContainerCreated, "Created"},
@@ -276,36 +285,52 @@ func containerOriginTable(nmd report.NodeMetadata, addHostTag bool) (Table, bool
if addHostTag {
rows = append([]Row{{Key: "Host", ValueMajor: report.ExtractHostID(nmd)}}, rows...)
}
title := "Container"
var (
name string
nameFound bool
)
if name, nameFound = nmd.Metadata[docker.ContainerName]; nameFound {
title += ` "` + name + `"`
}
return Table{
Title: "Origin Container",
Title: title,
Numeric: false,
Rows: rows,
Rank: containerRank,
}, len(rows) > 0
}, len(rows) > 0 || nameFound
}
func containerImageOriginTable(nmd report.NodeMetadata) (Table, bool) {
rows := []Row{}
for _, tuple := range []struct{ key, human string }{
{docker.ImageID, "Image ID"},
{docker.ImageName, "Image name"},
} {
if val, ok := nmd.Metadata[tuple.key]; ok {
rows = append(rows, Row{Key: tuple.human, ValueMajor: val, ValueMinor: ""})
}
}
title := "Container Image"
var (
nameFound bool
name string
)
if name, nameFound = nmd.Metadata[docker.ImageName]; nameFound {
title += ` "` + name + `"`
}
return Table{
Title: "Origin Container Image",
Title: title,
Numeric: false,
Rows: rows,
Rank: containerImageRank,
}, len(rows) > 0
}, len(rows) > 0 || nameFound
}
func hostOriginTable(nmd report.NodeMetadata) (Table, bool) {
rows := []Row{}
for _, tuple := range []struct{ key, human string }{
{host.HostName, "Host name"},
{host.Load, "Load"},
{host.OS, "Operating system"},
{host.KernelVersion, "Kernel version"},
@@ -316,10 +341,18 @@ func hostOriginTable(nmd report.NodeMetadata) (Table, bool) {
}
}
title := "Host"
var (
name string
foundName bool
)
if name, foundName = nmd.Metadata[host.HostName]; foundName {
title += ` "` + name + `"`
}
return Table{
Title: "Origin Host",
Title: title,
Numeric: false,
Rows: rows,
Rank: hostRank,
}, len(rows) > 0
}, len(rows) > 0 || foundName
}

View File

@@ -13,22 +13,17 @@ func TestOriginTable(t *testing.T) {
if _, ok := render.OriginTable(test.Report, "not-found", false); ok {
t.Errorf("unknown origin ID gave unexpected success")
}
for originID, want := range map[string]render.Table{
test.ServerProcessNodeID: {
Title: "Origin Process",
Numeric: false,
Rank: 2,
Rows: []render.Row{
{"Name", "apache", "", false},
{"PID", test.ServerPID, "", false},
},
},
for originID, want := range map[string]render.Table{test.ServerProcessNodeID: {
Title: fmt.Sprintf(`Process "apache" (%s)`, test.ServerPID),
Numeric: false,
Rank: 2,
Rows: []render.Row{},
},
test.ServerHostNodeID: {
Title: "Origin Host",
Title: fmt.Sprintf("Host %q", test.ServerHostName),
Numeric: false,
Rank: 1,
Rows: []render.Row{
{"Host name", test.ServerHostName, "", false},
{"Load", "0.01 0.01 0.01", "", false},
{"Operating system", "Linux", "", false},
},
@@ -47,23 +42,20 @@ func TestOriginTable(t *testing.T) {
// Test host tags
for originID, want := range map[string]render.Table{
test.ServerProcessNodeID: {
Title: "Origin Process",
Title: fmt.Sprintf(`Process "apache" (%s)`, test.ServerPID),
Numeric: false,
Rank: 2,
Rows: []render.Row{
{"Host", test.ServerHostID, "", false},
{"Name", "apache", "", false},
{"PID", test.ServerPID, "", false},
},
},
test.ServerContainerNodeID: {
Title: "Origin Container",
Title: `Container "server"`,
Numeric: false,
Rank: 3,
Rows: []render.Row{
{"Host", test.ServerHostID, "", false},
{"ID", test.ServerContainerID, "", false},
{"Name", "server", "", false},
{"Image ID", test.ServerContainerImageID, "", false},
},
},
@@ -90,15 +82,10 @@ func TestMakeDetailedHostNode(t *testing.T) {
Pseudo: false,
Tables: []render.Table{
{
Title: "Origin Host",
Title: fmt.Sprintf("Host %q", test.ClientHostName),
Numeric: false,
Rank: 1,
Rows: []render.Row{
{
Key: "Host name",
ValueMajor: "client.hostname.com",
ValueMinor: "",
},
{
Key: "Load",
ValueMajor: "0.01 0.01 0.01",
@@ -152,30 +139,25 @@ func TestMakeDetailedContainerNode(t *testing.T) {
Pseudo: false,
Tables: []render.Table{
{
Title: "Origin Container",
Title: `Container "server"`,
Numeric: false,
Rank: 3,
Rows: []render.Row{
{"ID", test.ServerContainerID, "", false},
{"Name", "server", "", false},
{"Image ID", test.ServerContainerImageID, "", false},
},
},
{
Title: "Origin Process",
Title: fmt.Sprintf(`Process "apache" (%s)`, test.ServerPID),
Numeric: false,
Rank: 2,
Rows: []render.Row{
{"Name", "apache", "", false},
{"PID", test.ServerPID, "", false},
},
Rows: []render.Row{},
},
{
Title: "Origin Host",
Title: fmt.Sprintf("Host %q", test.ServerHostName),
Numeric: false,
Rank: 1,
Rows: []render.Row{
{"Host name", test.ServerHostName, "", false},
{"Load", "0.01 0.01 0.01", "", false},
{"Operating system", "Linux", "", false},
},