-
Notifications
You must be signed in to change notification settings - Fork 72
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
Conversation
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.
Nice changes, left some additional improvements 👍🏻
docs/commands/rhoas_kafka_list.adoc
Outdated
@@ -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 |
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.
It should be clear that this searches all fields.
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.
Or rather, it should say which fields are searched.
pkg/cmd/kafka/list/list.go
Outdated
var queryString string | ||
|
||
if search != "" { | ||
queryString = fmt.Sprintf( |
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 would also have search on the ID field.
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.
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
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.
Fair enough, ignore me so :)
pkg/cmd/kafka/list/list.go
Outdated
@@ -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)) |
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.
a = a.Search(buildQuery(opts.search)) | |
if opts.search != "" { | |
a = a.Search(buildQuery(opts.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.
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' |
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.
It should be clear on which fields it will 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.
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?
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.
No I think that sounds good!
1d3d2d6
to
987f1c7
Compare
Needs rebase. Can't verify yet until staging is fixed. |
7dc34db
to
8889a1e
Compare
Rebased |
❯ 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. |
Search flag has been added to kafka list to filter by text. fixes #181
8889a1e
to
8b122a8
Compare
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.
Left a couple of final optional changes you could make, but they are nitpicks. Approving! 👍🏻
pkg/cmd/kafka/list/list.go
Outdated
|
||
if opts.search != "" { | ||
|
||
if err = kafka.ValidateSearchInput(opts.search); 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.
Usually we do this validation inside RunE
(as early as possible)
locales/kafka/active.en.toml
Outdated
[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: |
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.
Error messages should begin with a lowercase in Go. This is because it will usually be prefixed with something like "Error: ":
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 { |
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.
You should add a comment documenting the purpose of this function
18367f8
to
dcdb517
Compare
Search flag has been added to kafka list to filter by text.
fixes #181