-
Notifications
You must be signed in to change notification settings - Fork 881
feat(runs): apply settings to the run spec at run creation #7961
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
Open
davidlin20dev
wants to merge
3
commits into
flyteorg:main
Choose a base branch
from
davidlin20dev:feat/settings-run-applier
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package service | ||
|
|
||
| import ( | ||
| "github.com/flyteorg/flyte/v2/gen/go/flyteidl2/settings" | ||
| "github.com/flyteorg/flyte/v2/gen/go/flyteidl2/task" | ||
| ) | ||
|
|
||
| // applyRunSettings fills fields the caller left unset with values resolved from | ||
| // settings. An explicit value in the request always wins, so this only ever fills | ||
| // gaps, and a setting that is INHERIT or UNSET contributes nothing. | ||
| func applyRunSettings(spec *task.RunSpec, resolved *settings.Settings) { | ||
| if spec == nil { | ||
| return | ||
| } | ||
|
|
||
| if spec.GetQueue() == "" && resolved.GetRun().GetDefaultQueue().GetState() == | ||
| settings.SettingState_SETTING_STATE_VALUE { | ||
| spec.Queue = resolved.GetRun().GetDefaultQueue().GetStringValue() | ||
| } | ||
|
|
||
| // The proto defines 0 as unset for this field, so there is no explicit request for | ||
| // "unlimited" to override. The settings validator bounds the value to 0 or | ||
| // [2, MaxUint32], so narrowing to uint32 cannot overflow. | ||
| if concurrency := resolved.GetRun().GetMaxActionConcurrency(); spec.GetMaxActionConcurrency() == 0 && | ||
| concurrency.GetState() == settings.SettingState_SETTING_STATE_VALUE { | ||
| spec.MaxActionConcurrency = uint32(concurrency.GetIntValue()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package service | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/flyteorg/flyte/v2/gen/go/flyteidl2/settings" | ||
| "github.com/flyteorg/flyte/v2/gen/go/flyteidl2/task" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func runSettings(queue *settings.StringSetting, concurrency *settings.Int64Setting) *settings.Settings { | ||
| return &settings.Settings{ | ||
| Run: &settings.RunSettings{DefaultQueue: queue, MaxActionConcurrency: concurrency}, | ||
| } | ||
| } | ||
|
|
||
| func TestApplyRunSettings(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| spec *task.RunSpec | ||
| resolved *settings.Settings | ||
| wantQueue string | ||
| wantConcurrency uint32 | ||
| }{ | ||
| { | ||
| name: "empty queue takes the settings value", | ||
| spec: &task.RunSpec{}, | ||
| resolved: runSettings(&settings.StringSetting{State: stateValue, StringValue: "fast-queue"}, nil), | ||
| wantQueue: "fast-queue", | ||
| }, | ||
| { | ||
| name: "an explicit queue wins over settings", | ||
| spec: &task.RunSpec{Queue: "user-queue"}, | ||
| resolved: runSettings(&settings.StringSetting{State: stateValue, StringValue: "fast-queue"}, nil), | ||
| wantQueue: "user-queue", | ||
| }, | ||
| { | ||
| name: "a queue in INHERIT contributes nothing", | ||
| spec: &task.RunSpec{}, | ||
| resolved: runSettings(&settings.StringSetting{State: stateInherit, StringValue: "fast-queue"}, nil), | ||
| wantQueue: "", | ||
| }, | ||
| { | ||
| name: "zero concurrency takes the settings value", | ||
| spec: &task.RunSpec{}, | ||
| resolved: runSettings(nil, &settings.Int64Setting{State: stateValue, IntValue: 5}), | ||
| wantConcurrency: 5, | ||
| }, | ||
| { | ||
| name: "an explicit concurrency wins over settings", | ||
| spec: &task.RunSpec{MaxActionConcurrency: 3}, | ||
| resolved: runSettings(nil, &settings.Int64Setting{State: stateValue, IntValue: 5}), | ||
| wantConcurrency: 3, | ||
| }, | ||
| { | ||
| name: "concurrency in UNSET contributes nothing", | ||
| spec: &task.RunSpec{}, | ||
| resolved: runSettings(nil, &settings.Int64Setting{State: stateUnset, IntValue: 5}), | ||
| wantConcurrency: 0, | ||
| }, | ||
| { | ||
| name: "no settings at all", | ||
| spec: &task.RunSpec{}, | ||
| resolved: &settings.Settings{}, | ||
| }, | ||
| { | ||
| name: "nil spec does not panic", | ||
| spec: nil, | ||
| resolved: runSettings(&settings.StringSetting{State: stateValue, StringValue: "fast-queue"}, nil), | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| applyRunSettings(tt.spec, tt.resolved) | ||
| assert.Equal(t, tt.wantQueue, tt.spec.GetQueue()) | ||
| assert.Equal(t, tt.wantConcurrency, tt.spec.GetMaxActionConcurrency()) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 OSS decision was to not support orgs, ( #7157 removed it from every table and service, and the backend is meant to ignore it). The settings key shouldnt take org from the request. The SDK derives an org from the endpoint hostname, so a named run can look up
v1:<host>::and miss the row scheduled runs hit.Maybe
EncodeSettingsKeycan ignore org, so settings are stored and looked up under the same key no matter what the client sendsThere 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.
Makes sense, thanks for the review! Unnamed runs drop the org as well, so the fix covers that path too. I'll make EncodeSettingsKey ignore org in a separate PR and remove the org note from this one.