Skip to content

Skip subcontainer update on v2 calls #1722

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

Merged
merged 2 commits into from
Aug 18, 2017
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
10 changes: 6 additions & 4 deletions manager/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,18 @@ func (c *containerData) allowErrorLogging() bool {
return false
}

func (c *containerData) GetInfo() (*containerInfo, error) {
func (c *containerData) GetInfo(shouldUpdateSubcontainers bool) (*containerInfo, error) {
// Get spec and subcontainers.
if time.Since(c.lastUpdatedTime) > 5*time.Second {
err := c.updateSpec()
if err != nil {
return nil, err
}
err = c.updateSubcontainers()
if err != nil {
return nil, err
if shouldUpdateSubcontainers {
err = c.updateSubcontainers()
if err != nil {
return nil, err
}
}
c.lastUpdatedTime = time.Now()
}
Expand Down
2 changes: 1 addition & 1 deletion manager/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestGetInfo(t *testing.T) {
)
mockHandler.Aliases = []string{"a1", "a2"}

info, err := cd.GetInfo()
info, err := cd.GetInfo(true)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (self *manager) GetContainerSpec(containerName string, options v2.RequestOp
var errs partialFailure
specs := make(map[string]v2.ContainerSpec)
for name, cont := range conts {
cinfo, err := cont.GetInfo()
cinfo, err := cont.GetInfo(false)
if err != nil {
errs.append(name, "GetInfo", err)
}
Expand Down Expand Up @@ -449,7 +449,7 @@ func (self *manager) GetContainerInfoV2(containerName string, options v2.Request
infos := make(map[string]v2.ContainerInfo, len(containers))
for name, container := range containers {
result := v2.ContainerInfo{}
cinfo, err := container.GetInfo()
cinfo, err := container.GetInfo(false)
if err != nil {
errs.append(name, "GetInfo", err)
infos[name] = result
Expand All @@ -473,7 +473,7 @@ func (self *manager) GetContainerInfoV2(containerName string, options v2.Request

func (self *manager) containerDataToContainerInfo(cont *containerData, query *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
// Get the info from the container.
cinfo, err := cont.GetInfo()
cinfo, err := cont.GetInfo(true)
if err != nil {
return nil, err
}
Expand Down
44 changes: 43 additions & 1 deletion manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,48 @@ func expectManagerWithContainers(containers []string, query *info.ContainerInfoR
return m, infosMap, handlerMap
}

// Expect a manager with the specified containers and query. Returns the manager, map of ContainerInfo objects,
// and map of MockContainerHandler objects.}
func expectManagerWithContainersV2(containers []string, query *info.ContainerInfoRequest, t *testing.T) (*manager, map[string]*info.ContainerInfo, map[string]*containertest.MockContainerHandler) {
infosMap := make(map[string]*info.ContainerInfo, len(containers))
handlerMap := make(map[string]*containertest.MockContainerHandler, len(containers))

for _, container := range containers {
infosMap[container] = itest.GenerateRandomContainerInfo(container, 4, query, 1*time.Second)
}

memoryCache := memory.New(time.Duration(query.NumStats)*time.Second, nil)
sysfs := &fakesysfs.FakeSysFs{}
m := createManagerAndAddContainers(
memoryCache,
sysfs,
containers,
func(h *containertest.MockContainerHandler) {
cinfo := infosMap[h.Name]
ref, err := h.ContainerReference()
if err != nil {
t.Error(err)
}
for _, stat := range cinfo.Stats {
err = memoryCache.AddStats(ref, stat)
if err != nil {
t.Error(err)
}
}
spec := cinfo.Spec

h.On("GetSpec").Return(
spec,
nil,
).Once()
handlerMap[h.Name] = h
},
t,
)

return m, infosMap, handlerMap
}

func TestGetContainerInfo(t *testing.T) {
containers := []string{
"/c1",
Expand Down Expand Up @@ -173,7 +215,7 @@ func TestGetContainerInfoV2(t *testing.T) {
NumStats: 2,
}

m, _, handlerMap := expectManagerWithContainers(containers, query, t)
m, _, handlerMap := expectManagerWithContainersV2(containers, query, t)

infos, err := m.GetContainerInfoV2("/", options)
if err != nil {
Expand Down