Skip to content

Commit d28fd70

Browse files
moskybDrJosh9000
authored andcommitted
Promote descending-spawn-priority experiment
1 parent 8814083 commit d28fd70

3 files changed

Lines changed: 26 additions & 18 deletions

File tree

EXPERIMENTS.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ We previously made this the default behaviour of the agent (as of v3.63.0) but h
4747

4848
**Status:** Available as an experiment to allow users who have since depended on this behaviour to re-enable it. If you use this feature please let us know so we may better understand your use case.
4949

50-
### `descending-spawn-priority`
51-
52-
When using `--spawn` with `--spawn-with-priority`, the agent assigns ascending priorities to each spawned agent (1, 2, 3, ...). This experiment changes the priorities to be descending (-1, -2, -3, ...) instead. This helps jobs be assigned across all hosts in cases where the value of `--spawn` varies between hosts.
53-
5450
### `zip-plugins`
5551

5652
Allows plugins to be downloaded as zip archives instead of being cloned from a Git repository. This is useful for plugins hosted as zip files on HTTP(S) URLs.

clicommand/agent_start.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ type AgentStartConfig struct {
9898
Priority string `cli:"priority"`
9999
Spawn int `cli:"spawn"`
100100
SpawnPerCPU int `cli:"spawn-per-cpu"`
101-
SpawnWithPriority bool `cli:"spawn-with-priority"`
101+
SpawnWithPriority string `cli:"spawn-with-priority"`
102102
RedactedVars []string `cli:"redacted-vars" normalize:"list"`
103103
CancelSignal string `cli:"cancel-signal"`
104104

@@ -666,9 +666,10 @@ var AgentStartCommand = cli.Command{
666666
Value: 0,
667667
EnvVar: "BUILDKITE_AGENT_SPAWN_PER_CPU",
668668
},
669-
cli.BoolFlag{
669+
cli.StringFlag{
670670
Name: "spawn-with-priority",
671-
Usage: "Assign priorities to every spawned agent (when using --spawn or --spawn-per-cpu) equal to the agent's index (default: false)",
671+
Usage: `Assign priorities to every spawned agent (when using --spawn or --spawn-per-cpu). Pass "static" (1, 1, 1, ...), "ascending" (1, 2, 3, ...), or "descending" (-1, -2, -3, ...). Descending helps jobs be assigned across all hosts when the value of --spawn varies between hosts`,
672+
Value: "static",
672673
EnvVar: "BUILDKITE_AGENT_SPAWN_WITH_PRIORITY",
673674
},
674675
cancelSignalFlag,
@@ -842,6 +843,11 @@ var AgentStartCommand = cli.Command{
842843
cfg.PingMode = agent.PingModePollOnly
843844
}
844845

846+
validSpawnWithPriorities := []string{"static", "ascending", "descending"}
847+
if !slices.Contains(validSpawnWithPriorities, cfg.SpawnWithPriority) {
848+
return fmt.Errorf("invalid spawn-with-priority, must be one of %v", validSpawnWithPriorities)
849+
}
850+
845851
if cfg.VerificationJWKSFile != "" {
846852
if !slices.Contains(verificationFailureBehaviors, cfg.VerificationFailureBehavior) {
847853
return fmt.Errorf(
@@ -1288,17 +1294,23 @@ var AgentStartCommand = cli.Command{
12881294
// Handle per-spawn name interpolation, replacing %spawn with the spawn index
12891295
registerReq.Name = strings.ReplaceAll(cfg.Name, "%spawn", strconv.Itoa(i))
12901296

1291-
if cfg.SpawnWithPriority {
1292-
p := i
1293-
if experiments.IsEnabled(ctx, experiments.DescendingSpawnPriority) {
1294-
// This experiment helps jobs be assigned across all hosts
1295-
// in cases where the value of --spawn varies between hosts.
1296-
p = -i
1297-
}
1298-
l.Info("Assigning priority %d for agent %d", p, i)
1299-
registerReq.Priority = strconv.Itoa(p)
1297+
var priority string
1298+
switch cfg.SpawnWithPriority {
1299+
case "static":
1300+
priority = cfg.Priority
1301+
1302+
case "ascending":
1303+
priority = strconv.Itoa(i)
1304+
1305+
case "descending":
1306+
priority = strconv.Itoa(-i)
1307+
1308+
default:
1309+
return fmt.Errorf("unknown spawn-with-priority value %s", cfg.SpawnWithPriority)
13001310
}
13011311

1312+
registerReq.Priority = priority
1313+
13021314
// Register the agent with the buildkite API
13031315
reg, err := client.Register(ctx, registerReq)
13041316
if err != nil {

internal/experiments/experiments.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ const (
2424
const (
2525
// Available experiments
2626
AgentAPI = "agent-api"
27-
DescendingSpawnPriority = "descending-spawn-priority"
2827
InterpolationPrefersRuntimeEnv = "interpolation-prefers-runtime-env"
2928
PTYRaw = "pty-raw"
3029
ZipPlugins = "zip-plugins"
3130

3231
// Promoted or removed experiments - un-export these to ensure no new code
3332
// can depend on them.
33+
descendingSpawnPriority = "descending-spawn-priority"
3434
allowArtifactPathTraversal = "allow-artifact-path-traversal"
3535
ansiTimestamps = "ansi-timestamps"
3636
avoidRecursiveTrap = "avoid-recursive-trap"
@@ -51,13 +51,13 @@ const (
5151
var (
5252
Available = map[string]struct{}{
5353
AgentAPI: {},
54-
DescendingSpawnPriority: {},
5554
InterpolationPrefersRuntimeEnv: {},
5655
PTYRaw: {},
5756
ZipPlugins: {},
5857
}
5958

6059
Promoted = map[string]string{
60+
descendingSpawnPriority: "The `descending-spawn-priority` has been replaced with `--spawn-with-priority descending` as of agent v4",
6161
ansiTimestamps: standardPromotionMsg(ansiTimestamps, "v3.48.0"),
6262
allowArtifactPathTraversal: "The allow-artifact-path-traversal escape-hatch experiment has been removed as of agent v4, because the path traversal behaviour was insecure",
6363
avoidRecursiveTrap: standardPromotionMsg(avoidRecursiveTrap, "v3.66.0"),

0 commit comments

Comments
 (0)