Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pkg/wasp/pod-ranker/rank_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +141 to +143
Copy link
Member

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.

if memoryAndSwapSumQuantity.Cmp(rQuantity) == 1 {
return true
}
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/wasp/stats-collector/pod_stats_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

}
}
}
Expand Down Expand Up @@ -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
Copy link
Member

@Barakmor1 Barakmor1 Dec 3, 2024

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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),
Copy link
Member

@Barakmor1 Barakmor1 Dec 3, 2024

Choose a reason for hiding this comment

The 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?

}
}

Expand Down