Skip to content

feat(kafka topic list): add flags for pagination#810

Merged
rkpattnaik780 merged 8 commits intomainfrom
topic_pagination
Jul 12, 2021
Merged

feat(kafka topic list): add flags for pagination#810
rkpattnaik780 merged 8 commits intomainfrom
topic_pagination

Conversation

@rkpattnaik780
Copy link
Contributor

add --page and --size flag to kafka topic list command so user can navigate to different pages and adjust capacity of a page.

Addresses #766

Verification Steps

  1. Run the kafka list command with page and size flag.

go run ./cmd/rhoas kafka topic list --page 1 --size 1

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation change
  • Other (please specify)

Checklist

  • Documentation added for the feature
  • CI and all relevant tests are passing
  • Code Review completed
  • Verified independently by reviewer


[kafka.topic.list.flag.page.description]
description = 'Description for the --page flag'
one = 'Current page number for list of topics'
Copy link
Contributor

@bhardesty bhardesty Jul 7, 2021

Choose a reason for hiding this comment

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

Suggested change
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'
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
one = 'Maximum number of items to be returned per page'
one = 'Maximum number of items to be returned per page.'

@wtrocki
Copy link
Collaborator

wtrocki commented Jul 7, 2021

Good from technical standpoint. Does that works against stage?

@rkpattnaik780
Copy link
Contributor Author

Good from technical standpoint. Does that works against stage?

Yes it does, I will fix the build and re-request reviews.

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.

Some changes needed.

Comment on lines +43 to +46
const (
defaultPage = 1
defaultSize = 10
)
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 we should extract these int a common place which can be used by ALL list commands. Maybe even as a build variable?

Copy link
Contributor

Choose a reason for hiding this comment

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

You could assign these as the default values when creating Options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

What were the lint errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something like avoid magic numbers, create a named constant.

I don't see them anymore though, build seems to pass as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can created a named var in the build package and reference this instead? Something like build.DefaultPageSize

Copy link
Contributor Author

@rkpattnaik780 rkpattnaik780 Jul 8, 2021

Choose a reason for hiding this comment

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

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have put them in cmdutil package, let me know what you think.

}
}

validator := &topicutil.Validator{
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
validator := &topicutil.Validator{
validator := topicutil.Validator{

The pointer is not needed here.

}

if opts.search != "" {
validator := &topicutil.Validator{
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
validator := &topicutil.Validator{
validator := topicutil.Validator{

Not needed.

Comment on lines +147 to +149
if opts.size != defaultSize {
a = a.Size(int32(opts.size))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see where defaultSize ever gets used by the API client?

a = a.Size(int32(opts.size))
}

if opts.page != defaultPage {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see where defaultPage ever gets used by the API client?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These defaults are returned by the response when we don't set flags manually.
Screenshot from 2021-07-08 18-22-18
Should we let go of that check?

Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

kafkaID string
output string
search string
page int
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
page int
page int32

output string
search string
page int
size int
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
size int
size int32


// ValidatePage validates the value of page flag
// the valid values can range from [1,...]
func (v *Validator) ValidatePage(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.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we should still validate the page, but no need to pass an interface{}, just the int type will do.

@rkpattnaik780
Copy link
Contributor Author

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 (--default and --help) don't use them too. Would you like this to be addressed in another issue, we can finalize a convention and fix the descriptions?

Screenshot from 2021-07-09 17-07-07

Comment on lines +8 to +11
DefaultPageSize = 10

// DefaultPageNumber is the default page number when using list commands
DefaultPageNumber = 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 these needs to to be vars to be configurable at build-time.

Copy link
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Contributor

Choose a reason for hiding this comment

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

In a follow up PR, could you apply these wherever there is pagination?

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.

4 participants