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

Allow gathering of stats for root cgroup on v2 #2801

Merged
merged 1 commit into from
Mar 2, 2021
Merged
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
19 changes: 10 additions & 9 deletions container/libcontainer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,22 @@ func NewHandler(cgroupManager cgroups.Manager, rootFs string, pid int, includedM

// Get cgroup and networking stats of the specified container
func (h *Handler) GetStats() (*info.ContainerStats, error) {
var cgroupStats *cgroups.Stats
readCgroupStats := true
ignoreStatsError := false
if cgroups.IsCgroup2UnifiedMode() {
// On cgroup v2 there are no stats at the root cgroup
// so check whether it is the root cgroup
// On cgroup v2 the root cgroup stats have been introduced in recent kernel versions,
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you know from what kernel versions root cgroup stats are supported? That would be good to note.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there has been a floating transition to add various stats to the root cgroups in different versions. I am running mainline right now, and there are still some stats lacking right now as well.

I can do a small digging job, but I guess it will take some time (unless I find the data in a structured format somewhere)... :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

no biggie if it's hard to find, was just curious :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will take a look anyway! Always nice with some background info.

// so not all kernel versions have all the data. This means that stat fetching can fail
// due to lacking cgroup stat files, but that some data is provided.
if h.cgroupManager.Path("") == fs2.UnifiedMountpoint {
readCgroupStats = false
ignoreStatsError = true
}
}
var err error
if readCgroupStats {
cgroupStats, err = h.cgroupManager.GetStats()
if err != nil {

cgroupStats, err := h.cgroupManager.GetStats()
if err != nil {
if !ignoreStatsError {
return nil, err
}
klog.V(4).Infof("Ignoring errors when gathering stats for root cgroup since some controllers don't have stats on the root cgroup: %v", err)
}
libcontainerStats := &libcontainer.Stats{
CgroupStats: cgroupStats,
Expand Down