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

fix: nerdctl stats on containers without a memory limit returns host memory limit #3369

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cezar-r
Copy link

@cezar-r cezar-r commented Aug 26, 2024

Fix: runfinch/finch#45

  • Fixed bug where nerdctl stats would show 16 exbibytes of memory limit when memory limit on container was not set.

go.mod Outdated
github.com/containerd/stargz-snapshotter v0.15.2-0.20240709063920-1dac5ef89319
github.com/containerd/stargz-snapshotter/estargz v0.15.2-0.20240709063920-1dac5ef89319
github.com/containerd/stargz-snapshotter/ipfs v0.15.2-0.20240709063920-1dac5ef89319
github.com/containerd/stargz-snapshotter v0.15.2-0.20240826180748-fbc3f6a1d4aa
Copy link
Contributor

Choose a reason for hiding this comment

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

avoid updating hash for unrelated things.

Copy link
Author

Choose a reason for hiding this comment

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

These changes occurred after running go mod tidy, which I needed to run after adding the gopsutil package. Let me see how I can work around this

Copy link
Contributor

Choose a reason for hiding this comment

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

probably is fine

Copy link
Contributor

Choose a reason for hiding this comment

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

Tried it, and go mod tidy did not up these dependencies.
Maybe you did go get -u somehow?
Anyhow, I don't think we should touch these at this time.

Copy link
Author

Choose a reason for hiding this comment

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

fixed in latest push

@@ -73,6 +72,27 @@ func SetCgroup2StatsFields(previousStats *ContainerStats, metrics *v2.Metrics, l

}

func getMemLimit(metrics *v1.Metrics) float64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

getCgroupMemLimit

return memLimit
}

func getMemLimit2(metrics *v2.Metrics) float64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

getCgroup2MemLimit

}

func getHostMemoryLimit() uint64 {
virtualMemLimit, _ := mem.VirtualMemory()
Copy link
Contributor

Choose a reason for hiding this comment

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

why virtual memory?

Copy link
Author

Choose a reason for hiding this comment

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

Followed their documentation - https://github.com/shirou/gopsutil?tab=readme-ov-file#usage
I didn't catch any other relevant methods

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah seems its called virtualmemory

go.mod Outdated
@@ -59,6 +59,7 @@ require (
github.com/pelletier/go-toml/v2 v2.2.3
github.com/rootless-containers/bypass4netns v0.4.1
github.com/rootless-containers/rootlesskit/v2 v2.3.1
github.com/shirou/gopsutil/v3 v3.24.5
Copy link
Contributor

Choose a reason for hiding this comment

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

hey @cezar-r - is there a reason to not use /v4?

Copy link
Author

Choose a reason for hiding this comment

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

This was the recommended version that was prompted by Go and I was having some issues with v4 as well in go.sum but I can re-evaluate if needed @apostasie

Copy link
Contributor

Choose a reason for hiding this comment

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

My concern is that v3 will drop out of support soon. Back in May: v3 will not be updated except for high level security issues.

Copy link
Author

Choose a reason for hiding this comment

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

good catch, updated it to v4 in latest push

@cezar-r cezar-r marked this pull request as ready for review August 27, 2024 17:14
@cezar-r cezar-r force-pushed the stats-bug branch 6 times, most recently from 6e1679a to 9469eb3 Compare August 28, 2024 18:42
go.mod Outdated
@@ -59,6 +59,7 @@ require (
github.com/pelletier/go-toml/v2 v2.2.3
github.com/rootless-containers/bypass4netns v0.4.1
github.com/rootless-containers/rootlesskit/v2 v2.3.1
github.com/shirou/gopsutil/v4 v4.24.7
Copy link
Member

Choose a reason for hiding this comment

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

This seems to introduce a bunch of other deps that should not be necessary for fixing the issue

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, will explore other options

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

@cezar-r cezar-r marked this pull request as draft September 19, 2024 20:25
@cezar-r cezar-r force-pushed the stats-bug branch 2 times, most recently from e40e14f to 87686d0 Compare September 19, 2024 20:31
@cezar-r
Copy link
Author

cezar-r commented Sep 19, 2024

This seems to introduce a bunch of other deps that should not be necessary for fixing the issue

Apologies for the delay, the latest commit implements the fix without the need for other deps.

I do want to note; it seems like there was a discussion upstream in the containerd cgroups package relating to this issue (containerd/cgroups#265) that never got resolved. Is there alignment for the one of 4 options from that discussion? Should this fix even be implemented in this package or should it be in containerd?

Let me know your thoughts @AkihiroSuda

… memory limit

Signed-off-by: Cezar Rata <[email protected]>

Signed-off-by: Cezar Rata <[email protected]>

Signed-off-by: Cezar Rata <[email protected]>

Signed-off-by: Cezar Rata <[email protected]>
@AkihiroSuda
Copy link
Member

Should this fix even be implemented in this package or should it be in containerd?

This package

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.

finch stats on a container without a memory limit reports 16 exbibytes
4 participants