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

Fix a bug where network stats is not presented in container stats #1932

Merged
merged 1 commit into from
Mar 11, 2019

Conversation

fenxiong
Copy link
Contributor

@fenxiong fenxiong commented Mar 11, 2019

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.

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@suneyz suneyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@yumex93 yumex93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fenxiong fenxiong merged commit 724e55c into aws:dev Mar 11, 2019
@fenxiong fenxiong deleted the fix-stats branch March 11, 2019 20:52
@fenxiong fenxiong mentioned this pull request Mar 20, 2019
@suneyz suneyz added this to the 1.26.1 milestone Mar 27, 2019
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.

3 participants