Merge pull request #72787 from dashpole/cadvisor_prefix_whitelist

Only collect metrics for cgroups required by the summary API
This commit is contained in:
Kubernetes Prow Robot
2019-05-31 00:28:26 -07:00
committed by GitHub
7 changed files with 80 additions and 8 deletions

View File

@@ -82,7 +82,7 @@ func init() {
}
}
func New(imageFsInfoProvider ImageFsInfoProvider, rootPath string, usingLegacyStats bool) (Interface, error) {
func New(imageFsInfoProvider ImageFsInfoProvider, rootPath string, cgroupRoots []string, usingLegacyStats bool) (Interface, error) {
sysFs := sysfs.NewRealSysFs()
includedMetrics := cadvisormetrics.MetricSet{
@@ -98,10 +98,8 @@ func New(imageFsInfoProvider ImageFsInfoProvider, rootPath string, usingLegacySt
includedMetrics[cadvisormetrics.DiskUsageMetrics] = struct{}{}
}
// collect metrics for all cgroups
rawContainerCgroupPathPrefixWhiteList := []string{"/"}
// Create and start the cAdvisor container manager.
m, err := manager.New(memory.New(statsCacheDuration, nil), sysFs, maxHousekeepingInterval, allowDynamicHousekeeping, includedMetrics, http.DefaultClient, rawContainerCgroupPathPrefixWhiteList)
m, err := manager.New(memory.New(statsCacheDuration, nil), sysFs, maxHousekeepingInterval, allowDynamicHousekeeping, includedMetrics, http.DefaultClient, cgroupRoots)
if err != nil {
return nil, err
}

View File

@@ -31,7 +31,7 @@ type cadvisorUnsupported struct {
var _ Interface = new(cadvisorUnsupported)
func New(imageFsInfoProvider ImageFsInfoProvider, rootPath string, usingLegacyStats bool) (Interface, error) {
func New(imageFsInfoProvider ImageFsInfoProvider, rootPath string, cgroupsRoots []string, usingLegacyStats bool) (Interface, error) {
return &cadvisorUnsupported{}, nil
}

View File

@@ -33,7 +33,7 @@ type cadvisorClient struct {
var _ Interface = new(cadvisorClient)
// New creates a cAdvisor and exports its API on the specified port if port > 0.
func New(imageFsInfoProvider ImageFsInfoProvider, rootPath string, usingLegacyStats bool) (Interface, error) {
func New(imageFsInfoProvider ImageFsInfoProvider, rootPath string, cgroupRoots []string, usingLegacyStats bool) (Interface, error) {
client, err := winstats.NewPerfCounterClient()
return &cadvisorClient{
rootPath: rootPath,

View File

@@ -236,3 +236,37 @@ func getCgroupProcs(dir string) ([]int, error) {
func GetPodCgroupNameSuffix(podUID types.UID) string {
return podCgroupNamePrefix + string(podUID)
}
// NodeAllocatableRoot returns the literal cgroup path for the node allocatable cgroup
func NodeAllocatableRoot(cgroupRoot, cgroupDriver string) string {
root := ParseCgroupfsToCgroupName(cgroupRoot)
nodeAllocatableRoot := NewCgroupName(root, defaultNodeAllocatableCgroupName)
if libcontainerCgroupManagerType(cgroupDriver) == libcontainerSystemd {
return nodeAllocatableRoot.ToSystemd()
}
return nodeAllocatableRoot.ToCgroupfs()
}
// GetKubeletContainer returns the cgroup the kubelet will use
func GetKubeletContainer(kubeletCgroups string) (string, error) {
if kubeletCgroups == "" {
cont, err := getContainer(os.Getpid())
if err != nil {
return "", err
}
return cont, nil
}
return kubeletCgroups, nil
}
// GetRuntimeContainer returns the cgroup used by the container runtime
func GetRuntimeContainer(containerRuntime, runtimeCgroups string) (string, error) {
if containerRuntime == "docker" {
cont, err := getContainerNameForProcess(dockerProcessName, dockerPidFile)
if err != nil {
return "", fmt.Errorf("failed to get container name for docker process: %v", err)
}
return cont, nil
}
return runtimeCgroups, nil
}

View File

@@ -59,3 +59,18 @@ func getCgroupProcs(dir string) ([]int, error) {
func GetPodCgroupNameSuffix(podUID types.UID) string {
return ""
}
// NodeAllocatableRoot returns the literal cgroup path for the node allocatable cgroup
func NodeAllocatableRoot(cgroupRoot, cgroupDriver string) string {
return ""
}
// GetKubeletContainer returns the cgroup the kubelet will use
func GetKubeletContainer(kubeletCgroups string) (string, error) {
return "", nil
}
// GetRuntimeContainer returns the cgroup used by the container runtime
func GetRuntimeContainer(containerRuntime, runtimeCgroups string) (string, error) {
return "", nil
}