Skip to content
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

Ignore any .mount cgroup in docker #1573

Merged
merged 1 commit into from
Jan 16, 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
16 changes: 10 additions & 6 deletions container/docker/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,21 @@ func ContainerNameToDockerId(name string) string {
return id
}

// isContainerName returns true if the cgroup with associated name
// corresponds to a docker container.
func isContainerName(name string) bool {
// always ignore .mount cgroup even if associated with docker and delegate to systemd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cadvisor will log Error trying to work out if we can handle containerName: error, which seems misleading. How about changing this so that CanHandleAndAccept return (true, false, nil) or (false, false, nil)` instead?

I also think the caller of CanHandleAndAccept logs way too many errors periodically...but that's another issue.

if strings.HasSuffix(name, ".mount") {
return false
}
return dockerCgroupRegexp.MatchString(path.Base(name))
}

// Docker handles all containers under /docker
func (self *dockerFactory) CanHandleAndAccept(name string) (bool, bool, error) {
// docker factory accepts all containers it can handle.
canAccept := true

// if the container is not associated with docker, we can't handle it or accept it.
if !isContainerName(name) {
return false, canAccept, fmt.Errorf("invalid container name")
return false, false, nil
}

// Check if the container is known to docker and it is active.
Expand All @@ -160,10 +164,10 @@ func (self *dockerFactory) CanHandleAndAccept(name string) (bool, bool, error) {
// We assume that if Inspect fails then the container is not known to docker.
ctnr, err := self.client.ContainerInspect(context.Background(), id)
if err != nil || !ctnr.State.Running {
return false, canAccept, fmt.Errorf("error inspecting container: %v", err)
return false, true, fmt.Errorf("error inspecting container: %v", err)
}

return true, canAccept, nil
return true, true, nil
}

func (self *dockerFactory) DebugInfo() map[string][]string {
Expand Down
21 changes: 21 additions & 0 deletions container/docker/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,24 @@ func TestEnsureThinLsKernelVersion(t *testing.T) {
}
}
}

func TestIsContainerName(t *testing.T) {
tests := []struct {
name string
expected bool
}{
{
name: "/system.slice/var-lib-docker-overlay-9f086b233ab7c786bf8b40b164680b658a8f00e94323868e288d6ce20bc92193-merged.mount",
expected: false,
},
{
name: "/system.slice/docker-72e5a5ff5eef3c4222a6551b992b9360a99122f77d2229783f0ee0946dfd800e.scope",
expected: true,
},
}
for _, test := range tests {
if actual := isContainerName(test.name); actual != test.expected {
t.Errorf("%s: expected: %v, actual: %v", test.name, test.expected, actual)
}
}
}