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

Conversation

enp0s3
Copy link
Member

@enp0s3 enp0s3 commented Nov 21, 2024

Signed-off-by: Igor Bezukh [email protected]

Scenario 1: it can happen that API reports about a Pod, but the pod and its containers are not yet
fully created on the node cgroupfs, therefore there can be containers that are missing in the stats.

Scenario 2: Stats API has pointers to counters. Not all counters had default allocation of zero integer.

@enp0s3 enp0s3 force-pushed the npd-fix-cadvisor-stat branch from 8f4e6a0 to 9f5ed67 Compare November 21, 2024 12:55
Copy link

openshift-ci bot commented Nov 21, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from enp0s3. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@enp0s3 enp0s3 force-pushed the npd-fix-cadvisor-stat branch from 9f5ed67 to 29c9986 Compare November 21, 2024 12:57
there might be a situation where pod ranking is done on a freshly created
pod whose containers stats are not yet ready in cadvisor.

Signed-off-by: Igor Bezukh <[email protected]>
also fixed a bug in swap stats where swap usage stat was
assigned with swap available bytes.

Signed-off-by: Igor Bezukh <[email protected]>
@enp0s3 enp0s3 force-pushed the npd-fix-cadvisor-stat branch from 29c9986 to 2de2b11 Compare November 21, 2024 14:53
@enp0s3
Copy link
Member Author

enp0s3 commented Nov 22, 2024

/cc @Barakmor1

@openshift-ci openshift-ci bot requested a review from Barakmor1 November 22, 2024 16:29
Comment on lines +156 to +157
workingSet := *containerStats.MemoryWorkingSetBytes
swapUsage := *containerStats.MemorySwapCurrentBytes
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

Comment on lines +141 to +143
workingSet := *containerStats.MemoryWorkingSetBytes
swapUsage := *containerStats.MemorySwapCurrentBytes
memoryAndSwapSumQuantity := memoryAndSwapUsage(workingSet, swapUsage)
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.

@@ -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!

Comment on lines +517 to +519
UsageBytes: uint64Ptr(0),
WorkingSetBytes: uint64Ptr(0),
RSSBytes: 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 think we never use UsageBytes and RSSBytes, i think we can delete them instead WDYT?

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?

Copy link
Member

@Barakmor1 Barakmor1 left a comment

Choose a reason for hiding this comment

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

Left some small comments overall looks great
Thanks for fixing these bugs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants