Show k8s labels and container env vars in the details panel. (#1342)

* Show k8s labels and container env vars in the details panel.

* Add show more bar to the env vars and labels

* React key was in the wrong place; empty tables render section labels.
This commit is contained in:
Tom Wilkie
2016-04-20 08:18:03 +01:00
parent b745411ce1
commit 9eda27822c
18 changed files with 340 additions and 221 deletions

View File

@@ -1,39 +0,0 @@
package detailed
import (
"sort"
"github.com/weaveworks/scope/probe/docker"
"github.com/weaveworks/scope/report"
)
// NodeDockerLabels produces a table (to be consumed directly by the UI) based
// on an origin ID, which is (optimistically) a node ID in one of our
// topologies.
func NodeDockerLabels(nmd report.Node) []report.MetadataRow {
if _, ok := nmd.Counters.Lookup(nmd.Topology); ok {
// This is a group of nodes, so no docker labels!
return nil
}
if nmd.Topology != report.Container && nmd.Topology != report.ContainerImage {
return nil
}
var rows []report.MetadataRow
// Add labels in alphabetical order
labels := docker.ExtractLabels(nmd)
labelKeys := make([]string, 0, len(labels))
for k := range labels {
labelKeys = append(labelKeys, k)
}
sort.Strings(labelKeys)
for _, labelKey := range labelKeys {
rows = append(rows, report.MetadataRow{
ID: "label_" + labelKey,
Label: labelKey,
Value: labels[labelKey],
})
}
return rows
}

View File

@@ -186,12 +186,6 @@ func TestMakeDetailedContainerNode(t *testing.T) {
{ID: "docker_container_state_human", Label: "State", Value: "running", Priority: 2},
{ID: "docker_image_id", Label: "Image ID", Value: fixture.ServerContainerImageID, Priority: 11},
},
DockerLabels: []report.MetadataRow{
{ID: "label_" + detailed.AmazonECSContainerNameLabel, Label: detailed.AmazonECSContainerNameLabel, Value: `server`},
{ID: "label_foo1", Label: "foo1", Value: `bar1`},
{ID: "label_foo2", Label: "foo2", Value: `bar2`},
{ID: "label_io.kubernetes.pod.name", Label: "io.kubernetes.pod.name", Value: "ping/pong-b"},
},
Metrics: []report.MetricRow{
{
ID: docker.CPUTotalUsage,

View File

@@ -61,18 +61,18 @@ type Column struct {
// NodeSummary is summary information about a child for a Node.
type NodeSummary struct {
ID string `json:"id"`
Label string `json:"label"`
LabelMinor string `json:"label_minor"`
Rank string `json:"rank"`
Shape string `json:"shape,omitempty"`
Stack bool `json:"stack,omitempty"`
Linkable bool `json:"linkable,omitempty"` // Whether this node can be linked-to
Pseudo bool `json:"pseudo,omitempty"`
Metadata []report.MetadataRow `json:"metadata,omitempty"`
DockerLabels []report.MetadataRow `json:"docker_labels,omitempty"`
Metrics []report.MetricRow `json:"metrics,omitempty"`
Adjacency report.IDList `json:"adjacency,omitempty"`
ID string `json:"id"`
Label string `json:"label"`
LabelMinor string `json:"label_minor"`
Rank string `json:"rank"`
Shape string `json:"shape,omitempty"`
Stack bool `json:"stack,omitempty"`
Linkable bool `json:"linkable,omitempty"` // Whether this node can be linked-to
Pseudo bool `json:"pseudo,omitempty"`
Metadata []report.MetadataRow `json:"metadata,omitempty"`
Metrics []report.MetricRow `json:"metrics,omitempty"`
Tables []report.Table `json:"tables,omitempty"`
Adjacency report.IDList `json:"adjacency,omitempty"`
}
// MakeNodeSummary summarizes a node, if possible.
@@ -117,8 +117,8 @@ func (n NodeSummary) Copy() NodeSummary {
for _, row := range n.Metadata {
result.Metadata = append(result.Metadata, row.Copy())
}
for _, row := range n.DockerLabels {
result.DockerLabels = append(result.DockerLabels, row.Copy())
for _, table := range n.Tables {
result.Tables = append(result.Tables, table.Copy())
}
for _, row := range n.Metrics {
result.Metrics = append(result.Metrics, row.Copy())
@@ -128,13 +128,13 @@ func (n NodeSummary) Copy() NodeSummary {
func baseNodeSummary(r report.Report, n report.Node) NodeSummary {
return NodeSummary{
ID: n.ID,
Shape: Circle,
Linkable: true,
Metadata: NodeMetadata(r, n),
DockerLabels: NodeDockerLabels(n),
Metrics: NodeMetrics(r, n),
Adjacency: n.Adjacency.Copy(),
ID: n.ID,
Shape: Circle,
Linkable: true,
Metadata: NodeMetadata(r, n),
Metrics: NodeMetrics(r, n),
Tables: NodeTables(r, n),
Adjacency: n.Adjacency.Copy(),
}
}

20
render/detailed/tables.go Normal file
View File

@@ -0,0 +1,20 @@
package detailed
import (
"github.com/weaveworks/scope/report"
)
// NodeTables produces a list of tables (to be consumed directly by the UI) based
// on the report and the node. It uses the report to get the templates for the node's
// topology.
func NodeTables(r report.Report, n report.Node) []report.Table {
if _, ok := n.Counters.Lookup(n.Topology); ok {
// This is a group of nodes, so no tables!
return nil
}
if topology, ok := r.Topology(n.Topology); ok {
return topology.TableTemplates.Tables(n)
}
return nil
}

View File

@@ -11,14 +11,19 @@ import (
"github.com/weaveworks/scope/test/fixture"
)
func TestNodeDockerLabels(t *testing.T) {
func TestNodeTables(t *testing.T) {
inputs := []struct {
name string
rpt report.Report
node report.Node
want []report.MetadataRow
want []report.Table
}{
{
name: "container",
rpt: report.Report{
Container: report.MakeTopology().
WithTableTemplates(docker.ContainerTableTemplates),
},
node: report.MakeNodeWith(fixture.ClientContainerNodeID, map[string]string{
docker.ContainerID: fixture.ClientContainerID,
docker.LabelPrefix + "label1": "label1value",
@@ -26,16 +31,28 @@ func TestNodeDockerLabels(t *testing.T) {
}).WithTopology(report.Container).WithSets(report.EmptySets.
Add(docker.ContainerIPs, report.MakeStringSet("10.10.10.0/24", "10.10.10.1/24")),
),
want: []report.MetadataRow{
want: []report.Table{
{
ID: "label_label1",
Label: "label1",
Value: "label1value",
ID: docker.EnvPrefix,
Label: "Environment Variables",
Rows: []report.MetadataRow{},
},
{
ID: docker.LabelPrefix,
Label: "Docker Labels",
Rows: []report.MetadataRow{
{
ID: "label_label1",
Label: "label1",
Value: "label1value",
},
},
},
},
},
{
name: "unknown topology",
rpt: report.MakeReport(),
node: report.MakeNodeWith(fixture.ClientContainerNodeID, map[string]string{
docker.ContainerID: fixture.ClientContainerID,
}).WithTopology("foobar"),
@@ -43,7 +60,7 @@ func TestNodeDockerLabels(t *testing.T) {
},
}
for _, input := range inputs {
have := detailed.NodeDockerLabels(input.node)
have := detailed.NodeTables(input.rpt, input.node)
if !reflect.DeepEqual(input.want, have) {
t.Errorf("%s: %s", input.name, test.Diff(input.want, have))
}