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

Refactor the statistics of network in docker stats #15786

Merged
merged 1 commit into from Sep 16, 2015
Merged

Refactor the statistics of network in docker stats #15786

merged 1 commit into from Sep 16, 2015

Conversation

HuKeping
Copy link
Contributor

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

@HuKeping
Copy link
Contributor Author

For example, the output of stats after this PR will be like:

    ...
    "network": {
        "eth0": {
            "rx_bytes": 5338,
            "rx_dropped": 0,
            "rx_errors": 0,
            "rx_packets": 36,
            "tx_bytes": 648,
            "tx_dropped": 0,
            "tx_errors": 0,
            "tx_packets": 8
        },
        "eth5": {
            "rx_bytes": 4641,
            "rx_dropped": 0,
            "rx_errors": 0,
            "rx_packets": 26,
            "tx_bytes": 690,
            "tx_dropped": 0,
            "tx_errors": 0,
            "tx_packets": 9
        }
    },
    ...

@calavera
Copy link
Contributor

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.

@calavera
Copy link
Contributor

It will also need some tests and changes in the api docs 😸

@HuKeping
Copy link
Contributor Author

Test updated.

Read time.Time `json:"read"`

// Network is for fallback stats where API Version <= 1.21
Network NetworkStats `json:"network,omitempty"`
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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 ?

@thaJeztah
Copy link
Member

@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

@HuKeping
Copy link
Contributor Author

@calavera rebased, please take a look if this change is OK

@thaJeztah thanks and I'll update the docs after code review

@ehazlett
Copy link
Contributor

ehazlett commented Sep 4, 2015

@HuKeping would you mind rebasing again? thanks!

@HuKeping
Copy link
Contributor Author

HuKeping commented Sep 6, 2015

rebased @ehazlett @calavera

@calavera
Copy link
Contributor

calavera commented Sep 7, 2015

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") {
Copy link
Member

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?

Copy link
Contributor Author

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

@jessfraz
Copy link
Contributor

jessfraz commented Sep 8, 2015

this will need docs updates right

@thaJeztah
Copy link
Member

Yup, it does; #15786 (comment)

@HuKeping
Copy link
Contributor Author

HuKeping commented Sep 9, 2015

Docs added @thaJeztah @jfrazelle , PTAL

@thaJeztah
Copy link
Member

Thanks, @HuKeping. Docs changes LGTM (but we're not in docs-review yet).
Question; this is only affects the API; the output of docker stats on the CLI is still the same, correct?

@HuKeping
Copy link
Contributor Author

HuKeping commented Sep 9, 2015

Question; this is only affects the API; the output of docker stats on the CLI is still the same, correct?

Yes.

@HuKeping
Copy link
Contributor Author

rebased for conflict

@jessfraz
Copy link
Contributor

needs rebase sorry

@HuKeping
Copy link
Contributor Author

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>
@HuKeping
Copy link
Contributor Author

ping @cpuguy83

@cpuguy83
Copy link
Member

LGTM, moving to docs review.

@thaJeztah
Copy link
Member

docs re-LGTM

ping @SvenDowideit @moxiegirl

@moxiegirl
Copy link
Contributor

@HuKeping thank you! LGTM

@thaJeztah
Copy link
Member

All green, merging \o/

thaJeztah added a commit that referenced this pull request Sep 16, 2015
Refactor the statistics of network in docker stats
@thaJeztah thaJeztah merged commit 259a0fb into moby:master Sep 16, 2015
@HuKeping HuKeping deleted the stats-network branch September 17, 2015 01:36
@twhiteman
Copy link
Contributor

@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

{
     "read" : "2015-01-08T22:57:31.547920715Z",
     "network": {      <- should be "networks"
             "eth0": {
                 "rx_bytes": 5338,
                 "rx_dropped": 0,
                 ...

@HuKeping
Copy link
Contributor Author

Yes it is @twhiteman , sorry for that I'll fix it.

donhcd added a commit to donhcd/docker that referenced this pull request Oct 30, 2015
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>
tiborvass pushed a commit to tiborvass/docker that referenced this pull request Oct 31, 2015
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.
tiborvass pushed a commit to tiborvass/docker that referenced this pull request Oct 31, 2015
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants