-
Notifications
You must be signed in to change notification settings - Fork 3
feat(speculation): add prioritizer + prioritization-limit extensions #320
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
behinddwalls
wants to merge
1
commit into
preetam/ext/speculation-selector
Choose a base branch
from
preetam/ext/speculation-prioritizer
base: preetam/ext/speculation-selector
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.
+647
−1
Open
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions
8
submitqueue/extension/speculation/prioritizationlimit/BUILD.bazel
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,8 @@ | ||
| load("@rules_go//go:def.bzl", "go_library") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = ["prioritizationlimit.go"], | ||
| importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/prioritizationlimit", | ||
| visibility = ["//visibility:public"], | ||
| ) |
17 changes: 17 additions & 0 deletions
17
submitqueue/extension/speculation/prioritizationlimit/README.md
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,17 @@ | ||
| # Prioritization Limit | ||
|
|
||
| Vendor-agnostic "how much" policy that bounds how many builds a queue may run at once — the queue's concurrent-build budget. | ||
|
|
||
| See the [Speculation RFC](/doc/rfc/submitqueue/speculation.md) for the end-to-end design and how limits fit into the two-layer speculation model. | ||
|
|
||
| ## Prioritization Limit | ||
|
|
||
| The prioritization limit is the [prioritizer](../prioritizer)'s companion. The prioritizer decides **which** of the queue's pending builds run — its ranking across all in-flight batches; the prioritization limit decides **how many** fit at once. It is the queue-wide resource knob, the ultimate cap on speculation's demand on CI. | ||
|
|
||
| The value is **signal-driven**, not a fixed constant. Its primary input is the build system's available capacity, but a policy may also weigh cost budgets, time of day, or an experiment toggle. | ||
|
|
||
| It is **injected into the prioritizer** at construction and called by it, never passed as a method parameter — following the repo's extension-contract pattern, keeping the prioritizer interface limit-free and stable, and letting the limit be swapped independently of prioritizer logic. | ||
|
|
||
| ## Factory | ||
|
|
||
| A per-queue factory returns the limit policy for a queue, following the repo's extension contract. It is handed only the queue identity; the signals a policy weighs — a capacity feed, cost budgets, config — are injected at construction by the integrator in the wiring layer, which is also where the limit is handed to the prioritizer. Computing the limit itself takes no further inputs. |
19 changes: 19 additions & 0 deletions
19
submitqueue/extension/speculation/prioritizationlimit/fake/BUILD.bazel
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,19 @@ | ||
| load("@rules_go//go:def.bzl", "go_library", "go_test") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = ["fake.go"], | ||
| importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/prioritizationlimit/fake", | ||
| visibility = ["//visibility:public"], | ||
| deps = ["//submitqueue/extension/speculation/prioritizationlimit:go_default_library"], | ||
| ) | ||
|
|
||
| go_test( | ||
| name = "go_default_test", | ||
| srcs = ["fake_test.go"], | ||
| embed = [":go_default_library"], | ||
| deps = [ | ||
| "@com_github_stretchr_testify//assert:go_default_library", | ||
| "@com_github_stretchr_testify//require:go_default_library", | ||
| ], | ||
| ) |
53 changes: 53 additions & 0 deletions
53
submitqueue/extension/speculation/prioritizationlimit/fake/fake.go
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,53 @@ | ||
| // Copyright (c) 2025 Uber Technologies, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // Package fake provides a programmable prioritizationlimit.PrioritizationLimit | ||
| // for tests and examples. New sets the value returned by Limit; FailWith injects | ||
| // an error on every call. It is intended for examples and tests only, never | ||
| // production. | ||
| package fake | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/uber/submitqueue/submitqueue/extension/speculation/prioritizationlimit" | ||
| ) | ||
|
|
||
| // PrioritizationLimit is a programmable prioritizationlimit.PrioritizationLimit. | ||
| type PrioritizationLimit struct { | ||
| limit int | ||
| err error | ||
| } | ||
|
|
||
| // New returns a fake PrioritizationLimit whose Limit returns the given value. | ||
| func New(value int) *PrioritizationLimit { | ||
| return &PrioritizationLimit{limit: value} | ||
| } | ||
|
|
||
| // FailWith makes every Limit call return err. | ||
| func (l *PrioritizationLimit) FailWith(err error) *PrioritizationLimit { | ||
| l.err = err | ||
| return l | ||
| } | ||
|
|
||
| // Limit returns the configured value, or the injected error if FailWith was set. | ||
| func (l *PrioritizationLimit) Limit(_ context.Context) (int, error) { | ||
| if l.err != nil { | ||
| return 0, l.err | ||
| } | ||
| return l.limit, nil | ||
| } | ||
|
|
||
| // ensure the fake satisfies the interface. | ||
| var _ prioritizationlimit.PrioritizationLimit = (*PrioritizationLimit)(nil) |
36 changes: 36 additions & 0 deletions
36
submitqueue/extension/speculation/prioritizationlimit/fake/fake_test.go
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,36 @@ | ||
| // Copyright (c) 2025 Uber Technologies, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package fake | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestLimit_ReturnsConfiguredValue(t *testing.T) { | ||
| got, err := New(8).Limit(context.Background()) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, 8, got) | ||
| } | ||
|
|
||
| func TestLimit_FailWith(t *testing.T) { | ||
| sentinel := errors.New("boom") | ||
| _, err := New(8).FailWith(sentinel).Limit(context.Background()) | ||
| require.ErrorIs(t, err, sentinel) | ||
| } |
12 changes: 12 additions & 0 deletions
12
submitqueue/extension/speculation/prioritizationlimit/mock/BUILD.bazel
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,12 @@ | ||
| load("@rules_go//go:def.bzl", "go_library") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = ["prioritizationlimit_mock.go"], | ||
| importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/prioritizationlimit/mock", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//submitqueue/extension/speculation/prioritizationlimit:go_default_library", | ||
| "@org_uber_go_mock//gomock:go_default_library", | ||
| ], | ||
| ) |
96 changes: 96 additions & 0 deletions
96
submitqueue/extension/speculation/prioritizationlimit/mock/prioritizationlimit_mock.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
submitqueue/extension/speculation/prioritizationlimit/prioritizationlimit.go
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,57 @@ | ||
| // Copyright (c) 2025 Uber Technologies, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package prioritizationlimit | ||
|
|
||
| //go:generate mockgen -source=prioritizationlimit.go -destination=mock/prioritizationlimit_mock.go -package=mock | ||
|
|
||
| import "context" | ||
|
|
||
| // PrioritizationLimit is the "how much" policy that bounds how many builds a | ||
| // queue may run at once — the queue's concurrent-build budget. | ||
| // | ||
| // It is the prioritizer's companion: the prioritizer decides *which* of the | ||
| // queue's pending builds run (its ranking across all in-flight batches); the | ||
| // prioritization limit decides *how many* fit at once. It is the queue-wide | ||
| // resource knob, the ultimate cap on speculation's demand on CI. | ||
| // | ||
| // The value is dynamic: it may change between calls, so the prioritizer reads it | ||
| // each round rather than caching it. | ||
| // | ||
| // It is injected into the prioritizer at construction and called by it, never | ||
| // passed as a method parameter, keeping the prioritizer interface limit-free and | ||
| // stable. | ||
| type PrioritizationLimit interface { | ||
| // Limit returns the current maximum number of concurrent builds for the | ||
| // queue. The prioritizer admits at most this many candidates. It takes no | ||
| // parameters; anything an implementation needs is injected at construction. | ||
| Limit(ctx context.Context) (int, error) | ||
| } | ||
|
|
||
| // Config carries the per-queue identity handed to a Factory. The system knows | ||
| // only the queue name; everything a policy needs to compute the limit (a | ||
| // capacity feed, cost budgets, config) is injected at construction by the | ||
| // integrator. | ||
| type Config struct { | ||
| // QueueName identifies the queue this PrioritizationLimit serves. | ||
| QueueName string | ||
| } | ||
|
|
||
| // Factory builds the PrioritizationLimit for a queue. Implementations are | ||
| // provided by integrators (and tests) and inject whatever signals they need at | ||
| // construction. | ||
| type Factory interface { | ||
| // For returns the PrioritizationLimit for the given queue. | ||
| For(cfg Config) (PrioritizationLimit, error) | ||
| } |
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,9 @@ | ||
| load("@rules_go//go:def.bzl", "go_library") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = ["prioritizer.go"], | ||
| importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/prioritizer", | ||
| visibility = ["//visibility:public"], | ||
| deps = ["//submitqueue/entity:go_default_library"], | ||
| ) |
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,21 @@ | ||
| # Speculation Prioritizer | ||
|
|
||
| Vendor-agnostic interface for the queue-wide policy that rations a shared build budget across every in-flight batch in a queue. | ||
|
|
||
| See the [Speculation RFC](/doc/rfc/submitqueue/speculation.md) for the end-to-end design and how prioritization fits into the orchestrator pipeline. | ||
|
|
||
| ## Prioritizer | ||
|
|
||
| Selection is per batch and blind to other batches, so it cannot ration a shared budget: if every batch promoted generously, their combined demand could swamp CI. The prioritizer closes that gap. It sees every path across all of the queue's in-flight batches that is running or wants to run, ranks them by each path's score (plus any fairness or tie-break policy), and admits only the subset that fits the queue's concurrent-build budget. Selection expresses *desire* per batch; prioritization reconciles that desire against *supply* — it is the queue-wide enforcer. | ||
|
|
||
| The controller hands the prioritizer the queue's candidate paths directly — every path that is `Selected` (wants a slot) or `Prioritized`/`Building` (holds a slot), each carrying its identity and score. It returns **sparse decisions**, each naming a path by its ID: `Promote` to admit a pending path, `Cancel` to preempt a running one. Paths it omits are left as-is, and it returns at most one decision per path. It never writes: the controller maps each decision back to its tree (it remembers which tree each candidate came from), maps it to a status transition (`Promote` → `Prioritized`, `Cancel` → `Cancelling`) applied under that tree's optimistic lock, and enacts it, staying the single writer. | ||
|
|
||
| `Prioritized` means **admitted under the queue's build budget and cleared to build, but not yet building** — the path holds a slot and is waiting for the build stage to dispatch it and a build signal to confirm it (at which point it becomes `Building`). It is deliberately not called "admitted": batches are admitted at several points in the queue's lifecycle, while `Prioritized` names exactly the grant this seam makes. Contrast it with `Selected`, which is only the batch-level *desire* for a slot — a selected path has no claim on the budget until the prioritizer promotes it. | ||
|
|
||
| **Whether to preempt is the prioritizer's own policy**, swappable per queue. A sticky-slots implementation never emits `Cancel` for a running path — it only fills free slots, and a higher-priority path waits until a slot frees. A preemptive implementation ranks running and pending paths together and may `Cancel` a running path to admit a higher-scored one. Both read the same input through the same interface; only the ranking/eviction logic differs. (Preemption discards in-flight CI work, so "fill free slots only" is a common default.) | ||
|
|
||
| Prioritization is queue-wide — a different vantage point than the per-batch seams (enumerator, scorer, selector) — but it acts in the same currency: it ranks on the same path `Score` the scorer produces (a probability in [0, 1] under the [path scorer](../pathscorer)'s contract — the prioritizer needs no other assumption about the values, only that all paths in a queue share the scale) and emits the same `PathDecision` the selector does. Where the queue-wide reconcile runs in the pipeline is an integration detail; the contract here is unaffected by it. | ||
|
|
||
| ## Factory | ||
|
|
||
| A per-queue factory returns the prioritizer for a queue, following the repo's extension contract. It is handed only the queue identity; the prioritization limit, fairness policy, and capacity signals are injected at construction by the integrator in the wiring layer, which resolves per-queue settings through `queueconfig`. Prioritization itself stays config-free. | ||
23 changes: 23 additions & 0 deletions
23
submitqueue/extension/speculation/prioritizer/fake/BUILD.bazel
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,23 @@ | ||
| load("@rules_go//go:def.bzl", "go_library", "go_test") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = ["fake.go"], | ||
| importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/prioritizer/fake", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//submitqueue/entity:go_default_library", | ||
| "//submitqueue/extension/speculation/prioritizer:go_default_library", | ||
| ], | ||
| ) | ||
|
|
||
| go_test( | ||
| name = "go_default_test", | ||
| srcs = ["fake_test.go"], | ||
| embed = [":go_default_library"], | ||
| deps = [ | ||
| "//submitqueue/entity:go_default_library", | ||
| "@com_github_stretchr_testify//assert:go_default_library", | ||
| "@com_github_stretchr_testify//require:go_default_library", | ||
| ], | ||
| ) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.