Skip to content

Add support for Names and ID in stats format#27797

Merged
crosbymichael merged 1 commit intomoby:masterfrom
vdemeester:stats-format-names-support
Nov 10, 2016
Merged

Add support for Names and ID in stats format#27797
crosbymichael merged 1 commit intomoby:masterfrom
vdemeester:stats-format-names-support

Conversation

@vdemeester
Copy link
Copy Markdown
Member

@vdemeester vdemeester commented Oct 26, 2016

This adds support to display names or id of container instead of what was provided in the request.

This keeps the default behavior (docker stats byname will display byname in the CONTAINER colmun and docker stats byid will display the id in the CONTAINER column) but adds two new format directive.

$ docker stats 7c3
CONTAINER           CPU %               MEM USAGE / LIMIT       MEM %               NET I/O              BLOCK I/O             PIDS
7c3                 15.02%              666.5 MiB / 15.56 GiB   4.18%               22.46 MB / 3.56 MB   405.5 MB / 162.1 MB   71
$ docker stats --format="table {{.Names}}\t{{.ID}}\t{{.Container}}" 7c3
NAME                CONTAINER ID                                                       CONTAINER
elastic_agnesi      7c32fcc1c619123926f2c3cbc2356375b1887196b6b0cf3ed682973916bbb74e   7c3

/cc @thaJeztah @dnephin

🐸

Signed-off-by: Vincent Demeester [email protected]

Copy link
Copy Markdown
Contributor

@MHBauer MHBauer left a comment

Choose a reason for hiding this comment

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

Code looks right. Not sure I understand the use case.

Comment thread api/types/stats.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why here vs on the Stats struct? I don't have any preference. I'm just curious how we decide to put it on one or the other.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Mainly because I wanted to keep Stats struct with only metrics field and no metadata.

Comment thread cli/command/formatter/stats.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Check my understanding.

  • Container has the user input name.
  • Name has the full name, and used to have the user input name.
  • ID has the full ID.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yep, that's it. I kept Container as the user input as this is what it's doing now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you put ID at the top here? (ID, Name, Container)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No reason to nit pick when its still in design review @thaJeztah. be nice to @vdemeester

Comment thread cli/command/formatter/stats.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this called Names with an s?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@crosbymichael I asked myself the same question 😅. I did it to mimic the docker ps --format which has Names too, I'm fine to rename it to Name 👼

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@vdemeester docker ps used to show all the things a container could be referenced as which includes names, as well as link aliases. That's why it is plural.... it might still do that if you use --no-trunc come to think of it.

Definitely singular here is good.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll update 👼

Comment thread cli/command/container/stats_helpers.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can't we display both the container name and the container ID?
I believe the container name is more readable than its iD.
Thought? 😊

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@ripcurld00d On the debug log ? This change is here to keep the same behavior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@vdemeester yes, now I see it. s.Container can be the ID or the Name depends on what the user enters.

@boaz0
Copy link
Copy Markdown
Contributor

boaz0 commented Oct 31, 2016

@vdemeester @thaJeztah
I think it closes #20973, right?

@boaz0
Copy link
Copy Markdown
Contributor

boaz0 commented Oct 31, 2016

If I'm not wrong, in case there is a container called 18f132d776 and another container with ID 18f132d776 then both of them will be displayed.

Is that OK? Maybe adding --container-id can solve this edge-case?
Feedback? 😺

@vdemeester
Copy link
Copy Markdown
Member Author

@ripcurld00d yes you're right, I should update the description. For the name/id collision, I don't think we should do anything 👼.

@coolljt0725
Copy link
Copy Markdown
Contributor

coolljt0725 commented Nov 1, 2016

During review this PR, I found there would be an issue with docker stats byname if user call docker rename to rename the container, the name display in CONTAINER colmun does not change. I think this PR could fix this issue with more changes since this PR return the container name to client(https://github.com/docker/docker/pull/27797/files#diff-ad75d4bbd2897e0abd0207e0f2608bf6R47).

EDIT: open an issue to track this #27937

@vdemeester vdemeester force-pushed the stats-format-names-support branch from e44cf35 to 7a1a9c5 Compare November 2, 2016 21:25
@vdemeester
Copy link
Copy Markdown
Member Author

@coolljt0725 yep, I'm not really sure how to fix it the best way possible 👼. At some point we should make it so that Container and ID are the same (or Name), and thus not display the user input as Container. But not sure how we should change that (in terms or retro-compat, etc…)…

@vdemeester vdemeester added the status/failing-ci Indicates that the PR in its current state fails the test suite label Nov 2, 2016
This adds support to display names or id of container instead of what
was provided in the request.

This keeps the default behavior (`docker stats byname` will display
`byname` in the `CONTAINER` colmun and `docker stats byid` will display
the id in the `CONTAINER` column) but adds two new format directive.

Signed-off-by: Vincent Demeester <[email protected]>
@vdemeester vdemeester force-pushed the stats-format-names-support branch from 7a1a9c5 to ef915fd Compare November 3, 2016 06:20
@vdemeester vdemeester removed the status/failing-ci Indicates that the PR in its current state fails the test suite label Nov 3, 2016
@crosbymichael crosbymichael self-assigned this Nov 8, 2016
@crosbymichael
Copy link
Copy Markdown
Contributor

What is the use case for this because adding three different ways have identifying the container is pretty confusing for me and hard to reason about that cons for this.

@vdemeester
Copy link
Copy Markdown
Member Author

@crosbymichael The use case is to be able to display the actual name or id of the container instead of the user input. Right now there is no way to get the name of a container for stats if you don't already know it and pass it to the command (and thus, stats on all containers, you can't, at all 😓).

Keeping Container for retro-compatibility but I really wish I wouldn't have too…

@crosbymichael
Copy link
Copy Markdown
Contributor

@vdemeester is this just an api issue or does the cli format have to change as well? Could we get away with just returning the full container id and not this name stuff since names can change and its weird. Most of the time the name will be the Continaer part anyways right?

@colinmollenhour
Copy link
Copy Markdown

This shows merged into 1.13 milestone but it does not appear to be present in 17.03.0-ce. Also, shouldn't "byname" and "byid" be "--byname" and "--byid" since they are options?

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.

9 participants