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
Conversation
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, I realize |
@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. |
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 |
multiple ID's on |
Maybe with multiple it can change format so tasks are nested underneath a service... but |
@cpuguy83 Maybe we could add an option (e.g., |
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 |
p.s.... I think this might be nice: |
serviceID string | ||
noResolve bool | ||
filter opts.FilterOpt | ||
serviceIDs []string |
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.
These aren't just service ids. These can also be the names of services. Make sure to model that correctly.
This should really support name or id for service lookup. |
040e1f4
to
f607e0e
Compare
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. |
@yongtang Probably best to look at |
Name prefix is a bit wierd, particularly when you have services with similar names, e.g. |
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. |
f607e0e
to
0890af7
Compare
for _, serviceEntry := range serviceList { | ||
filter.Add("service", serviceEntry.ID) | ||
} | ||
continue service_search |
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.
What is this loop doing?
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.
@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
.
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.
@yongtang I can read the code. I mean "What is the purpose of this loop?". It's fairly obtuse.
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.
@stevvooe Yes the loops might be unnecessarily redundant. Let me take a further look and see if it could be improved.
aeeb76f
to
fb4edd6
Compare
ping @stevvooe PTAL #25234 (comment) |
fb4edd6
to
3f0eaf3
Compare
@stevvooe the PR has been updated. Please take a look and let me know if there are any issues. |
ping @dnephin could you give this a review? |
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 { |
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.
Doing n * 2
service calls here is not great. Can this be done from the API?
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.
@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.
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.
Maybe that's a sign that we shouldn't support multiple service ids on this command?
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.
@dnephin what's your suggestion? Any way to get this PR moving again, or are you not comfortable with this feature?
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.
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.
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.
@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.
6dd0e1f
to
66d3ae3
Compare
66d3ae3
to
eba9150
Compare
eba9150
to
d678736
Compare
@dnephin I updated the PR and now there are only |
Thanks, this design works for me |
ping @yongtang looks like this needs a rebase |
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>
d678736
to
7094235
Compare
@thaJeztah @dnephin The PR has been rebased. Thanks. |
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
Support multiple service IDs on "docker service ps"
- 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