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 fetching templates by name #349

Merged
merged 5 commits into from
Nov 4, 2020

Conversation

kqdeng
Copy link
Contributor

@kqdeng kqdeng commented Oct 26, 2020

Description

Adds the ability to query templates by name.
The ListTemplates method has been changed to accept a FilterRequest instead of just Empty.
The FilterRequest has a field filter that accepts a string used to match the names of templates. A wildcard * can be used to match a sequence of zero or more characters.
Passing an empty FilterRequest will return all templates.

Why is this needed

A user might have the following templates: hello-world, ubuntu-01, ubuntu-02, ubuntu-03, goodbye-world and wants to list only the linux templates. Before, they would only be able to either list all of the templates, or only one (and only if they already know the id).
With this PR, they can just call ListTemplates with the FilterRequest's filter field to ubuntu-* and it will return only ubuntu-01, ubuntu-02, and ubuntu-03.

Fixes: #352 / ENG-9455

How Has This Been Tested?

  • manually
  • TBD

How are existing users impacted? What migration steps/scripts do we need?

Users using an older version of the tink-cli may experience errors. Best solution is to update the tink-server, tink-cli, and tink-worker to use the images built from this PR

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)
  • added unit or e2e tests
  • provided instructions on how to upgrade

@kqdeng kqdeng force-pushed the ENG-9455-query-by-name-v2 branch 2 times, most recently from 7acfae7 to 2efcae7 Compare October 26, 2020 15:23
@codecov
Copy link

codecov bot commented Oct 26, 2020

Codecov Report

Merging #349 into master will increase coverage by 0.95%.
The diff coverage is 19.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #349      +/-   ##
==========================================
+ Coverage   23.79%   24.74%   +0.95%     
==========================================
  Files          14       14              
  Lines        1244     1277      +33     
==========================================
+ Hits          296      316      +20     
- Misses        928      940      +12     
- Partials       20       21       +1     
Impacted Files Coverage Δ
http-server/http_handlers.go 6.19% <0.00%> (-0.49%) ⬇️
grpc-server/template.go 36.53% <44.44%> (+17.34%) ⬆️
grpc-server/workflow.go 21.00% <100.00%> (+0.39%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 322775a...775cdf7. Read the comment docs.

@mmlb
Copy link
Contributor

mmlb commented Oct 26, 2020

I opened up #351 to fix the whitespace issue and avoid it in the future by making sure CI catches.

@mmlb mmlb changed the title ENG-9455 query by name Support fetching templates by name Oct 26, 2020
@gianarb
Copy link
Contributor

gianarb commented Oct 26, 2020

Do we want somehow to formalize and make this filtering available for other resources? I am just trying to avoid an unfriendly proliferation of different filters that probably sounds useful short term but won't make usability nice in long term

@kqdeng
Copy link
Contributor Author

kqdeng commented Oct 27, 2020

@gianarb Can you elaborate? Are you suggesting we should also provide the option to filter by any attribute of a resource?

@gianarb
Copy link
Contributor

gianarb commented Oct 27, 2020

@kdeng3849 yeah something like that.

I am wondering if we should build this feature in a way that will allow us to get filtering done for all the resources across fields in a consistent way. Without building something ad hoc for one case.

I think having the filtering done one by one will make the UX inconsistent and not great

Copy link
Contributor

@gianarb gianarb left a comment

Choose a reason for hiding this comment

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

We need a rebase, @mmlb 's fault :P

@mmlb
Copy link
Contributor

mmlb commented Oct 27, 2020

oh that merged already? :toot:

@kqdeng kqdeng force-pushed the ENG-9455-query-by-name-v2 branch 5 times, most recently from 25ae6d9 to 8d15c9a Compare October 29, 2020 13:21
@kqdeng kqdeng requested review from gianarb and mmlb October 29, 2020 13:24
@kqdeng kqdeng requested a review from splaspood October 29, 2020 18:13
Comment on lines 120 to 121
want struct {
expectedError bool
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we make this something like:

Suggested change
want struct {
expectedError bool
}
err bool

instead? No need to define a struct for just one type and its easier to use too.

@mmlb
Copy link
Contributor

mmlb commented Oct 29, 2020

@kdeng3849 yeah something like that.

I am wondering if we should build this feature in a way that will allow us to get filtering done for all the resources across fields in a consistent way. Without building something ad hoc for one case.

I think having the filtering done one by one will make the UX inconsistent and not great

Yeah I think maybe something like

...
rpc GetTemplate(GetRequest) returns (WorkflowTemplate)
...
message GetRequest {
  oneof get_oneof {
    string id = 1;
    string name = 2;
  }
}

we can leave the other oneof options for later if necessary. I think I'd rather see a pattern we can agree on that is extensible to avoid GetBy... for each proto type. Does this line up with what you're thinking @gianarb ?

@kqdeng kqdeng requested a review from mmlb November 2, 2020 16:46
mattcburns
mattcburns previously approved these changes Nov 2, 2020
@gianarb
Copy link
Contributor

gianarb commented Nov 3, 2020

Yeah I think it sounds good @mmlb

@DavidHwu
Copy link

DavidHwu commented Nov 3, 2020

@mmlb & @gianarb this PR is blocking Central Eng (or @mattcburns ) from moving forward on a commitment integration deadline.
I've read your change requests... is this a must have or NTH (Nice To Have)?

While @mmlb comments I think is worthy... I believe this can be served in another ticket. Resulting in unblocking Matt Burns for this deadline.

gianarb
gianarb previously approved these changes Nov 3, 2020
Copy link
Contributor

@gianarb gianarb left a comment

Choose a reason for hiding this comment

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

I am having some difficulties visualizing the grpc API right now but I don't want to hold more on this :)

Comment on lines 32 to 33
grID := &template.GetRequest_Id{Id: arg}
req := template.GetRequest{GetBy: grID}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do it like this instead please:

			req := template.GetRequest{
				GetBy: &template.GetRequest_Id{
					Id: arg,
				},
			}

No need to introduce a variable that we have to remember to ignore (grID) :D

db/db.go Outdated
@@ -35,7 +36,7 @@ type hardware interface {

type template interface {
CreateTemplate(ctx context.Context, name string, data string, id uuid.UUID) error
GetTemplate(ctx context.Context, id string) (string, string, error)
GetTemplate(ctx context.Context, attributes map[string]string) (string, string, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a struct will be better to use here.

@@ -51,4 +51,9 @@ message CreateResponse {

message GetRequest {
string id = 1;
string name = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

this is in the wrong commit :D

@@ -43,7 +43,7 @@ var listCmd = &cobra.Command{
}

func listTemplates(cmd *cobra.Command, t table.Writer) {
list, err := client.TemplateClient.ListTemplates(context.Background(), &template.FilterRequest{Filter: "%"})
list, err := client.TemplateClient.ListTemplates(context.Background(), &template.FilterRequest{Filter: "*"})
Copy link
Contributor

Choose a reason for hiding this comment

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

this commit should be squashed into the previous one

@@ -2,6 +2,7 @@ package grpcserver

Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the commit message to something like

Add tests for Get filtering

@@ -270,15 +270,18 @@ func (s *server) ShowWorkflowEvents(req *workflow.GetRequest, stream workflow.Wo
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

I think adding createYaml to the commit message would help when looking through git history:

createYaml: use more descriptive argument names

Rename temp and tempData to templateID and templateData for better clarity.

@@ -36,7 +36,7 @@ type hardware interface {

type template interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

agree with this, but should just be squashed in the commit that does it :D

Comment on lines 57 to 63
message FilterRequest {
string filter = 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it'd be great to have FilterRequest look like GetRequest so that we have one way to do filtering. This would also help to convey what field the filter is taking place on.

message FilterRequest {
  one_of filter_types {
    string name = 1;
  }
}

Signed-off-by: Kelly Deng <kelly@packet.com>
Signed-off-by: Kelly Deng <kelly@packet.com>
Signed-off-by: Kelly Deng <kelly@packet.com>
Signed-off-by: Kelly Deng <kelly@packet.com>
@mmlb mmlb removed the request for review from splaspood November 4, 2020 19:10
@mmlb mmlb added the ready-to-merge Signal to Mergify to merge the PR. label Nov 4, 2020
@mergify mergify bot merged commit a94738e into tinkerbell:master Nov 4, 2020
mergify bot added a commit that referenced this pull request Nov 13, 2020
## Description

Fetching a template by name now also returns the associated ID.

## Why is this needed

A recent PR #349 added the functionality of fetching a template by name. The returned template is expected to include the ID, name, and template data. However, currently, it would only return the name and the template data. The returned ID is just an empty string.

## How Has This Been Tested?

Manually

## How are existing users impacted? What migration steps/scripts do we need?

## Checklist:

I have:

- [ ] updated the documentation and/or roadmap (if required)
- [x] added unit or e2e tests
- [ ] provided instructions on how to upgrade
@mmlb mmlb removed the ready-to-merge Signal to Mergify to merge the PR. label Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to query and filter template by name
5 participants