feat(kafka topic list): add flags for pagination#810
Conversation
|
|
||
| [kafka.topic.list.flag.page.description] | ||
| description = 'Description for the --page flag' | ||
| one = 'Current page number for list of topics' |
There was a problem hiding this comment.
| one = 'Current page number for list of topics' | |
| one = 'Current page number for list of topics.' |
|
|
||
| [kafka.topic.list.flag.size.description] | ||
| description = 'Description for the --size flag' | ||
| one = 'Maximum number of items to be returned per page' |
There was a problem hiding this comment.
| one = 'Maximum number of items to be returned per page' | |
| one = 'Maximum number of items to be returned per page.' |
|
Good from technical standpoint. Does that works against stage? |
Yes it does, I will fix the build and re-request reviews. |
craicoverflow
left a comment
There was a problem hiding this comment.
Some changes needed.
pkg/cmd/kafka/topic/list/list.go
Outdated
| const ( | ||
| defaultPage = 1 | ||
| defaultSize = 10 | ||
| ) |
There was a problem hiding this comment.
I think we should extract these int a common place which can be used by ALL list commands. Maybe even as a build variable?
There was a problem hiding this comment.
You could assign these as the default values when creating Options.
There was a problem hiding this comment.
Had to deviate from our current approach as vs code was showing multiple lint warnings/errors, do you want me to fallback to conventional method.
There was a problem hiding this comment.
What were the lint errors?
There was a problem hiding this comment.
Something like avoid magic numbers, create a named constant.
I don't see them anymore though, build seems to pass as well.
There was a problem hiding this comment.
You can created a named var in the build package and reference this instead? Something like build.DefaultPageSize
There was a problem hiding this comment.
This does not seem a very good idea. Other build variables seem to have a different context than stuffs like default values for page and size. Can we put it at some level lower than build?
There was a problem hiding this comment.
You are right, and yes we can! But we can still make it externally configurable without having it be specifically in build. So wherever you decide to put it, make it configurable in the same way
There was a problem hiding this comment.
Have put them in cmdutil package, let me know what you think.
pkg/cmd/kafka/topic/list/list.go
Outdated
| } | ||
| } | ||
|
|
||
| validator := &topicutil.Validator{ |
There was a problem hiding this comment.
| validator := &topicutil.Validator{ | |
| validator := topicutil.Validator{ |
The pointer is not needed here.
pkg/cmd/kafka/topic/list/list.go
Outdated
| } | ||
|
|
||
| if opts.search != "" { | ||
| validator := &topicutil.Validator{ |
There was a problem hiding this comment.
| validator := &topicutil.Validator{ | |
| validator := topicutil.Validator{ |
Not needed.
pkg/cmd/kafka/topic/list/list.go
Outdated
| if opts.size != defaultSize { | ||
| a = a.Size(int32(opts.size)) | ||
| } |
There was a problem hiding this comment.
I don't see where defaultSize ever gets used by the API client?
pkg/cmd/kafka/topic/list/list.go
Outdated
| a = a.Size(int32(opts.size)) | ||
| } | ||
|
|
||
| if opts.page != defaultPage { |
There was a problem hiding this comment.
I don't see where defaultPage ever gets used by the API client?
There was a problem hiding this comment.
If the backend changes the default size to 20 for example, the CLI will continue to use 10 as the default value. The user may enter --size=10 as the page size, but pagination will not be effective because the comparison is happening against the local defaultSize value.
I think we should have a single, common defaultSize which can be used in control plane and data plane APIs. This gives the CLI more control over pagination defaults and can ensure consistency when different APIs have different defaults.
Make sense?
There was a problem hiding this comment.
Also - think about upstream. Default value of 10 is an implementation detail of RHOAS service APIs, but if this CLI could be reused within a different environment upstream those defaults could be completely different.
pkg/cmd/kafka/topic/list/list.go
Outdated
| kafkaID string | ||
| output string | ||
| search string | ||
| page int |
There was a problem hiding this comment.
| page int | |
| page int32 |
pkg/cmd/kafka/topic/list/list.go
Outdated
| output string | ||
| search string | ||
| page int | ||
| size int |
There was a problem hiding this comment.
| size int | |
| size int32 |
pkg/kafka/topic/validators.go
Outdated
|
|
||
| // ValidatePage validates the value of page flag | ||
| // the valid values can range from [1,...] | ||
| func (v *Validator) ValidatePage(val interface{}) error { |
There was a problem hiding this comment.
Passing an interface{} and type checking is a bit expensive - we are using it in the other validators as it is a requirement to satisfy the survey interactive requirements..but for pagination we will never use it in such a way so you can pass the known type.
There was a problem hiding this comment.
Did this thinking about consistency, we should validate on client side if these flags are greater than zero. Else we'll get a 400 from server.
There was a problem hiding this comment.
Yes, we should still validate the page, but no need to pass an interface{}, just the int type will do.
20727b6 to
a667c59
Compare
|
Hi @bhardesty. I am seeing some inconsistencies regarding use of periods in flag descriptions. Some flags end with period and some don't. As suggested by @craicoverflow we shouldn't use periods as the flags provided by cobra ( |
2eecfd5 to
20a2494
Compare
| DefaultPageSize = 10 | ||
|
|
||
| // DefaultPageNumber is the default page number when using list commands | ||
| DefaultPageNumber = 1 |
There was a problem hiding this comment.
I think these needs to to be vars to be configurable at build-time.
There was a problem hiding this comment.
Build variables can only be a string 🤔 Leave it like this for now and we can figure out how to configure it later (leave a TODO)
There was a problem hiding this comment.
Checked now it doesnt work as expected! It needs to be addressed in a follow-up.
| DefaultJSONIndent = " " | ||
|
|
||
| // DefaultPageSize is the default number of items per page when using list commands | ||
| DefaultPageSize = 10 |
There was a problem hiding this comment.
In a follow up PR, could you apply these wherever there is pagination?


add
--pageand--sizeflag tokafka topic listcommand so user can navigate to different pages and adjust capacity of a page.Addresses #766
Verification Steps
kafka listcommand with page and size flag.Type of change
Checklist