diff --git a/container/container.go b/container/container.go index 7d21d1d1..ecec1706 100644 --- a/container/container.go +++ b/container/container.go @@ -32,7 +32,7 @@ type ListType int type ContainerHandler interface { GetSpec() (*info.ContainerSpec, error) GetStats() (*info.ContainerStats, error) - ListContainers(listType ListType) ([]string, error) + ListContainers(listType ListType) ([]info.ContainerRef, error) ListThreads(listType ListType) ([]int, error) ListProcesses(listType ListType) ([]int, error) StatsSummary() (*info.ContainerStatsPercentiles, error) diff --git a/container/filter.go b/container/filter.go index 0495bdc7..b1ed38c5 100644 --- a/container/filter.go +++ b/container/filter.go @@ -34,7 +34,7 @@ func (self *containerListFilter) GetStats() (*info.ContainerStats, error) { return self.handler.GetStats() } -func (self *containerListFilter) ListContainers(listType ListType) ([]string, error) { +func (self *containerListFilter) ListContainers(listType ListType) ([]info.ContainerRef, error) { containers, err := self.handler.ListContainers(listType) if err != nil { return nil, err @@ -42,9 +42,9 @@ func (self *containerListFilter) ListContainers(listType ListType) ([]string, er if len(containers) == 0 { return nil, nil } - ret := make([]string, 0, len(containers)) + ret := make([]info.ContainerRef, 0, len(containers)) for _, c := range containers { - if self.filter(c) { + if self.filter(c.Name) { ret = append(ret, c) } } diff --git a/container/filter_test.go b/container/filter_test.go index b6c2d41a..3c4250d8 100644 --- a/container/filter_test.go +++ b/container/filter_test.go @@ -37,9 +37,9 @@ func (self *mockContainerHandler) GetStats() (*info.ContainerStats, error) { return args.Get(0).(*info.ContainerStats), args.Error(1) } -func (self *mockContainerHandler) ListContainers(listType ListType) ([]string, error) { +func (self *mockContainerHandler) ListContainers(listType ListType) ([]info.ContainerRef, error) { args := self.Called(listType) - return args.Get(0).([]string), args.Error(1) + return args.Get(0).([]info.ContainerRef), args.Error(1) } func (self *mockContainerHandler) ListThreads(listType ListType) ([]int, error) { @@ -55,10 +55,10 @@ func (self *mockContainerHandler) ListProcesses(listType ListType) ([]int, error func TestWhiteListContainerFilter(t *testing.T) { mockc := &mockContainerHandler{} mockc.On("ListContainers", LIST_RECURSIVE).Return( - []string{ - "/docker/ee0103", - "/container/created/by/lmctfy", - "/user/something", + []info.ContainerRef{ + info.ContainerRef{Name: "/docker/ee0103"}, + info.ContainerRef{Name: "/container/created/by/lmctfy"}, + info.ContainerRef{Name: "/user/something"}, }, nil, ) @@ -76,7 +76,7 @@ func TestWhiteListContainerFilter(t *testing.T) { for _, c := range containers { legal := false for _, prefix := range filterPaths { - if strings.HasPrefix(c, prefix) { + if strings.HasPrefix(c.Name, prefix) { legal = true } } @@ -90,10 +90,10 @@ func TestWhiteListContainerFilter(t *testing.T) { func TestBlackListContainerFilter(t *testing.T) { mockc := &mockContainerHandler{} mockc.On("ListContainers", LIST_RECURSIVE).Return( - []string{ - "/docker/ee0103", - "/container/created/by/lmctfy", - "/user/something", + []info.ContainerRef{ + info.ContainerRef{Name: "/docker/ee0103"}, + info.ContainerRef{Name: "/container/created/by/lmctfy"}, + info.ContainerRef{Name: "/user/something"}, }, nil, ) @@ -111,7 +111,7 @@ func TestBlackListContainerFilter(t *testing.T) { for _, c := range containers { legal := true for _, prefix := range filterPaths { - if strings.HasPrefix(c, prefix) { + if strings.HasPrefix(c.Name, prefix) { legal = false } } diff --git a/container/statssum.go b/container/statssum.go index 081e6667..b18c7222 100644 --- a/container/statssum.go +++ b/container/statssum.go @@ -94,7 +94,7 @@ func (self *percentilesContainerHandlerWrapper) GetStats() (*info.ContainerStats return stats, nil } -func (self *percentilesContainerHandlerWrapper) ListContainers(listType ListType) ([]string, error) { +func (self *percentilesContainerHandlerWrapper) ListContainers(listType ListType) ([]info.ContainerRef, error) { return self.handler.ListContainers(listType) } diff --git a/container/statssum_test.go b/container/statssum_test.go index 0c020e12..995a29fc 100644 --- a/container/statssum_test.go +++ b/container/statssum_test.go @@ -29,7 +29,7 @@ type mockContainer struct { func (self *mockContainer) GetSpec() (*info.ContainerSpec, error) { return nil, nil } -func (self *mockContainer) ListContainers(listType ListType) ([]string, error) { +func (self *mockContainer) ListContainers(listType ListType) ([]info.ContainerRef, error) { return nil, nil } diff --git a/info/container.go b/info/container.go index fe9245b0..d288494d 100644 --- a/info/container.go +++ b/info/container.go @@ -49,12 +49,19 @@ type ContainerSpec struct { Memory *MemorySpec `json:"memory,omitempty"` } -type ContainerInfo struct { +// Container reference contains enough information to uniquely identify a container +type ContainerRef struct { // The absolute name of the container. Name string `json:"name"` + Aliases []string `json:"aliases,omitempty"` +} + +type ContainerInfo struct { + ContainerRef + // The direct subcontainers of the current container. - Subcontainers []string `json:"subcontainers,omitempty"` + Subcontainers []ContainerRef `json:"subcontainers,omitempty"` // The isolation used in the container. Spec *ContainerSpec `json:"spec,omitempty"` diff --git a/info/container_test.go b/info/container_test.go index bf449a4e..a0e67755 100644 --- a/info/container_test.go +++ b/info/container_test.go @@ -30,7 +30,9 @@ func TestStatsStartTime(t *testing.T) { stats = append(stats, s) } cinfo := &ContainerInfo{ - Name: "/some/container", + ContainerRef: ContainerRef{ + Name: "/some/container", + }, Stats: stats, } ref := ct.Add(time.Duration(N-1) * time.Second) @@ -52,7 +54,9 @@ func TestStatsEndTime(t *testing.T) { stats = append(stats, s) } cinfo := &ContainerInfo{ - Name: "/some/container", + ContainerRef: ContainerRef{ + Name: "/some/container", + }, Stats: stats, } ref := ct