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
Refactor the statistics of network in docker stats #15786
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. |
Read time.Time `json:"read"` | ||
|
||
// Network is for fallback stats where API Version <= 1.21 | ||
Network NetworkStats `json:"network,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
@@ -58,14 +59,64 @@ func (daemon *Daemon) ContainerStats(name string, config *ContainerStatsConfig) | |||
return nil | |||
} | |||
|
|||
s := getStat(v) | |||
statsJSON := getStatJSON(v) | |||
if version.LessThan("1.21") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <hukeping@huawei.com>
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? https://github.com/docker/docker/blob/master/docs/reference/api/docker_remote_api_v1.21.md
|
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 <don.hcd@gmail.com>
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 <don.hcd@gmail.com> (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 <don.hcd@gmail.com> (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 stats
but 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 hukeping@huawei.com