allow lookup by prefix on ID and full Name for jobs and nodes#210
allow lookup by prefix on ID and full Name for jobs and nodes#210aluzzardi merged 1 commit intomoby:masterfrom vieux:prefix_no_index
Conversation
use .Find(ByPrefix(xxx)) use prefix from go-memdb Signed-off-by: Victor Vieux <vieux@docker.com>
Current coverage is
|
|
Open question: Should it be ID prefix, Name prefix or both? Right now we're doing both and I'm not sure about names. Also, the only way to do a name lookup through the API is by prefix. The following would be possible, but I'm not sure I like it: c.ListJobs(&api.ListJobsRequest{
options: &api.ListOptions{
name: args[0],
prefix: args[0],
},
}) |
|
@aluzzardi I think it should be only |
|
I would also vote to only do prefix matching on IDs, but I don't have a strong opinion. The argument in favor of doing it is that it's more consistent if we do prefix matches on both names or IDs, so there isn't an arbitrary difference between them that people have to be aware of. The argument against is that typing a name shouldn't be a big burden to place on users, and by keeping names explicit we can avoid confusing "ambiguous name..." error messages. |
|
@aaronlehmann I agree. Are you OK to close #199 ? if so I'll update this on to prefix only IDs |
|
The question is, how do we lookup by name then? :) There are two options:
If we go with 1) then |
|
@aluzzardi I would go with 2) but I don't like the fact that you pass the same arg twice. Why not just une generic parameter like |
|
@aluzzardi: Either approach is fine with me. |
manager/state/memory.go
Outdated
| } | ||
| return fromResultIterator(it), nil | ||
| case byPrefix: | ||
| itID, err := jobs.memDBTx.Get(jobs.table(), indexID+"_prefix", string(v)) |
There was a problem hiding this comment.
Can you put "_prefix" in a constant? I know it's a little silly, but I've been burned too many times by typos in strings like this.
|
The store parts look good to me. Just need to finalize the details currently being discussed, then we should merge this. |
|
@aluzzardi or we do something very generic,we use index directly : |
|
@aaronlehmann I addressed all your comments @aluzzardi I went with option 2, with an match via full ID first. |
|
|
||
| message ListOptions { | ||
| string prefix = 1; | ||
| } |
There was a problem hiding this comment.
Seems a little strange that this prefix field can also match a full name. But I'm not really sure what else to suggest.
Maybe "query"?
|
LGTM |
|
@aaronlehmann @vieux Not sure about |
|
@aluzzardi agreed but for now it's good enough no ? |
|
I have some reservations on It's more flexible and it's going to get more complex when we add namespaces (Find by ID prefix or namespace+name prefix). Also, I don't know if we want to implicitly do a name prefix lookup. Even though it's more calls, what about, when you run GetJob(args[0])
ListJobs(
Namespace: flags.Namespace,
Name: args[0],
)
ListJobs(
Prefix: args[0],
)Note that in gRPC, there's just one connection so issuing a bunch of calls is not that expensive. I'm okay with merging it as is and improving later on. LGTM |
|
@aluzzardi note: in this PR we only match on full Name and partial ID. there is no prefix search on name. Feel free to merge |
|
@vieux Woops - forgot to say, we should validate that the query has at least 2 characters. |
| } | ||
|
|
||
| message ListOptions { | ||
| string query = 1; |
There was a problem hiding this comment.
Can we have a TODO here? This should not be a permanent type. It doesn't take on any of the design constraints we've spoken about.
result from bench:
Compared to #199: