-
Notifications
You must be signed in to change notification settings - Fork 8
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
[bugfix]: Fix null pointer de-reference when parsing statistics from cAdvisor #83
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,7 +134,13 @@ func exceedMemoryLimits(summary summaryFunc) cmpFunc { | |
func hasContainerExceedMemoryLimits(pod *v1.Pod, summary stats_collector.PodSummary) bool { | ||
for _, container := range pod.Spec.Containers { | ||
if rQuantity, ok := container.Resources.Limits[v1.ResourceMemory]; ok { | ||
memoryAndSwapSumQuantity := memoryAndSwapUsage(*summary.Containers[container.Name].MemoryWorkingSetBytes, *summary.Containers[container.Name].MemorySwapCurrentBytes) | ||
containerStats, exists := summary.Containers[container.Name] | ||
if !exists { | ||
continue | ||
} | ||
workingSet := *containerStats.MemoryWorkingSetBytes | ||
swapUsage := *containerStats.MemorySwapCurrentBytes | ||
memoryAndSwapSumQuantity := memoryAndSwapUsage(workingSet, swapUsage) | ||
if memoryAndSwapSumQuantity.Cmp(rQuantity) == 1 { | ||
return true | ||
} | ||
|
@@ -143,7 +149,13 @@ func hasContainerExceedMemoryLimits(pod *v1.Pod, summary stats_collector.PodSumm | |
|
||
for _, container := range pod.Spec.InitContainers { | ||
if rQuantity, ok := container.Resources.Limits[v1.ResourceMemory]; ok { | ||
memoryAndSwapSumQuantity := memoryAndSwapUsage(*summary.Containers[container.Name].MemoryWorkingSetBytes, *summary.Containers[container.Name].MemorySwapCurrentBytes) | ||
containerStats, exists := summary.Containers[container.Name] | ||
if !exists { | ||
continue | ||
} | ||
workingSet := *containerStats.MemoryWorkingSetBytes | ||
swapUsage := *containerStats.MemorySwapCurrentBytes | ||
Comment on lines
+156
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
memoryAndSwapSumQuantity := memoryAndSwapUsage(workingSet, swapUsage) | ||
if memoryAndSwapSumQuantity.Cmp(rQuantity) == 1 { | ||
return true | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,7 +138,7 @@ func (psc *PodStatsCollectorImpl) GetPodSummary(pod *v1.Pod) (PodSummary, error) | |
summary.Containers[containerName] = ContainerSummary{ | ||
MemorySwapMaxBytes: cinfo.Spec.Memory.SwapLimit, | ||
MemoryWorkingSetBytes: containerStats.Memory.WorkingSetBytes, | ||
MemorySwapCurrentBytes: containerStats.Swap.SwapAvailableBytes, | ||
MemorySwapCurrentBytes: containerStats.Swap.SwapUsageBytes, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch! |
||
} | ||
} | ||
} | ||
|
@@ -514,7 +514,9 @@ func cadvisorInfoToCPUandMemoryStats(info *cadvisorapiv2.ContainerInfo) (*statsa | |
} else { | ||
memoryStats = &statsapi.MemoryStats{ | ||
Time: metav1.NewTime(cstat.Timestamp), | ||
UsageBytes: uint64Ptr(0), | ||
WorkingSetBytes: uint64Ptr(0), | ||
RSSBytes: uint64Ptr(0), | ||
Comment on lines
+517
to
+519
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we never use UsageBytes and RSSBytes, i think we can delete them instead WDYT? |
||
} | ||
} | ||
return cpuStats, memoryStats | ||
|
@@ -553,8 +555,9 @@ func cadvisorInfoToSwapStats(info *cadvisorapiv2.ContainerInfo) *statsapi.SwapSt | |
} | ||
} else { | ||
swapStats = &statsapi.SwapStats{ | ||
Time: metav1.NewTime(cstat.Timestamp), | ||
SwapUsageBytes: uint64Ptr(0), | ||
Time: metav1.NewTime(cstat.Timestamp), | ||
SwapUsageBytes: uint64Ptr(0), | ||
SwapAvailableBytes: uint64Ptr(0), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we never use SwapAvailableBytes anymore, i think we can delete it instead WDYT? |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, what do you think about also checking if these are nil? Maybe we can log a message in that case for better debuggability.