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

filesystem usage stats are wrong in v2 api #1395

Merged
merged 1 commit into from
Jul 25, 2016

Conversation

derekwaynecarr
Copy link
Collaborator

Go reuses memory, so the result was that things that took the pointer value of stat would get a random result from a different filesystem for available, capacity, etc. It caused the output of /v2.1/machinestats to just be really wrong and confusing ;-)

/cc @ronnielai @vishh @timstclair @ncdc @pmorie

@vishh
Copy link
Contributor

vishh commented Jul 25, 2016

Good catch. LGTM

@derekwaynecarr
Copy link
Collaborator Author

Thanks... it took most of my afternoon to track down ;-) I need 🍻

@k8s-bot
Copy link
Collaborator

k8s-bot commented Jul 25, 2016

Jenkins GCE e2e

Build/test passed for commit 8551b0e.

@vishh
Copy link
Contributor

vishh commented Jul 25, 2016

We need to improve testing around the critical APIs..

@vishh
Copy link
Contributor

vishh commented Jul 25, 2016

Lol. Yeah. Time for 🍻 🍻

@vishh vishh self-assigned this Jul 25, 2016
@vishh vishh merged commit 04f73fe into google:master Jul 25, 2016
@jimmidyson
Copy link
Collaborator

@derekwaynecarr Sorry for being dense but could you explain the problem & how this fixes it? Got so much to learn!

@timstclair
Copy link
Contributor

@jimmidyson The problem is that Go reuses the memory for the object in a range clause, and the for loop is taking the address of some fields on that struct:

...
            Usage:      &stat.Usage,
            Available:  &stat.Available,
            InodesFree: &stat.InodesFree,
...

This means that every machine stats's Usage, Available, InodesFree will all point to the same memory address, which will contain the last item that was iterated over. The solution forces a new struct to be allocated for each iteration.

@jimmidyson
Copy link
Collaborator

Aha thanks @timstclair!

@ichekrygin
Copy link

@derekwaynecarr: do you know by any chance if this fix made its way into v1.3.5?

@timstclair
Copy link
Contributor

Nope. Kubernetes v1.3.5 shipped with cAdvisor v0.23.7. This change was recently cherrypicked into the v0.23 branch, but hasn't been cherrypicked into Kubernetes yet.

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.

6 participants