Skip to content

Commit

Permalink
Show k8s labels and container env vars in the details panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwilkie committed Apr 19, 2016
1 parent baee925 commit 99e12c2
Show file tree
Hide file tree
Showing 17 changed files with 291 additions and 208 deletions.
10 changes: 5 additions & 5 deletions client/app/scripts/components/node-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ export default class NodeDetails extends React.Component {
</div>
)}

{details.docker_labels && details.docker_labels.length > 0
&& <div className="node-details-content-section">
<div className="node-details-content-section-header">Docker Labels</div>
<NodeDetailsLabels rows={details.docker_labels} />
</div>}
{details.tables && details.tables.length > 0
&& details.tables.map(table => (<div className="node-details-content-section">
<div className="node-details-content-section-header">{table.label}</div>
<NodeDetailsLabels rows={table.rows} />
</div>))}
</div>
</div>
);
Expand Down
19 changes: 17 additions & 2 deletions probe/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ const (

NetworkModeHost = "host"

LabelPrefix = "docker_label_"
EnvPrefix = "docker_env_"

stopTimeout = 10
)

Expand Down Expand Up @@ -323,6 +326,18 @@ func (c *container) metrics() report.Metrics {
return result
}

func (c *container) env() map[string]string {
result := map[string]string{}
for _, value := range c.container.Config.Env {
v := strings.SplitN(value, "=", 2)
if len(v) != 2 {
continue
}
result[v[0]] = v[1]
}
return result
}

func (c *container) GetNode(hostID string, localAddrs []net.IP) report.Node {
c.RLock()
defer c.RUnlock()
Expand Down Expand Up @@ -376,8 +391,8 @@ func (c *container) GetNode(hostID string, localAddrs []net.IP) report.Node {
result = result.WithControls(StartContainer)
}

result = AddLabels(result, c.container.Config.Labels)
result = AddEnv(result, c.container.Config.Env)
result = result.AddTable(LabelPrefix, c.container.Config.Labels)
result = result.AddTable(EnvPrefix, c.env())
result = result.WithMetrics(c.metrics())
return result
}
Expand Down
39 changes: 0 additions & 39 deletions probe/docker/env.go

This file was deleted.

38 changes: 0 additions & 38 deletions probe/docker/env_test.go

This file was deleted.

35 changes: 0 additions & 35 deletions probe/docker/labels.go

This file was deleted.

18 changes: 15 additions & 3 deletions probe/docker/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ var (
ImageID: {ID: ImageID, Label: "Image ID", From: report.FromLatest, Truncate: 12, Priority: 1},
report.Container: {ID: report.Container, Label: "# Containers", From: report.FromCounters, Datatype: "number", Priority: 2},
}

ContainerTableTemplates = report.TableTemplates{
LabelPrefix: {ID: LabelPrefix, Label: "Docker Labels", Prefix: LabelPrefix},
EnvPrefix: {ID: EnvPrefix, Label: "Environment Variables", Prefix: EnvPrefix},
}

ContainerImageTableTemplates = report.TableTemplates{
LabelPrefix: {ID: LabelPrefix, Label: "Docker Labels", Prefix: LabelPrefix},
}
)

// Reporter generate Reports containing Container and ContainerImage topologies
Expand Down Expand Up @@ -96,7 +105,8 @@ func (r *Reporter) Report() (report.Report, error) {
func (r *Reporter) containerTopology(localAddrs []net.IP) report.Topology {
result := report.MakeTopology().
WithMetadataTemplates(ContainerMetadataTemplates).
WithMetricTemplates(ContainerMetricTemplates)
WithMetricTemplates(ContainerMetricTemplates).
WithTableTemplates(ContainerTableTemplates)
result.Controls.AddControl(report.Control{
ID: StopContainer,
Human: "Stop",
Expand Down Expand Up @@ -144,14 +154,16 @@ func (r *Reporter) containerTopology(localAddrs []net.IP) report.Topology {
}

func (r *Reporter) containerImageTopology() report.Topology {
result := report.MakeTopology().WithMetadataTemplates(ContainerImageMetadataTemplates)
result := report.MakeTopology().
WithMetadataTemplates(ContainerImageMetadataTemplates).
WithTableTemplates(ContainerImageTableTemplates)

r.registry.WalkImages(func(image *docker_client.APIImages) {
imageID := trimImageID(image.ID)
node := report.MakeNodeWith(map[string]string{
ImageID: imageID,
})
node = AddLabels(node, image.Labels)
node = node.AddTable(LabelPrefix, image.Labels)

if len(image.RepoTags) > 0 {
node = node.WithLatests(map[string]string{ImageName: image.RepoTags[0]})
Expand Down
3 changes: 2 additions & 1 deletion probe/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
PodCreated = "kubernetes_pod_created"
PodContainerIDs = "kubernetes_pod_container_ids"
PodState = "kubernetes_pod_state"
PodLabelPrefix = "kubernetes_pod_labels_"
ServiceIDs = "kubernetes_service_ids"
)

Expand Down Expand Up @@ -99,5 +100,5 @@ func (p *pod) GetNode() report.Node {
Add(report.Service, report.MakeStringSet(report.MakeServiceNodeID(p.Namespace(), segments[1]))),
)
}
return n
return n.AddTable(PodLabelPrefix, p.ObjectMeta.Labels)
}
16 changes: 14 additions & 2 deletions probe/kubernetes/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ var (
ServiceCreated: {ID: ServiceCreated, Label: "Created", From: report.FromLatest, Priority: 3},
ServiceIP: {ID: ServiceIP, Label: "Internal IP", From: report.FromLatest, Priority: 4},
}

PodTableTemplates = report.TableTemplates{
PodLabelPrefix: {ID: PodLabelPrefix, Label: "Kubernetes Labels", Prefix: PodLabelPrefix},
}

ServiceTableTemplates = report.TableTemplates{
ServiceLabelPrefix: {ID: ServiceLabelPrefix, Label: "Kubernetes Labels", Prefix: ServiceLabelPrefix},
}
)

// Reporter generate Reports containing Container and ContainerImage topologies
Expand Down Expand Up @@ -58,7 +66,9 @@ func (r *Reporter) Report() (report.Report, error) {

func (r *Reporter) serviceTopology() (report.Topology, []Service, error) {
var (
result = report.MakeTopology().WithMetadataTemplates(ServiceMetadataTemplates)
result = report.MakeTopology().
WithMetadataTemplates(ServiceMetadataTemplates).
WithTableTemplates(ServiceTableTemplates)
services = []Service{}
)
err := r.client.WalkServices(func(s Service) error {
Expand All @@ -72,7 +82,9 @@ func (r *Reporter) serviceTopology() (report.Topology, []Service, error) {

func (r *Reporter) podTopology(services []Service) (report.Topology, report.Topology, error) {
var (
pods = report.MakeTopology().WithMetadataTemplates(PodMetadataTemplates)
pods = report.MakeTopology().
WithMetadataTemplates(PodMetadataTemplates).
WithTableTemplates(PodTableTemplates)
containers = report.MakeTopology()
selectors = map[string]labels.Selector{}
)
Expand Down
11 changes: 6 additions & 5 deletions probe/kubernetes/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (

// These constants are keys used in node metadata
const (
ServiceID = "kubernetes_service_id"
ServiceName = "kubernetes_service_name"
ServiceCreated = "kubernetes_service_created"
ServiceIP = "kubernetes_service_ip"
ServiceID = "kubernetes_service_id"
ServiceName = "kubernetes_service_name"
ServiceCreated = "kubernetes_service_created"
ServiceIP = "kubernetes_service_ip"
ServiceLabelPrefix = "kubernetes_service_label_"
)

// Service represents a Kubernetes service
Expand Down Expand Up @@ -60,5 +61,5 @@ func (s *service) GetNode() report.Node {
ServiceCreated: s.ObjectMeta.CreationTimestamp.Format(time.RFC822),
Namespace: s.Namespace(),
ServiceIP: s.Spec.ClusterIP,
})
}).AddTable(ServiceLabelPrefix, s.Labels)
}
39 changes: 0 additions & 39 deletions render/detailed/docker_labels.go

This file was deleted.

6 changes: 0 additions & 6 deletions render/detailed/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 99e12c2

Please sign in to comment.