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

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

Merged
merged 3 commits into from
Apr 20, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 11 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,17 @@ 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 => {
if (table.rows.length > 0) {
return (
<div className="node-details-content-section" key={table.id}>
<div className="node-details-content-section-header">{table.label}</div>
<NodeDetailsLabels rows={table.rows} />
</div>
);
}
return null;
})}
</div>
</div>
);
Expand Down
56 changes: 43 additions & 13 deletions client/app/scripts/components/node-details/node-details-labels.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
import React from 'react';

export default function NodeDetailsLabels({rows}) {
return (
<div className="node-details-labels">
{rows.map(field => (<div className="node-details-labels-field" key={field.id}>
<div className="node-details-labels-field-label truncate" title={field.label}>
{field.label}
</div>
<div className="node-details-labels-field-value truncate" title={field.value}>
{field.value}
import ShowMore from '../show-more';

export default class NodeDetailsLabels extends React.Component {

constructor(props, context) {
super(props, context);
this.DEFAULT_LIMIT = 5;
this.state = {
limit: this.DEFAULT_LIMIT,
};
this.handleLimitClick = this.handleLimitClick.bind(this);
}

handleLimitClick() {
const limit = this.state.limit ? 0 : this.DEFAULT_LIMIT;
this.setState({limit});
}

render() {
let rows = this.props.rows;
const limited = rows && this.state.limit > 0 && rows.length > this.state.limit;
const expanded = this.state.limit === 0;
const notShown = rows.length - this.DEFAULT_LIMIT;
if (rows && limited) {
rows = rows.slice(0, this.state.limit);
}

return (
<div className="node-details-labels">
{rows.map(field => (<div className="node-details-labels-field" key={field.id}>
<div className="node-details-labels-field-label truncate" title={field.label}
key={field.id}>
{field.label}
</div>
<div className="node-details-labels-field-value truncate" title={field.value}>
{field.value}
</div>
</div>
</div>
))}
</div>
);
))}
<ShowMore handleClick={this.handleLimitClick} collection={this.props.rows}
expanded={expanded} notShown={notShown} />
</div>
);
}
}
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 @@ -143,15 +153,17 @@ 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)
nodeID := report.MakeContainerImageNodeID(imageID)
node := report.MakeNodeWith(nodeID, 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 @@ -71,7 +81,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.

Loading