Hide the mutex lock in formatter.ContainerStats#26819
Hide the mutex lock in formatter.ContainerStats#26819thaJeztah merged 1 commit intomoby:masterfrom boaz0:fix_stats_mutex
Conversation
There was a problem hiding this comment.
I hate the idea of copying the containers statistics (it won't scale nicely).
I am working on a better way to avoid this part.
|
@thaJeztah @runcom @cpuguy83 @vdemeester @LK4D4 Any feedback will be appreciated! 😺 |
|
@ripcurld00d Doesn't this mean that |
|
@LK4D4, no you got it right. I do believe I can make this more atomic (read the CPU, memory and etc in one time frame), though. Anything else that I should keep in mind? |
|
@ripcurld00d Otherwise, patch looks good to me. |
There was a problem hiding this comment.
This name isn't good IMO. At first, it doesn't reflect what this structure does and then "clear containers" is intel containers technology :)
There was a problem hiding this comment.
Yes, I am bad at giving names 😊.
Is it a bad idea to move this to api/types and call it ContainerStats?
There was a problem hiding this comment.
What's the difference with ContainerStats? (Just so I can try thinking of a better name)
There was a problem hiding this comment.
@thaJeztah ContainerStats is used for collecting the container statistics while ClearContainerStats (now ContainerStatsRecord) is used to display the statistics on the screen.
Because of that ContainerStats has both mutex and an error field.
There was a problem hiding this comment.
Can't you make statistics type public and use it here as argument?
There was a problem hiding this comment.
Yes, it will definitely make it more readable. 👍
|
Odd, windowRS1 failed: None of them are related to |
cpuguy83
left a comment
There was a problem hiding this comment.
I can sort of follow the code, but it's a bit confusing.
I wonder if we need so many different structs for the same information.
Instead we can put methods on one, like IsWindows() which can lock and check the windows field, and Name() and read the name field.
There was a problem hiding this comment.
I think this comment is not right.
Statistics is where this comment belongs.
There was a problem hiding this comment.
Still not quite sure what this does. Maybe it's just for formatting?
Maybe ContainerStatsFormatter?
There was a problem hiding this comment.
I think maybe a better name would be StatsEntry
There was a problem hiding this comment.
All of these with basically the same fields and name is pretty confusing.
There was a problem hiding this comment.
Not really "getting" anything here, just copying into a new struct.
There was a problem hiding this comment.
Yes, that's right. Nevertheless, you eventually get a ContainerStatsRecord entity.
You want me to rename this anyway?
|
@cpuguy83 thanks for your feedback. |
|
@cpuguy83 and @LK4D4 PTAL thanks. 😺 /cc @thaJeztah |
There was a problem hiding this comment.
Let's use values instead of pointers everywhere for consistency.
There was a problem hiding this comment.
I don't like global variable usage here. It's definitely shouldn't be global.
There was a problem hiding this comment.
Ummm... the alternative is to put this variable inside the StatsEntity struct.
What do you think?
There was a problem hiding this comment.
Yeah, I think it would be better. I saw that we use global var in stat_helper too. It's also so wrong :(
There was a problem hiding this comment.
👍
I don't mind fixing this as well.
The question is whether you prefer doing that in this commit or in another one.
The formatter.ContainerStats struct exposes its Mutex. This is a bad design and should be fixed. To fix that, I separated the statistics attributes from ContainerStats to StatsEntry and hid the mutex. Notice that the mutex protects both the `err` field and the statistics attributes. Then, implemented SetStatistics, SetError, GetStatistics and GetError to avoid races. Moreover, to make this less granular, I decided to replace the read-write mutex with the regular mutex and to pass a StatsEntry slice to formatter.ContainerStatsWrite Signed-off-by: Boaz Shuster <[email protected]>
|
@LK4D4 re-review 🎱 🍶 plz? |
|
ping @cpuguy83 |
|
LGTM |
Hide the mutex lock in formatter.ContainerStats
- What I did
Created getters and setters to the container statistics and hide the mutex lock.
- How I did it
- How to verify it
docker statsanddocker stats --format "{{.PIDs}} -- {{.Container}}"and see that the formats are different.- Description for the changelog
This patch supposes to fix the issue mentioned in #24987