-
Notifications
You must be signed in to change notification settings - Fork 359
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
chore: add checkpoint and max slots config policy enforcements in PATCH experiment #10125
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10125 +/- ##
==========================================
- Coverage 58.87% 54.56% -4.32%
==========================================
Files 757 1267 +510
Lines 106045 159610 +53565
Branches 3637 3636 -1
==========================================
+ Hits 62435 87084 +24649
- Misses 43477 72393 +28916
Partials 133 133
Flags with carried forward coverage won't be shown. Click here to find out more.
|
✅ Deploy Preview for determined-ui canceled.
|
a33456e
to
bb87e37
Compare
7ec5781
to
afe5e43
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.
Some suggestions - PR looks great in general.
} | ||
ctx := context.TODO() | ||
return workspace.WorkspaceByName(ctx, wkspName) | ||
} |
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 refactor
require.NoError(t, err) | ||
require.Equal(t, *wkspName, w.Name) | ||
}) | ||
} |
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.
❤️ love that you unit tested getWorkspaceByConfig
!
@@ -113,3 +114,55 @@ func DeleteConfigPolicies(ctx context.Context, | |||
} | |||
return nil | |||
} | |||
|
|||
// GetEnforcedConfig gets the fields of the global invariant config or constraint if specified, and | |||
// the workspace invariant config or constraint otherwise. If neither is specified, returns 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.
Nice function description. I recommend describing what the function does, and then describing the priority order. So something like
// GetEnforcedConfig fetches the field from an invariant_config or constraints policyType,
in order of precedence. Global scope has highest precedence, then workspace.
Returns nil if none is found.
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 find the field format to be unintuitive. e.g. "'resources' -> 'max_slots'"
Could you add an example to the function description? Or at least as a comment within the function?
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 like the func description change! Changed this and added an example for the field
arg
@@ -113,3 +114,55 @@ func DeleteConfigPolicies(ctx context.Context, | |||
} | |||
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.
GetEnforcedConfig
is fine as a name. I think something like GetConfigPolicyField
is more descriptive. When I first read the function name, I thought it was only for invariant configs. It also wasn't clear that it was fetching a single field, rather than a whole or partial config.
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.
Great point! Changed this
if policyType != "invariant_config" && policyType != "constraints" { | ||
return nil, fmt.Errorf("invalid policy type :%s", policyType) | ||
} | ||
|
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.
Please also validate workloadType
; I think all our other postgres functions do. There's no need to add a test case for 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.
it seems like we actually don't validate workloadType
in any of the postgres functions! At first this seemed odd, but then I remembered we made workload_type
an enum!
I can still perform the validation if you'd like, but this function would be unique in that regard
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.
In that case, don't add it. I was mistaken!
*msg.MaxSlots > *maxSlotsLimit { | ||
log.Warnf("unable to set max slots") | ||
return | ||
} |
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 think this code should be in a separate function, preferably in configpolicies
package. The main reason is that I prefer to keep "config policy logic" in configpolicies
. In other words, an experiment API has no need to know how config policies work, that there's invariant_configs and constraints, precedence, etc. Ideally we would be able to change how config policies work by only changing code in configpolicies
files.
The other reason is that the logic can be simplified if it's in its own function. The function could return at line 431 and then have no need to check enforcedMaxSlots == nil
on line 442.
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.
Love this idea, and makes sense! moved this work into its own func, great idea!
70b0d5e
to
2ce783a
Compare
// enforced max slots for the workspace if that's set as an invariant config, and returns the | ||
// requested max slots otherwise. Returns an error when max slots is not set as an invariant config | ||
// and the requested max slots violates the constriant. | ||
func CanSetMaxSlots(slotsReq *int, wkspID int) (bool, *int, 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.
The function should return bool, int, error
or *int, error
. In the first return group, the bool lets the caller know if int was set or not. In the second group, a valid int is inferred from whether or not the pointer is nil.
I would simplify it further to just int, error
. If there's an error, max_slots
cannot be updated. If error is nil, then set max_slots
to the returned int value.
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.
Great point, changed return type to *int, 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.
Ahh wait ok i see your point about int, error!
hmm, yes i see! ok ill change to this
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.
Gah ok actually, I think it's easier to keep this as is since the func takes in an optional *int (so it can return that same optional *int).
So when the caller gets the func output, it can just replace its input w the func output.
Are you cool w leaving it *int, error
instead of int, error
?
Ticket
CM-583
Description
add checkpoint and max slots config policy enforcements in PATCH experiment
Test Plan
CI passes.
Checklist
docs/release-notes/
See Release Note for details.