-
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
fix(kafka create): reduce number of calls made to AMS API #1596
Conversation
pkg/cmd/kafka/create/completions.go
Outdated
quotaCostList, err := accountmgmtutil.FetchOrgQuotaCost(f.Context, conn) | ||
if err != nil { | ||
return nil, directive | ||
} | ||
|
||
userInstanceType, _ := accountmgmtutil.GetUserSupportedInstanceType(quotaCostList, &constants.Kafka.Ams) |
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.
There are two ways to look at this:
- We can make single call and return structure that contains all high level objects
our create command needs - Have one call that returns some raw api object that contains a lot of non useful data
Here we are using approach nr2. While it is ok this has some problems:
- 2 calls needed - result of the first call exposes too many fields that are low level.
There is no enough encapsulation - Verbose usage - 2 calls needed - error handling is not well defined and will return
low level info to user - Not clear what method to use to get high level info for the CLI
While this PR is acceptable I personally feel that we should be using encapsulation more.
This means that we should avoid using:
GetValidMarketplaces(quotaCostList *amsclient.QuotaCostList)
And look to create our own CLi structures that represent values that we really want to operate in CLI
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.
There was already existing structure that we were returning from the AMS calls that contained type of quota and remaining amount. I think we should extend that structure:
@rkpattnaik780 I was requested to review this but are you still making changes that Wojciech suggested? |
Let's ignore reviewing this for now |
3c4b032
to
136e35d
Compare
@@ -225,7 +234,7 @@ func runCreate(opts *options) error { | |||
return f.Localizer.MustLocalizeError("kafka.create.error.noInteractiveMode") | |||
} | |||
|
|||
payload, err = promptKafkaPayload(opts, *userInstanceType) | |||
payload, err = promptKafkaPayload(opts, userInstanceType) |
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 interactive mode needs more changes, currently the user will need to specify BillingModel
as flag before starting the interactive mode.
pkg/cmd/kafka/create/create.go
Outdated
if err != nil || userInstanceType == nil { | ||
return f.Localizer.MustLocalizeError("kafka.create.error.userInstanceType.notFound") | ||
} | ||
|
||
if opts.billingModel == "marketplace" { |
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 see this logic happening outside create command
pkg/cmd/kafka/create/create.go
Outdated
|
||
billingModelPrompt := &survey.Select{ | ||
Message: "Billing model:", | ||
Options: kafkacmdutil.ValidBillingModels, |
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.
That will outdate fast as new billing models should be introduced.
I think the best tradeoffs would be to return error to user from ams package containing billing models he can create when invalid is provided or billing model is missing.
pkg/shared/accountmgmtutil/ams.go
Outdated
} | ||
|
||
func GetUserSupportedInstanceType(ctx context.Context, spec *remote.AmsConfig, conn connection.Connection) (quota *QuotaSpec, err error) { | ||
userInstanceTypes, err := GetUserSupportedInstanceTypes(ctx, spec, conn) | ||
func GetUserSupportedInstanceType(ctx context.Context, spec *remote.AmsConfig, conn connection.Connection, billingModel string) (quota *QuotaSpec, err 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.
This method should probably include marketplaceId and marketplaceType. Just billing model would not be enough for us to return single quota (there will be situations when multiple quotas are returned
pkg/shared/accountmgmtutil/ams.go
Outdated
func BattleOfInstanceBillingModels(quotas []QuotaSpec) []QuotaSpec { | ||
var betterQuotasMap map[string]*QuotaSpec = make(map[string]*QuotaSpec) | ||
alwaysWinsBillingModel := "standard" | ||
func BattleOfInstanceBillingModels(quotas []QuotaSpec, alwaysWinsBillingModel string) []QuotaSpec { |
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.
This method should be removed.
I think PR trying to do too much. I would suggest to:
func getMeQuotaFor(billingType *string,
marketplaceProvider *string,
cloudAccountId *string) (*Quota, err) {
// match all arguments to the
// quota objects and return single one
// return error if: cannot find quota object
// and size of quota object is larger than 1.
}
|
@rkpattnaik780 hope that helps |
return nil, errors.New("accountID cant be provided with standard billing model") | ||
} | ||
|
||
if (cloudAccountID != "") != (marketplace != "") { |
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.
Very clever pattern!
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 have noticed that this does not work with Trial instances. I can fix that on friday without worries |
)" This reverts commit 5346fc1.
Re-use
QuotaCostList
wherever possible.Follow up for #1593
Type of change