Process only CPU and memory stats when Kubelete stats API is called with

only_cpu_and_memory parameter. Before all stats were processed and
removed before returning.
This commit is contained in:
Krzysztof Jastrzebski
2018-09-19 16:26:00 +02:00
parent 138a3c7172
commit 3b21995c95
14 changed files with 753 additions and 79 deletions

View File

@@ -91,30 +91,33 @@ func (sp *summaryProviderImpl) Get(updateStats bool) (*statsapi.Summary, error)
}
func (sp *summaryProviderImpl) GetCPUAndMemoryStats() (*statsapi.Summary, error) {
summary, err := sp.Get(false)
// TODO(timstclair): Consider returning a best-effort response if any of
// the following errors occur.
node, err := sp.provider.GetNode()
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get node info: %v", err)
}
summary.Node.Network = nil
summary.Node.Fs = nil
summary.Node.Runtime = nil
summary.Node.Rlimit = nil
for i := 0; i < len(summary.Node.SystemContainers); i++ {
summary.Node.SystemContainers[i].Accelerators = nil
summary.Node.SystemContainers[i].Rootfs = nil
summary.Node.SystemContainers[i].Logs = nil
summary.Node.SystemContainers[i].UserDefinedMetrics = nil
nodeConfig := sp.provider.GetNodeConfig()
rootStats, err := sp.provider.GetCgroupCPUAndMemoryStats("/", false)
if err != nil {
return nil, fmt.Errorf("failed to get root cgroup stats: %v", err)
}
for i := 0; i < len(summary.Pods); i++ {
summary.Pods[i].Network = nil
summary.Pods[i].VolumeStats = nil
summary.Pods[i].EphemeralStorage = nil
for j := 0; j < len(summary.Pods[i].Containers); j++ {
summary.Pods[i].Containers[j].Accelerators = nil
summary.Pods[i].Containers[j].Rootfs = nil
summary.Pods[i].Containers[j].Logs = nil
summary.Pods[i].Containers[j].UserDefinedMetrics = nil
}
podStats, err := sp.provider.ListPodCPUAndMemoryStats()
if err != nil {
return nil, fmt.Errorf("failed to list pod stats: %v", err)
}
return summary, nil
nodeStats := statsapi.NodeStats{
NodeName: node.Name,
CPU: rootStats.CPU,
Memory: rootStats.Memory,
StartTime: rootStats.StartTime,
SystemContainers: sp.GetSystemContainersCPUAndMemoryStats(nodeConfig, podStats, false),
}
summary := statsapi.Summary{
Node: nodeStats,
Pods: podStats,
}
return &summary, nil
}