-
Notifications
You must be signed in to change notification settings - Fork 617
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 a bug where network stats is not presented in container stats #1932
Conversation
When switching to use Docker Go SDK, we used types.Stats to save the stats response from corresponding Docker Engine API. This struct doesn't contain all fields in the API response, notably the "networks" field is missing and therefore the field isn't presented in container stats response. This field was populated when we were using fsouza/go-dockerclient prior to v1.24.0. Fixing it by changing to use types.StatsJSON struct which contains the "networks" field along with fields in types.Stats.
err = json.Unmarshal(body, &taskStats) | ||
if err != nil { | ||
return fmt.Errorf("task stats: unable to parse response body: %v", err) | ||
} | ||
|
||
if isBridgeNetworkMode { |
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.
curious, do we also want to validate for other network mode or the containerStats.Networks will be blank other than bridge mode?
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.
it's blank in other modes
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.
LGTM
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.
LGTM
Summary
Fix a bug where network stats are not presented in container stats.
Implementation details
When switching to use Docker Go SDK, we used types.Stats to save the stats response from corresponding Docker Engine API. This struct doesn't contain all fields in the API response, notably the "networks" field is missing and therefore the field isn't presented in container stats response. This field was populated when we were using fsouza/go-dockerclient prior to v1.24.0. Fixing it by changing to use types.StatsJSON struct which contains the "networks" field along with fields in types.Stats.
Related issue: #1927
Backward compatibility
Since types.StatsJSON contains strictly more fields than types.Stats, this change should be backward compatible.
Docker engine api version
The "networks" field is added in Docker Engine API version 1.21, corresponding to Docker version 1.9.x. Since we already deprecated support for Docker version older than 1.9 we should always expect the field to be presented.
Testing
New tests cover the changes: yes
The "networks" field will be populated by Docker in bridge network mode on Linux, and nat network mode on Windows. Related v3 metadata functional tests are updated to check that the field is populated in those modes (v2 metadata is not affected since it only works for awsvpc network mode). Also did manual tests to verify that it works.
Description for the changelog
Bug - Fixed a bug where network stats are not presented in container stats
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.