-
Notifications
You must be signed in to change notification settings - Fork 674
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
Minimum validation for multitenant formations #5199
Minimum validation for multitenant formations #5199
Conversation
@@ -2837,6 +2875,30 @@ func validateGroupHostFlavor(groupId string, resourceName string, group *Group) | |||
return nil | |||
} | |||
|
|||
func validateMultitenantMemoryCpu(groupId string, resourceName string, resourceDefaults *Group, group *Group) 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.
Not sure what Go conventions are (just learning), but you might be able to put guard clauses in here to simplify the rest of your code. Like in the first line of this method:
if group.CPU != nil {
return nil
}
return fmt.Errorf("We were unable to complete your request: group.memory requires a minimum of %d megabytes. Try again with valid values or contact support if the issue persists.", resourceDefaults.Memory.Minimum) | ||
} | ||
|
||
if group.CPU != nil && group.Memory.Allocation < cpuEnforcementRatioCeiling*resourceDefaults.Members.Minimum && group.Memory.Allocation > group.CPU.Allocation*resourceDefaults.Memory.CPUEnforcementRatioMb { |
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.
cpuEnforcementRatioCeiling*resourceDefaults.Members.Minimum
will work for provisioning, but a customer might have horizontally scaled, so we'd need you use cpuEnforcementRatioCeiling*resourceDefaults.Members.allocationCount
, right?
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.
@bpeicher yup you're correct! Thank you for catching that!
// TODO: Replace this with resourceDefaults.Memory.CPUEnforcementRatioCeiling when it is fixed | ||
cpuEnforcementRatioCeiling := 16384 |
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.
When will this fix go in? Will that be before merging this PR?
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.
@obai-1 This fix won't go in until the next release cut and deployment, so we're looking at around May.
This PR will be merged sometime thing week. So that's why we gotta hard code the cpuEnforcementRatioCeiling for now.
@@ -2837,6 +2870,39 @@ func validateGroupHostFlavor(groupId string, resourceName string, group *Group) | |||
return nil | |||
} | |||
|
|||
func validateMultitenantMemoryCpu(groupId string, resourceName string, resourceDefaults *Group, group *Group) 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.
Do you need resourceName
parameter here?
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.
Nope! Thank you for catching that 😄
// This means the CPUEnforcementRatioMb was not sent, which means we are dealing with a non-multitenant going to a multitenat | ||
if cpuEnforcmentRationMb == 0 { | ||
cpuEnforcmentRationMb = 8192 | ||
} |
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.
if cpuEnforcmentRationMb
is coming from resourceDefaults
is this logic required here?
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.
@obai-1 There is an edge case, when a user is has an existing databases and is going from non-multitenant
to multitenant
. In that case, we use the deployments/:id/groups
API endpoint to get the database current configuration.
However, the deployments/:id/groups
does not have the host_flavor
query param. In other words, we do not get the cpuEnforcementRatioCeiling
or the cpuEnforcementRatioMb
.
So we have one of 2 options:
- Call the
deployables/{type}/group
. Process the result, extract the ratios from it, and pass those into the function as well. This is a large amount of code that will have to be removed regardless as the enforcement ratios and query parameter are going to go away soonish, per the following "when the old hosting model goes away, so do these query string parameters". - Account for the edge case by hard-coding the cpuEnforcementRatio in the event the API didn't return it.
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.
as the enforcement ratios and query parameter are going to go away soonish
Hmm.. unless I am missing something, they are not going away anytime soon..
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.
Also hardcoding these numbers here is not safe. Those numbers could change down the line, and could also be db specific. Remember once we release it out to the wild, it is hard to take it back :)
return nil | ||
} | ||
|
||
if group.CPU != nil && group.CPU.Allocation > 2 { |
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 be something like group.CPU.Allocation >= EnforcementRatioCeiling/EnforcementRatio
return nil | ||
} | ||
|
||
if group.CPU != nil && group.Memory.Allocation*resourceDefaults.Members.Allocation < cpuEnforcementRatioCeilingTemp*resourceDefaults.Members.Allocation && group.Memory.Allocation*resourceDefaults.Members.Allocation > group.CPU.Allocation*cpuEnforcementRatioMb { |
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.
Is this validation useful, since you are not going to have any fractional values in group.CPU
?
defaultList, err := getDefaultScalingGroups(service, plan, "multitenant", meta) | ||
|
||
if err != nil { | ||
return 0, 0 |
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 would be better to propagate the error upward from here, rather than returning 0, 0.
Something like return err, 0, 0
// Get default or current group scaling values | ||
for _, group := range tfGroups { | ||
if group == nil { | ||
break |
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.
Would continue
be better than break
here?
if group.CPU == nil { | ||
return nil | ||
} | ||
|
||
if group.CPU.Allocation == 0 { | ||
return 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.
Nit: these can be combined with ||
* added minimum-validation logic * refactored minimum compute code * updated tests to pass with enforced minimums * used cloud-databases-go-sdk version 0.6.0 * added getCpuEnforcementRatios to get use the cpu enforcement ratios in all the different scenarios * editted validateMultitenant Function to match CLI and Provisioning-ui * made changes requested in latest PR review
Community Note
Relates OR Closes #0000
Testing Done
Provisioning with Redis
Provisioning multitenant Redis with insufficient memory
Provisioning multitenant Redis with below-ratio memory
Provisioning multitenant Redis with exact-ratio memory
Provisioning multitenant Redis with Invalid Ratio
Provisioning with RabbitMQ
Provisioning multitenant RabbitMQ with insufficient memory
Scaling
Scaling non-multitenant to multitenant
Initial Non-Multitenant Formation
Convert to Multitenant Formation with Invalid CPU Ratio
Result
Convert to Multitenant Formation
Result
Scale Multitenant Formation Below Acceptable Memory
Result
Scale Multitenant Formation With Acceptable Memory
Result
Acceptance Test