mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 09:41:57 +00:00
Use image name without version as id. (#1531)
* Use image name without version as id. * Review feedback
This commit is contained in:
@@ -43,6 +43,7 @@ type Registry interface {
|
||||
WatchContainerUpdates(ContainerUpdateWatcher)
|
||||
GetContainer(string) (Container, bool)
|
||||
GetContainerByPrefix(string) (Container, bool)
|
||||
GetContainerImage(string) (*docker_client.APIImages, bool)
|
||||
}
|
||||
|
||||
// ContainerUpdateWatcher is the type of functions that get called when containers are updated.
|
||||
@@ -390,6 +391,13 @@ func (r *registry) GetContainerByPrefix(prefix string) (Container, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (r *registry) GetContainerImage(id string) (*docker_client.APIImages, bool) {
|
||||
r.RLock()
|
||||
defer r.RUnlock()
|
||||
image, ok := r.images[id]
|
||||
return image, ok
|
||||
}
|
||||
|
||||
// WalkImages runs f on every image of running containers the registry
|
||||
// knows of. f may be run on the same image more than once.
|
||||
func (r *registry) WalkImages(f func(*docker_client.APIImages)) {
|
||||
|
||||
@@ -38,7 +38,7 @@ var (
|
||||
}
|
||||
|
||||
ContainerImageMetadataTemplates = report.MetadataTemplates{
|
||||
ImageID: {ID: ImageID, Label: "Image ID", From: report.FromLatest, Truncate: 12, Priority: 1},
|
||||
ImageID: {ID: ImageID, Label: "Image ID", From: report.FromSets, Truncate: 12, Priority: 1},
|
||||
report.Container: {ID: report.Container, Label: "# Containers", From: report.FromCounters, Datatype: "number", Priority: 2},
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,11 @@ func (r *mockRegistry) GetContainer(_ string) (docker.Container, bool) { return
|
||||
|
||||
func (r *mockRegistry) GetContainerByPrefix(_ string) (docker.Container, bool) { return nil, false }
|
||||
|
||||
func (r *mockRegistry) GetContainerImage(id string) (*client.APIImages, bool) {
|
||||
image, ok := r.images[id]
|
||||
return image, ok
|
||||
}
|
||||
|
||||
var (
|
||||
mockRegistryInstance = &mockRegistry{
|
||||
containersByPID: map[int]docker.Container{
|
||||
|
||||
@@ -82,12 +82,21 @@ func (t *Tagger) tag(tree process.Tree, topology *report.Topology) {
|
||||
continue
|
||||
}
|
||||
|
||||
topology.AddNode(report.MakeNodeWith(nodeID, map[string]string{
|
||||
node := report.MakeNodeWith(nodeID, map[string]string{
|
||||
ContainerID: c.ID(),
|
||||
}).WithParents(report.EmptySets.
|
||||
Add(report.Container, report.MakeStringSet(report.MakeContainerNodeID(c.ID()))).
|
||||
Add(report.ContainerImage, report.MakeStringSet(report.MakeContainerImageNodeID(c.Image()))),
|
||||
))
|
||||
Add(report.Container, report.MakeStringSet(report.MakeContainerNodeID(c.ID()))),
|
||||
)
|
||||
|
||||
// If we can work out the image name, add a parent tag for it
|
||||
image, ok := t.registry.GetContainerImage(c.Image())
|
||||
if ok && len(image.RepoTags) > 0 {
|
||||
imageName := ImageNameWithoutVersion(image.RepoTags[0])
|
||||
node = node.WithParents(report.EmptySets.
|
||||
Add(report.ContainerImage, report.MakeStringSet(report.MakeContainerImageNodeID(imageName))),
|
||||
)
|
||||
}
|
||||
|
||||
topology.AddNode(node)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,8 +70,8 @@ func TestTagger(t *testing.T) {
|
||||
}
|
||||
|
||||
// node should have the container image as a parent
|
||||
if have, ok := node.Parents.Lookup(report.ContainerImage); !ok || !have.Contains(report.MakeContainerImageNodeID("baz")) {
|
||||
t.Errorf("Expected process node %s to have container image %q as a parent, got %q", nodeID, "baz", have)
|
||||
if have, ok := node.Parents.Lookup(report.ContainerImage); !ok || !have.Contains(report.MakeContainerImageNodeID("bang")) {
|
||||
t.Errorf("Expected process node %s to have container image %q as a parent, got %q", nodeID, "bang", have)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user