Unverified Commit 949199e6 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #67426 from yanxuean/check-both-err

Automatic merge from submit-queue (batch tested with PRs 67100, 67426). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. should check all error in ResourceCollector.Start() Signed-off-by: 's avataryanxuean <yan.xuean@zte.com.cn> **What this PR does / why we need it**: 1. We should check both errors. test/e2e_node/resource_collector.go ``` func (r *ResourceCollector) Start() { // Get the cgroup container names for kubelet and runtime kubeletContainer, err := getContainerNameForProcess(kubeletProcessName, "") runtimeContainer, err := getContainerNameForProcess(framework.TestContext.ContainerRuntimeProcessName, framework.TestContext.ContainerRuntimePidFile) if err == nil { systemContainers = map[string]string{ stats.SystemContainerKubelet: kubeletContainer, stats.SystemContainerRuntime: runtimeContainer, } } ``` 2. redundant compare The Timestamp.Equal is unlikely to occur, because we have met Timestamp.Before. ``` if oldStats, ok := oldStatsMap[name]; ok && oldStats.Timestamp.Before(newStats.Timestamp) { if oldStats.Timestamp.Equal(newStats.Timestamp) { continue } r.buffers[name] = append(r.buffers[name], computeContainerResourceUsage(name, oldStats, newStats)) } ``` **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ``` /sig-node
parents 99fab84c ea9376a1
...@@ -86,9 +86,9 @@ func NewResourceCollector(interval time.Duration) *ResourceCollector { ...@@ -86,9 +86,9 @@ func NewResourceCollector(interval time.Duration) *ResourceCollector {
// then repeatedly runs collectStats. // then repeatedly runs collectStats.
func (r *ResourceCollector) Start() { func (r *ResourceCollector) Start() {
// Get the cgroup container names for kubelet and runtime // Get the cgroup container names for kubelet and runtime
kubeletContainer, err := getContainerNameForProcess(kubeletProcessName, "") kubeletContainer, err1 := getContainerNameForProcess(kubeletProcessName, "")
runtimeContainer, err := getContainerNameForProcess(framework.TestContext.ContainerRuntimeProcessName, framework.TestContext.ContainerRuntimePidFile) runtimeContainer, err2 := getContainerNameForProcess(framework.TestContext.ContainerRuntimeProcessName, framework.TestContext.ContainerRuntimePidFile)
if err == nil { if err1 == nil && err2 == nil {
systemContainers = map[string]string{ systemContainers = map[string]string{
stats.SystemContainerKubelet: kubeletContainer, stats.SystemContainerKubelet: kubeletContainer,
stats.SystemContainerRuntime: runtimeContainer, stats.SystemContainerRuntime: runtimeContainer,
...@@ -165,9 +165,6 @@ func (r *ResourceCollector) collectStats(oldStatsMap map[string]*cadvisorapiv2.C ...@@ -165,9 +165,6 @@ func (r *ResourceCollector) collectStats(oldStatsMap map[string]*cadvisorapiv2.C
newStats := cStats.Stats[0] newStats := cStats.Stats[0]
if oldStats, ok := oldStatsMap[name]; ok && oldStats.Timestamp.Before(newStats.Timestamp) { if oldStats, ok := oldStatsMap[name]; ok && oldStats.Timestamp.Before(newStats.Timestamp) {
if oldStats.Timestamp.Equal(newStats.Timestamp) {
continue
}
r.buffers[name] = append(r.buffers[name], computeContainerResourceUsage(name, oldStats, newStats)) r.buffers[name] = append(r.buffers[name], computeContainerResourceUsage(name, oldStats, newStats))
} }
oldStatsMap[name] = newStats oldStatsMap[name] = newStats
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment