Skip to content

Commit

Permalink
manager: simplify createContainer
Browse files Browse the repository at this point in the history
The code to initialize perf collector is almost the same between cgroup
v1 and v2, the only difference is how we get cgroup path. Since now
GetCgroupPath is v2 ready, we can use it, and thus unify these two
cases.

This commit is best reviewed with --ignore-space-change.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin authored and Paweł Szulik committed Oct 21, 2021
1 parent c985f28 commit 3beb265
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
2 changes: 0 additions & 2 deletions cmd/internal/container/mesos/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (

mesos "github.com/mesos/mesos-go/api/v1/lib"
"github.com/stretchr/testify/assert"

containerlibcontainer "github.com/google/cadvisor/container/libcontainer"
)

func TestIsContainerName(t *testing.T) {
Expand Down
27 changes: 9 additions & 18 deletions manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import (
"github.com/google/cadvisor/watcher"

"github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/opencontainers/runc/libcontainer/cgroups/fs2"

"k8s.io/klog/v2"
"k8s.io/utils/clock"
Expand Down Expand Up @@ -937,15 +936,7 @@ func (m *manager) createContainerLocked(containerName string, watchSource watche
return err
}

if cgroups.IsCgroup2UnifiedMode() {
if m.includedMetrics.Has(container.PerfMetrics) {
perfCgroupPath := path.Join(fs2.UnifiedMountpoint, containerName)
cont.perfCollector, err = m.perfManager.GetCollector(perfCgroupPath)
if err != nil {
klog.Errorf("Perf event metrics will not be available for container %q: %v", containerName, err)
}
}
} else {
if !cgroups.IsCgroup2UnifiedMode() {
devicesCgroupPath, err := handler.GetCgroupPath("devices")
if err != nil {
klog.Warningf("Error getting devices cgroup path: %v", err)
Expand All @@ -955,15 +946,15 @@ func (m *manager) createContainerLocked(containerName string, watchSource watche
klog.V(4).Infof("GPU metrics may be unavailable/incomplete for container %s: %s", cont.info.Name, err)
}
}
if m.includedMetrics.Has(container.PerfMetrics) {
perfCgroupPath, err := handler.GetCgroupPath("perf_event")
}
if m.includedMetrics.Has(container.PerfMetrics) {
perfCgroupPath, err := handler.GetCgroupPath("perf_event")
if err != nil {
klog.Warningf("Error getting perf_event cgroup path: %q", err)
} else {
cont.perfCollector, err = m.perfManager.GetCollector(perfCgroupPath)
if err != nil {
klog.Warningf("Error getting perf_event cgroup path: %q", err)
} else {
cont.perfCollector, err = m.perfManager.GetCollector(perfCgroupPath)
if err != nil {
klog.Errorf("Perf event metrics will not be available for container %q: %v", containerName, err)
}
klog.Errorf("Perf event metrics will not be available for container %q: %v", containerName, err)
}
}
}
Expand Down

0 comments on commit 3beb265

Please sign in to comment.