1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix docker stats show wrong memory limit when do docker update

When a container create with -m 100m and then docker update other
cgroup settings such as --cpu-quota, the memory limit show by
docker stats will become the default value but not the 100m.

Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
Lei Jitang 2015-12-29 20:33:16 -05:00
parent 78ce43bad8
commit 518ed75e1a
2 changed files with 35 additions and 1 deletions

View file

@ -601,7 +601,7 @@ func (container *Container) UpdateContainer(hostConfig *container.HostConfig) er
// the command so we can update configs to the real world. // the command so we can update configs to the real world.
if container.IsRunning() { if container.IsRunning() {
container.Lock() container.Lock()
updateCommand(container.Command, resources) updateCommand(container.Command, *cResources)
container.Unlock() container.Unlock()
} }

View file

@ -3,8 +3,11 @@
package main package main
import ( import (
"encoding/json"
"fmt"
"strings" "strings"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/integration/checker" "github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -160,3 +163,34 @@ func (s *DockerSuite) TestUpdateKernelMemory(c *check.C) {
out, _ = dockerCmd(c, "exec", name, "cat", file) out, _ = dockerCmd(c, "exec", name, "cat", file)
c.Assert(strings.TrimSpace(out), checker.Equals, "104857600") c.Assert(strings.TrimSpace(out), checker.Equals, "104857600")
} }
func (s *DockerSuite) TestUpdateStats(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport)
testRequires(c, cpuCfsQuota)
name := "foo"
dockerCmd(c, "run", "-d", "-ti", "--name", name, "-m", "500m", "busybox")
c.Assert(waitRun(name), checker.IsNil)
getMemLimit := func(id string) uint64 {
resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "")
c.Assert(err, checker.IsNil)
c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
var v *types.Stats
err = json.NewDecoder(body).Decode(&v)
c.Assert(err, checker.IsNil)
body.Close()
return v.MemoryStats.Limit
}
preMemLimit := getMemLimit(name)
dockerCmd(c, "update", "--cpu-quota", "2000", name)
curMemLimit := getMemLimit(name)
c.Assert(preMemLimit, checker.Equals, curMemLimit)
}