Skip to content

Commit ed231f8

Browse files
committed
Validate ping mode flag, change ping-only to poll-only
1 parent 9b1fcd7 commit ed231f8

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

agent/agent_worker.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ import (
2020
"github.com/buildkite/roko"
2121
)
2222

23+
const (
24+
PingModeAuto = "auto" // empty string can be used from tests
25+
PingModeStreamOnly = "stream-only"
26+
PingModePollOnly = "poll-only"
27+
)
28+
2329
type AgentWorkerConfig struct {
2430
// Whether to set debug in the job
2531
Debug bool
@@ -323,18 +329,21 @@ func (a *AgentWorker) Start(ctx context.Context, idleMon *idleMonitor) (startErr
323329

324330
var loops []func()
325331
switch a.agentConfiguration.PingMode {
326-
case "", "auto":
332+
case "", PingModeAuto: // note: "" can happen in some tests
327333
loops = []func(){pingLoop, streamingLoop, debouncerLoop}
328334
bat.Acquire(actorDebouncer)
329335

330-
case "ping-only":
336+
case PingModePollOnly:
331337
loops = []func(){pingLoop}
332338
fromDebouncerCh = nil // prevent action loop listening to streaming side
333339

334-
case "stream-only":
340+
case PingModeStreamOnly:
335341
loops = []func(){streamingLoop, debouncerLoop}
336342
fromPingLoopCh = nil // prevent action loop listening to ping side
337343
bat.Acquire(actorDebouncer)
344+
345+
default:
346+
return fmt.Errorf("unknown ping mode %q", a.agentConfiguration.PingMode)
338347
}
339348

340349
// There's always an action handler.

clicommand/agent_start.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,18 @@ Example:
6060
6161
$ buildkite-agent start --token xxx`
6262

63+
const pingModePingOnly = "ping-only"
64+
6365
var (
6466
verificationFailureBehaviors = []string{agent.VerificationBehaviourBlock, agent.VerificationBehaviourWarn}
6567

68+
pingModes = []string{
69+
agent.PingModeAuto,
70+
agent.PingModePollOnly,
71+
pingModePingOnly, // canonicalises to agent.PingModePollOnly
72+
agent.PingModeStreamOnly,
73+
}
74+
6675
buildkiteSetEnvironmentVariables = []*regexp.Regexp{
6776
regexp.MustCompile("^BUILDKITE$"),
6877
regexp.MustCompile("^BUILDKITE_.*$"),
@@ -764,8 +773,8 @@ var AgentStartCommand = cli.Command{
764773
// API + agent behaviour
765774
cli.StringFlag{
766775
Name: "ping-mode",
767-
Usage: "Selects available protocols for dispatching work to this agent. One of ping-only (default), auto (prefer streaming, but fall back to polling when necessary) or stream-only.",
768-
Value: "ping-only",
776+
Usage: "Selects available protocols for dispatching work to this agent. One of auto (default, prefer streaming, but fall back to polling when necessary), poll-only, or stream-only.",
777+
Value: "auto",
769778
EnvVar: "BUILDKITE_AGENT_PING_MODE",
770779
},
771780

@@ -852,6 +861,15 @@ var AgentStartCommand = cli.Command{
852861
return fmt.Errorf("failed to unset config from environment: %w", err)
853862
}
854863

864+
if !slices.Contains(pingModes, cfg.PingMode) {
865+
return fmt.Errorf("invalid ping mode %q, must be one of %v", cfg.PingMode, pingModes)
866+
}
867+
// Calling it "ping-only" was a mistake, so canonicalise it to "poll-only"
868+
// on the very remote chance someone is using that.
869+
if cfg.PingMode == pingModePingOnly {
870+
cfg.PingMode = agent.PingModePollOnly
871+
}
872+
855873
if cfg.VerificationJWKSFile != "" {
856874
if !slices.Contains(verificationFailureBehaviors, cfg.VerificationFailureBehavior) {
857875
return fmt.Errorf(

internal/e2e/basic_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ func TestBasicE2E(t *testing.T) {
3131
}
3232
}
3333

34-
func TestBasicE2E_PingOnly(t *testing.T) {
34+
func TestBasicE2E_PollOnly(t *testing.T) {
3535
ctx := t.Context()
3636
tc := newTestCase(t, "basic_e2e.yaml")
3737

38-
tc.startAgent("--ping-mode=ping-only")
38+
tc.startAgent("--ping-mode=poll-only")
3939
build := tc.triggerBuild()
4040

4141
// It should take much less time than 1 minute to successfully run the job.

0 commit comments

Comments
 (0)