pinned cadvisor to a latest commit

Signed-off-by: Tarun Pothulapati <tarunpothulapati@outlook.com>
This commit is contained in:
Tarun Pothulapati
2019-08-08 17:56:37 +05:30
parent 6d49d69c91
commit ce31366baf
28 changed files with 165 additions and 525 deletions

View File

@@ -18,8 +18,8 @@ go_library(
"//vendor/github.com/google/cadvisor/utils:go_default_library",
"//vendor/github.com/karrick/godirwalk:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/github.com/sigma/go-inotify:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
"//vendor/k8s.io/utils/inotify:go_default_library",
],
)

View File

@@ -116,6 +116,15 @@ func GetSpec(cgroupPaths map[string]string, machineInfoFactory info.MachineInfoF
}
}
// Processes, read it's value from pids path directly
pidsRoot, ok := cgroupPaths["pids"]
if ok {
if utils.FileExists(pidsRoot) {
spec.HasProcesses = true
spec.Processes.Limit = readUInt64(pidsRoot, "pids.max")
}
}
spec.HasNetwork = hasNetwork
spec.HasFilesystem = hasFilesystem
@@ -143,7 +152,7 @@ func readString(dirpath string, file string) string {
func readUInt64(dirpath string, file string) uint64 {
out := readString(dirpath, file)
if out == "" {
if out == "" || out == "max" {
return 0
}

View File

@@ -17,7 +17,7 @@ package common
import (
"sync"
inotify "github.com/sigma/go-inotify"
inotify "k8s.io/utils/inotify"
)
// Watcher for container-related inotify events in the cgroup hierarchy.
@@ -55,7 +55,7 @@ func (iw *InotifyWatcher) AddWatch(containerName, dir string) (bool, error) {
// Register an inotify notification.
if !cgroupsWatched[dir] {
err := iw.watcher.AddWatch(dir, inotify.IN_CREATE|inotify.IN_DELETE|inotify.IN_MOVE)
err := iw.watcher.AddWatch(dir, inotify.InCreate|inotify.InDelete|inotify.InMove)
if err != nil {
return alreadyWatched, err
}

View File

@@ -6,7 +6,6 @@ go_library(
"handler.go",
"helpers.go",
],
cgo = True,
importmap = "k8s.io/kubernetes/vendor/github.com/google/cadvisor/container/libcontainer",
importpath = "github.com/google/cadvisor/container/libcontainer",
visibility = ["//visibility:public"],
@@ -15,6 +14,7 @@ go_library(
"//vendor/github.com/google/cadvisor/info/v1:go_default_library",
"//vendor/github.com/opencontainers/runc/libcontainer:go_default_library",
"//vendor/github.com/opencontainers/runc/libcontainer/cgroups:go_default_library",
"//vendor/golang.org/x/sys/unix:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
)

View File

@@ -27,18 +27,15 @@ import (
"github.com/google/cadvisor/container"
info "github.com/google/cadvisor/info/v1"
"golang.org/x/sys/unix"
"bytes"
"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/cgroups"
"k8s.io/klog"
)
/*
#include <unistd.h>
*/
import "C"
type Handler struct {
cgroupManager cgroups.Manager
rootFs string
@@ -133,6 +130,9 @@ func (h *Handler) GetStats() (*info.ContainerStats, error) {
klog.V(4).Infof("Unable to get Process Stats: %v", err)
}
}
// if include processes metrics, just set threads metrics if exist, and has no relationship with cpu path
setThreadsStats(cgroupStats, stats)
}
// For backwards compatibility.
@@ -144,7 +144,7 @@ func (h *Handler) GetStats() (*info.ContainerStats, error) {
}
func processStatsFromProcs(rootFs string, cgroupPath string) (info.ProcessStats, error) {
var fdCount uint64
var fdCount, socketCount uint64
filePath := path.Join(cgroupPath, "cgroup.procs")
out, err := ioutil.ReadFile(filePath)
if err != nil {
@@ -168,11 +168,23 @@ func processStatsFromProcs(rootFs string, cgroupPath string) (info.ProcessStats,
continue
}
fdCount += uint64(len(fds))
for _, fd := range fds {
fdPath := path.Join(dirPath, fd.Name())
linkName, err := os.Readlink(fdPath)
if err != nil {
klog.V(4).Infof("error while reading %q link: %v", fdPath, err)
continue
}
if strings.HasPrefix(linkName, "socket") {
socketCount++
}
}
}
processStats := info.ProcessStats{
ProcessCount: uint64(len(pids)),
FdCount: fdCount,
SocketCount: socketCount,
}
return processStats, nil
@@ -514,19 +526,12 @@ func setCpuStats(s *cgroups.Stats, ret *info.ContainerStats, withPerCPU bool) {
}
// Copied from
// https://github.com/moby/moby/blob/8b1adf55c2af329a4334f21d9444d6a169000c81/daemon/stats/collector_unix.go#L73
// Apache 2.0, Copyright Docker, Inc.
func getNumberOnlineCPUs() (uint32, error) {
i, err := C.sysconf(C._SC_NPROCESSORS_ONLN)
// According to POSIX - errno is undefined after successful
// sysconf, and can be non-zero in several cases, so look for
// error in returned value not in errno.
// (https://sourceware.org/bugzilla/show_bug.cgi?id=21536)
if i == -1 {
var availableCPUs unix.CPUSet
if err := unix.SchedGetaffinity(0, &availableCPUs); err != nil {
return 0, err
}
return uint32(i), nil
return uint32(availableCPUs.Count()), nil
}
func setDiskIoStats(s *cgroups.Stats, ret *info.ContainerStats) {
@@ -598,6 +603,15 @@ func setNetworkStats(libcontainerStats *libcontainer.Stats, ret *info.ContainerS
}
}
// read from pids path not cpu
func setThreadsStats(s *cgroups.Stats, ret *info.ContainerStats) {
if s != nil {
ret.Processes.ThreadsCurrent = s.PidsStats.Current
ret.Processes.ThreadsMax = s.PidsStats.Limit
}
}
func newContainerStats(libcontainerStats *libcontainer.Stats, includedMetrics container.MetricSet) *info.ContainerStats {
ret := &info.ContainerStats{
Timestamp: time.Now(),

View File

@@ -106,6 +106,7 @@ var supportedSubsystems map[string]struct{} = map[string]struct{}{
"cpu": {},
"cpuacct": {},
"memory": {},
"pids": {},
"cpuset": {},
"blkio": {},
"devices": {},

View File

@@ -20,8 +20,8 @@ go_library(
"//vendor/github.com/google/cadvisor/watcher:go_default_library",
"//vendor/github.com/opencontainers/runc/libcontainer/cgroups/fs:go_default_library",
"//vendor/github.com/opencontainers/runc/libcontainer/configs:go_default_library",
"//vendor/github.com/sigma/go-inotify:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
"//vendor/k8s.io/utils/inotify:go_default_library",
],
)

View File

@@ -77,6 +77,9 @@ func newRawContainerHandler(name string, cgroupSubsystems *libcontainer.CgroupSu
pid := 0
if isRootCgroup(name) {
pid = 1
// delete pids from cgroup paths because /sys/fs/cgroup/pids/pids.current not exist
delete(cgroupPaths, "pids")
}
handler := libcontainer.NewHandler(cgroupManager, rootFs, pid, includedMetrics)

View File

@@ -26,7 +26,7 @@ import (
"github.com/google/cadvisor/container/common"
"github.com/google/cadvisor/container/libcontainer"
"github.com/google/cadvisor/watcher"
inotify "github.com/sigma/go-inotify"
inotify "k8s.io/utils/inotify"
"k8s.io/klog"
)
@@ -172,13 +172,13 @@ func (self *rawContainerWatcher) processEvent(event *inotify.Event, events chan
// Convert the inotify event type to a container create or delete.
var eventType watcher.ContainerEventType
switch {
case (event.Mask & inotify.IN_CREATE) > 0:
case (event.Mask & inotify.InCreate) > 0:
eventType = watcher.ContainerAdd
case (event.Mask & inotify.IN_DELETE) > 0:
case (event.Mask & inotify.InDelete) > 0:
eventType = watcher.ContainerDelete
case (event.Mask & inotify.IN_MOVED_FROM) > 0:
case (event.Mask & inotify.InMovedFrom) > 0:
eventType = watcher.ContainerDelete
case (event.Mask & inotify.IN_MOVED_TO) > 0:
case (event.Mask & inotify.InMovedTo) > 0:
eventType = watcher.ContainerAdd
default:
// Ignore other events.