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

Support multiple service IDs on "docker service ps" #25234

Merged
merged 1 commit into from Jan 3, 2017

Conversation

yongtang
Copy link
Member

- What I did

This fix tries to address the issue raised in #25228 to support multiple service IDs on docker service ps.

- How I did it

Multiple IDs are allowed with docker service ps ..., and related documentation has been updated.

- How to verify it

A test has been added to cover the changes.

- Description for the changelog

Support multiple service IDs on "docker service ps"

- A picture of a cute animal (not mandatory but encouraged)

This fix fixes #25228.

Signed-off-by: Yong Tang yong.tang.github@outlook.com

@thaJeztah
Copy link
Member

functionally, it makes sense to have an option to show tasks for multiple services; I'm a bit in doubt what the best approach is. For example, docker ps by default shows everything, but requires a --filter to just show a single (container).

I realize docker service ps is slightly different, hence my doubt

ping @stevvooe @aluzzardi @tiborvass

@ezrasilvera
Copy link
Contributor

@thaJeztah I'm not sure I would compare it to docker ps (on single engine). Maybe it is closer indeed to "ps" on the previous swarm where you got all containers and indeed used filter if needed.
In general I would love to see a more "old swarm" related options where one can see all the resources and filer out.
BTW, specific for "docker service" it's not reasonable to allow multiple IDs for "inspect" but not for other subcommands

@thaJeztah
Copy link
Member

Yes, perhaps this is the best approach; I was thinking out loud, and thought I'd better write it up on GitHub, before I forget to do so

@cpuguy83
Copy link
Member

cpuguy83 commented Aug 1, 2016

multiple ID's on service ps is a bit strange, tbh. I'm not sure the UX holds up to it.

@cpuguy83
Copy link
Member

cpuguy83 commented Aug 1, 2016

Maybe with multiple it can change format so tasks are nested underneath a service... but docker service ls pretty much shows this same information, just without the individual task details.

@yongtang
Copy link
Member Author

yongtang commented Aug 1, 2016

@cpuguy83 Maybe we could add an option (e.g., --detail or --tasks) to docker service ls, so that it will shown individual task details together with the services?

@thaJeztah
Copy link
Member

We discussed this, and since there's no other option to show multiple services on multiple nodes, this is probably the best solution after all, so moving to code review

@cpuguy83
Copy link
Member

p.s.... I think this might be nice: docker service ps $(docker serivce ls -q --filter ...)

serviceID string
noResolve bool
filter opts.FilterOpt
serviceIDs []string
Copy link
Contributor

Choose a reason for hiding this comment

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

These aren't just service ids. These can also be the names of services. Make sure to model that correctly.

@stevvooe
Copy link
Contributor

This should really support name or id for service lookup.

@yongtang yongtang force-pushed the 25228-service-ps-multiple-ID branch from 040e1f4 to f607e0e Compare August 20, 2016 02:14
@yongtang
Copy link
Member Author

Thanks @thaJeztah @stevvooe @cpuguy83. I have updated the pull request and now with both name prefix and ID searched for services.

One thing I am not sure is the return code when some (or all of the) terms searched does not found service with matched ID or matched name prefix. The currently PR will return empty result (but no error). Should we return error on it? Would like to hear suggestions on this scenario.

@cpuguy83
Copy link
Member

@yongtang Probably best to look at docker inspect output in this scenario.

@cpuguy83
Copy link
Member

Name prefix is a bit wierd, particularly when you have services with similar names, e.g. test and test2

@stevvooe
Copy link
Contributor

stevvooe commented Aug 27, 2016

@cpuguy83

Name prefix is a bit wierd, particularly when you have services with similar names, e.g. test and test2

Yes, but we've specified an algorithm that should work in most cases.

It must be modified here, since ambiguous lookups are no longer an error but a merge.

@yongtang yongtang force-pushed the 25228-service-ps-multiple-ID branch from f607e0e to 0890af7 Compare August 28, 2016 20:33
@yongtang
Copy link
Member Author

Thanks @cpuguy83 @stevvooe. The pull request has been updated. Now service ps will return error in case any one of the name/ID can not be found, similar to docker inspect. Please let me know if there are any issues.

for _, serviceEntry := range serviceList {
filter.Add("service", serviceEntry.ID)
}
continue service_search
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this loop doing?

Copy link
Member Author

Choose a reason for hiding this comment

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

@stevvooe The outmost loop for _, service := range opts.services is to iterate through the input term(ID/Name) of the service ps.

The inner loop for _, filterType := range filterTypes is to search with id then with name.

During the search process, if either id or name search returns anything, it will add the serviceEntry.ID to the filter (for process later), and continue with the next term(ID/Name) of the service search (continue service_search).

If both id and name search returns nothing, then it will be added to the unknownServices.

Previously I adds all the search term (Name/ID) of service ps to id filter first, do one search, and then to name filter, do another search.

However, that will not give us the information on which search term (Name/ID) is a hit and which is not.

So I just search each term (Name/ID) one by one, first through id, then through name. This will allows us to show unfound terms like docker inspect.

Copy link
Contributor

Choose a reason for hiding this comment

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

@yongtang I can read the code. I mean "What is the purpose of this loop?". It's fairly obtuse.

Copy link
Member Author

Choose a reason for hiding this comment

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

@stevvooe Yes the loops might be unnecessarily redundant. Let me take a further look and see if it could be improved.

@yongtang yongtang force-pushed the 25228-service-ps-multiple-ID branch 2 times, most recently from aeeb76f to fb4edd6 Compare September 19, 2016 23:36
@thaJeztah
Copy link
Member

ping @stevvooe PTAL #25234 (comment)

@yongtang yongtang force-pushed the 25228-service-ps-multiple-ID branch from fb4edd6 to 3f0eaf3 Compare October 5, 2016 20:13
@yongtang
Copy link
Member Author

yongtang commented Oct 5, 2016

@stevvooe the PR has been updated. Please take a look and let me know if there are any issues.

@thaJeztah
Copy link
Member

ping @dnephin could you give this a review?

@thaJeztah
Copy link
Member

also /cc @albers @sdurrheimer as this need changes to the completion scripts

}
serviceNameFilter := filters.NewArgs()
serviceNameFilter.Add("name", service)
if serviceList, err := client.ServiceList(ctx, types.ServiceListOptions{Filter: serviceNameFilter}); err == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Doing n * 2 service calls here is not great. Can this be done from the API?

Copy link
Member Author

Choose a reason for hiding this comment

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

@dnephin I tried to reduce the number of passes to list the services but cannot find a good way. The issue is that ServiceList will not indicate which search term is hit and which search term is a miss. We will not be able to know if any search term returns nothing if we combines search terms into less ServiceList calls.

I also thought about list all services in one call (without filtering), then do the filtering on the client side to find out which search term is a hit and which search term is a miss. This might be OK if the total number of services is small but I am not sure if it will be an issue if the total number of services is big.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe that's a sign that we shouldn't support multiple service ids on this command?

Copy link
Member

Choose a reason for hiding this comment

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

@dnephin what's your suggestion? Any way to get this PR moving again, or are you not comfortable with this feature?

Copy link
Member

Choose a reason for hiding this comment

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

I don't have any ideas of how to make this work. I think it's a bit awkward to support multiple services from this command because you end up seeing a list of unrelated tasks.

Copy link
Member

Choose a reason for hiding this comment

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

@dnephin It already happens with docker node ps.

Not too worried about making extra calls, because the user will do it anyway. But if we can optimize it all the better.

@yongtang yongtang force-pushed the 25228-service-ps-multiple-ID branch 2 times, most recently from 6dd0e1f to 66d3ae3 Compare October 22, 2016 16:58
@yongtang
Copy link
Member Author

yongtang commented Dec 1, 2016

@dnephin I updated the PR and now there are only 2 service calls instead of n * 2 service calls. Please take a look and see if it fit the requirement.

@dnephin
Copy link
Member

dnephin commented Dec 2, 2016

Thanks, this design works for me

@thaJeztah
Copy link
Member

ping @yongtang looks like this needs a rebase

@thaJeztah
Copy link
Member

ping @dnephin LGTY? If so we're ready to merge I think

This fix tries to address issue raised in 25228 to support
multiple service IDs on `docker service ps`.

Multiple IDs are allowed with `docker service ps ...`, and
related documentation has been updated.

A test has been added to cover the changes.

This fix fixes 25228.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
@yongtang
Copy link
Member Author

@thaJeztah @dnephin The PR has been rebased. Thanks.

Copy link
Member

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Support multiple service IDs on "docker service tasks"
8 participants