skip subcontainer update on v2 calls

This commit is contained in:
Seth Jennings 2017-08-17 12:15:22 -05:00
parent 764e91bf16
commit 3ba4699c12
4 changed files with 53 additions and 9 deletions

View File

@ -113,16 +113,18 @@ func (c *containerData) allowErrorLogging() bool {
return false return false
} }
func (c *containerData) GetInfo() (*containerInfo, error) { func (c *containerData) GetInfo(shouldUpdateSubcontainers bool) (*containerInfo, error) {
// Get spec and subcontainers. // Get spec and subcontainers.
if time.Since(c.lastUpdatedTime) > 5*time.Second { if time.Since(c.lastUpdatedTime) > 5*time.Second {
err := c.updateSpec() err := c.updateSpec()
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = c.updateSubcontainers() if shouldUpdateSubcontainers {
if err != nil { err = c.updateSubcontainers()
return nil, err if err != nil {
return nil, err
}
} }
c.lastUpdatedTime = time.Now() c.lastUpdatedTime = time.Now()
} }

View File

@ -174,7 +174,7 @@ func TestGetInfo(t *testing.T) {
) )
mockHandler.Aliases = []string{"a1", "a2"} mockHandler.Aliases = []string{"a1", "a2"}
info, err := cd.GetInfo() info, err := cd.GetInfo(true)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -400,7 +400,7 @@ func (self *manager) GetContainerSpec(containerName string, options v2.RequestOp
var errs partialFailure var errs partialFailure
specs := make(map[string]v2.ContainerSpec) specs := make(map[string]v2.ContainerSpec)
for name, cont := range conts { for name, cont := range conts {
cinfo, err := cont.GetInfo() cinfo, err := cont.GetInfo(false)
if err != nil { if err != nil {
errs.append(name, "GetInfo", err) errs.append(name, "GetInfo", err)
} }
@ -449,7 +449,7 @@ func (self *manager) GetContainerInfoV2(containerName string, options v2.Request
infos := make(map[string]v2.ContainerInfo, len(containers)) infos := make(map[string]v2.ContainerInfo, len(containers))
for name, container := range containers { for name, container := range containers {
result := v2.ContainerInfo{} result := v2.ContainerInfo{}
cinfo, err := container.GetInfo() cinfo, err := container.GetInfo(false)
if err != nil { if err != nil {
errs.append(name, "GetInfo", err) errs.append(name, "GetInfo", err)
infos[name] = result infos[name] = result
@ -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) { func (self *manager) containerDataToContainerInfo(cont *containerData, query *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
// Get the info from the container. // Get the info from the container.
cinfo, err := cont.GetInfo() cinfo, err := cont.GetInfo(true)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -124,6 +124,48 @@ func expectManagerWithContainers(containers []string, query *info.ContainerInfoR
return m, infosMap, handlerMap 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) { func TestGetContainerInfo(t *testing.T) {
containers := []string{ containers := []string{
"/c1", "/c1",
@ -173,7 +215,7 @@ func TestGetContainerInfoV2(t *testing.T) {
NumStats: 2, NumStats: 2,
} }
m, _, handlerMap := expectManagerWithContainers(containers, query, t) m, _, handlerMap := expectManagerWithContainersV2(containers, query, t)
infos, err := m.GetContainerInfoV2("/", options) infos, err := m.GetContainerInfoV2("/", options)
if err != nil { if err != nil {