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

feat(kafka list): add search flag #364

Merged
merged 5 commits into from
Feb 23, 2021
Merged

feat(kafka list): add search flag #364

merged 5 commits into from
Feb 23, 2021

Conversation

rkpattnaik780
Copy link
Contributor

Search flag has been added to kafka list to filter by text.

fixes #181

Copy link
Contributor

@craicoverflow craicoverflow left a comment

Choose a reason for hiding this comment

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

Nice changes, left some additional improvements 👍🏻

@@ -23,6 +23,7 @@ rhoas kafka list [flags]
--limit int The maximum number of Kafka instances to be returned (default 100)
-o, --output string Format in which to display the Kafka instances. Choose from: "json", "yml", "yaml"
--page int Display the Kafka instances from the specified page number.
--search string Text search to filter the Kafka instances
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be clear that this searches all fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or rather, it should say which fields are searched.

var queryString string

if search != "" {
queryString = fmt.Sprintf(
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also have search on the ID field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The kafka list endpoint doesn't support searching through the id column.

Failed to parse search query: Unsupported column name for search: 'id'. Supported column names are: region, name, cloud_provider, status, owner. Query invalid: id like 10

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough, ignore me so :)

@@ -95,6 +99,7 @@ func runList(opts *options) error {
a := api.Kafka().ListKafkas(context.Background())
a = a.Page(strconv.Itoa(opts.page))
a = a.Size(strconv.Itoa(opts.limit))
a = a.Search(buildQuery(opts.search))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
a = a.Search(buildQuery(opts.search))
if opts.search != "" {
a = a.Search(buildQuery(opts.search))
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I also think this is a great place to have a debug log of the search query :)

@@ -40,6 +40,10 @@ one = 'Display the Kafka instances from the specified page number.'
description = 'Description for the --limit flag'
one = 'The maximum number of Kafka instances to be returned'

[kafka.list.flag.search]
description = 'Description for the --search flag'
one = 'Text search to filter the Kafka instances'
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be clear on which fields it will search.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we make it something like Text search to filter the kafka instances by name, owner, cloud_provider, region and status.
Can you suggest something better?

Copy link
Contributor

Choose a reason for hiding this comment

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

No I think that sounds good!

@craicoverflow
Copy link
Contributor

Needs rebase. Can't verify yet until staging is fixed.

@rkpattnaik780
Copy link
Contributor Author

Needs rebase. Can't verify yet until staging is fixed.

Rebased

@craicoverflow
Copy link
Contributor

❯ rhoas kafka list --search "enda test"
Error: Failed to parse search query: Unable to list kafka requests for ephelan_kafka_devexp: MGD-SERV-API-23: Failed to parse search query: Provided search query seems incomplete: 'name like %enda test% or owner like %enda test% or cloud_provider like %enda test% or region like %enda test% or status like %enda test%'

Having a space in the query throws an API error. It is best to validate this client-side.

We could throw an error in the CLI if the search query has spaces? What do you think?

@rkpattnaik780
Copy link
Contributor Author

rkpattnaik780 commented Feb 22, 2021

❯ rhoas kafka list --search "enda test"
Error: Failed to parse search query: Unable to list kafka requests for ephelan_kafka_devexp: MGD-SERV-API-23: Failed to parse search query: Provided search query seems incomplete: 'name like %enda test% or owner like %enda test% or cloud_provider like %enda test% or region like %enda test% or status like %enda test%'

Having a space in the query throws an API error. It is best to validate this client-side.

We could throw an error in the CLI if the search query has spaces? What do you think?

Yes, that will be better. I will look into it.
Do you think we should throw errors for other unsupported chars as well, the server expects search values to conform to '^([a-zA-Z0-9-_%]*[a-zA-Z0-9-_%])?$', maybe we should use this one for validation.
What do you think @craicoverflow ?

Copy link
Contributor

@craicoverflow craicoverflow left a comment

Choose a reason for hiding this comment

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

Left a couple of final optional changes you could make, but they are nitpicks. Approving! 👍🏻


if opts.search != "" {

if err = kafka.ValidateSearchInput(opts.search); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Usually we do this validation inside RunE (as early as possible)

[kafka.validation.error.invalidSearchValue]
description = 'Error message when invalid search input is provided'
one = '''
Illegal search value "{{.Search}}", search input must satisfy the following conditions:
Copy link
Contributor

Choose a reason for hiding this comment

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

Error messages should begin with a lowercase in Go. This is because it will usually be prefixed with something like "Error: ":

Suggested change
Illegal search value "{{.Search}}", search input must satisfy the following conditions:
illegal search value "{{.Search}}", search input must satisfy the following conditions:

@@ -69,3 +70,30 @@ func TransformKafkaRequest(kafka *kasclient.KafkaRequest) *kasclient.KafkaReques

return kafka
}

func ValidateSearchInput(val interface{}) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should add a comment documenting the purpose of this function

@rkpattnaik780 rkpattnaik780 merged commit 7e2b9c1 into main Feb 23, 2021
@rkpattnaik780 rkpattnaik780 deleted the kafka_list_search branch February 23, 2021 12:10
@rkpattnaik780 rkpattnaik780 mentioned this pull request Oct 4, 2021
9 tasks
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.

Implement search on rhoas kafka list command
2 participants