Refactor the statistics of network in docker stats#15786
Refactor the statistics of network in docker stats#15786thaJeztah merged 1 commit intomoby:masterfrom HuKeping:stats-network
Conversation
|
For example, the output of stats after this PR will be like: |
|
I agree that we should change this. However, we cannot replace the json response without versioning the fields. We should keep returning the current json for request versions <= 1.21 and the new json for request versions > 1.22. |
|
It will also need some tests and changes in the api docs 😸 |
|
Test updated. |
api/types/stats.go
Outdated
There was a problem hiding this comment.
We rather move deprecated fields to a separated struct. Look what we do with ContainerJSON in this same file. We have a ContainerJSONBase with the common fields and we compose structs for specific versions with it and the fields required by each version of the api.
There was a problem hiding this comment.
I do considered to use the similar solution as what the ContainerJSON does. But later I found it is complicated, and provides not obvious value, it will introduce many things like:
if version.LessThan("1.xx") {
...
}
which I don't thinks is a good code style, and it will force the relative functions to add arguments version and maybe more things.
Besides the word Network explain itself well and so does the Networks. When someday we decide to drop Network, it is fine to just remove it and it will not need to remove those
if version <=
If you prefer the old ways, it's OK for me.
There was a problem hiding this comment.
We're working on a better way to serialize objects in the api, but until then, we prefer the old way. Believe me, I dislike those conditionals as much as you do, but we need to be consistent.
There was a problem hiding this comment.
Updated. I tried to not make a over deep change of the existing code. So I place the version-check the moment before this API return:
- If request version < 1.21, sum up those original data and return
- if request version >=1.21, the original data will be returned
But it still seems quite redundant. any better solutions please @calavera ?
|
@HuKeping looks like this needs a rebase Also, don't forget to update the example output in the API docs and add a mention to the API change log here; https://github.com/docker/docker/blob/master/docs/reference/api/docker_remote_api.md |
|
@calavera rebased, please take a look if this change is OK @thaJeztah thanks and I'll update the docs after code review |
|
@HuKeping would you mind rebasing again? thanks! |
|
Thanks @HuKeping. LGTM |
daemon/stats.go
Outdated
There was a problem hiding this comment.
can we have booleans in ContainerStatsConfig saying which format to use instead of leaking API version here in daemon?
There was a problem hiding this comment.
Put API version in ContainerStatsConfig is a good idea, but I prefer to use version instead of boolean, WDYT
|
this will need docs updates right |
|
Yup, it does; #15786 (comment) |
|
Docs added @thaJeztah @jfrazelle , PTAL |
|
Thanks, @HuKeping. Docs changes LGTM (but we're not in docs-review yet). |
Yes. |
|
rebased for conflict |
|
needs rebase sorry |
|
rebased @jfrazelle |
For now docker stats will sum the rxbytes, txbytes, etc. of all the interfaces. It is OK for the output of CLI `docker stats` but not good for the API response, especially when the container is in sereval subnets. It's better to leave these origianl data to user. Signed-off-by: Hu Keping <[email protected]>
|
ping @cpuguy83 |
|
LGTM, moving to docs review. |
|
docs re-LGTM ping @SvenDowideit @moxiegirl |
|
@HuKeping thank you! LGTM |
|
All green, merging \o/ |
Refactor the statistics of network in docker stats
|
@HuKeping the API docs example shows a network JSON entry, it should be networks now right? |
|
Yes it is @twhiteman , sorry for that I'll fix it. |
This fixes a bug introduced in moby#15786: * if a pre-v1.20 client requested docker stats, the daemon would return both an API-compatible JSON blob *and* an API-incompatible JSON blob: see https://gist.github.com/donhcd/338a5b3681cd6a071629 Signed-off-by: Donald Huang <[email protected]>
This fixes a bug introduced in moby#15786: * if a pre-v1.20 client requested docker stats, the daemon would return both an API-compatible JSON blob *and* an API-incompatible JSON blob: see https://gist.github.com/donhcd/338a5b3681cd6a071629 Signed-off-by: Donald Huang <[email protected]> (cherry picked from commit d2c04f8) The commit title wrongfully mentioned API v1.22, when it meant to mention v1.21.
This fixes a bug introduced in moby#15786: * if a pre-v1.20 client requested docker stats, the daemon would return both an API-compatible JSON blob *and* an API-incompatible JSON blob: see https://gist.github.com/donhcd/338a5b3681cd6a071629 Signed-off-by: Donald Huang <[email protected]> (cherry picked from commit d2c04f8) The commit title wrongfully mentioned API v1.22, when it meant to mention v1.21.
For now docker stats will sum the rxbytes, txbytes, etc. of all
the interfaces.
It is OK for the output of CLI
docker statsbut not good forthe API response, especially when the container is in sereval
subnets.
It's better to leave these origianl data to user.
Signed-off-by: Hu Keping [email protected]