Skip to content

Commit

Permalink
Merge pull request #2450 from weaveworks/mike/docker-swarm/stack-ns
Browse files Browse the repository at this point in the history
swarm service: Capture stack namespace and strip it from name
  • Loading branch information
ekimekim authored Apr 18, 2017
2 parents e8ecfe1 + 72bcdba commit b58832d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion probe/docker/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
IsInHostNetwork = "docker_is_in_host_network"
ImageTableID = "image_table"
ServiceName = "service_name"
StackNamespace = "stack_namespace"
)

// Exposed for testing
Expand Down Expand Up @@ -135,7 +136,8 @@ var (
}

SwarmServiceMetadataTemplates = report.MetadataTemplates{
ServiceName: {ID: ServiceName, Label: "Service Name", From: report.FromLatest, Priority: 0},
ServiceName: {ID: ServiceName, Label: "Service Name", From: report.FromLatest, Priority: 0},
StackNamespace: {ID: StackNamespace, Label: "Stack Namespace", From: report.FromLatest, Priority: 1},
}
)

Expand Down
12 changes: 9 additions & 3 deletions probe/docker/tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,20 @@ func (t *Tagger) Tag(r report.Report) (report.Report, error) {
if !ok {
continue
}
stackNamespace, ok := container.Latest.Lookup(LabelPrefix + "com.docker.stack.namespace")
if !ok {
continue
}

if strings.HasPrefix(serviceName, "dockerswarm_") {
serviceName = serviceName[len("dockerswarm_"):]
prefix := stackNamespace + "_"
if strings.HasPrefix(serviceName, prefix) {
serviceName = serviceName[len(prefix):]
}

nodeID := report.MakeSwarmServiceNodeID(serviceID)
node := report.MakeNodeWith(nodeID, map[string]string{
ServiceName: serviceName,
ServiceName: serviceName,
StackNamespace: stackNamespace,
})
r.SwarmService = r.SwarmService.AddNode(node)

Expand Down

0 comments on commit b58832d

Please sign in to comment.