Skip to content

Commit

Permalink
Merge pull request #2910 from buildkite/pass-cancel-grace-period-to-b…
Browse files Browse the repository at this point in the history
…ootstrap

Pass cancel grace period to bootstrap
  • Loading branch information
DrJosh9000 authored Jul 31, 2024
2 parents 2be45da + 28007ed commit ab0a68e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion agent/agent_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"math/rand/v2"
"net/http"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -590,7 +591,7 @@ func (a *AgentWorker) AcquireAndRunJob(ctx context.Context, jobId string) error
aj, resp, err := a.apiClient.AcquireJob(
timeoutCtx, jobId,
api.Header{Name: "X-Buildkite-Lock-Acquire-Job", Value: "1"},
api.Header{Name: "X-Buildkite-Backoff-Sequence", Value: fmt.Sprintf("%d", r.AttemptCount())},
api.Header{Name: "X-Buildkite-Backoff-Sequence", Value: strconv.Itoa(r.AttemptCount())},
)
if err != nil {
if resp != nil {
Expand Down
7 changes: 4 additions & 3 deletions agent/job_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func (r *JobRunner) createEnvironment(ctx context.Context) ([]string, error) {
// Add agent environment variables
env["BUILDKITE_AGENT_DEBUG"] = fmt.Sprintf("%t", r.conf.Debug)
env["BUILDKITE_AGENT_DEBUG_HTTP"] = fmt.Sprintf("%t", r.conf.DebugHTTP)
env["BUILDKITE_AGENT_PID"] = fmt.Sprintf("%d", os.Getpid())
env["BUILDKITE_AGENT_PID"] = strconv.Itoa(os.Getpid())

// We know the BUILDKITE_BIN_PATH dir, because it's the path to the
// currently running file (there is only 1 binary)
Expand Down Expand Up @@ -487,12 +487,13 @@ func (r *JobRunner) createEnvironment(ctx context.Context) ([]string, error) {
env["BUILDKITE_GIT_FETCH_FLAGS"] = r.conf.AgentConfiguration.GitFetchFlags
env["BUILDKITE_GIT_CLONE_MIRROR_FLAGS"] = r.conf.AgentConfiguration.GitCloneMirrorFlags
env["BUILDKITE_GIT_CLEAN_FLAGS"] = r.conf.AgentConfiguration.GitCleanFlags
env["BUILDKITE_GIT_MIRRORS_LOCK_TIMEOUT"] = fmt.Sprintf("%d", r.conf.AgentConfiguration.GitMirrorsLockTimeout)
env["BUILDKITE_GIT_MIRRORS_LOCK_TIMEOUT"] = strconv.Itoa(r.conf.AgentConfiguration.GitMirrorsLockTimeout)
env["BUILDKITE_SHELL"] = r.conf.AgentConfiguration.Shell
env["BUILDKITE_AGENT_EXPERIMENT"] = strings.Join(experiments.Enabled(ctx), ",")
env["BUILDKITE_REDACTED_VARS"] = strings.Join(r.conf.AgentConfiguration.RedactedVars, ",")
env["BUILDKITE_STRICT_SINGLE_HOOKS"] = fmt.Sprintf("%t", r.conf.AgentConfiguration.StrictSingleHooks)
env["BUILDKITE_SIGNAL_GRACE_PERIOD_SECONDS"] = fmt.Sprintf("%d", int(r.conf.AgentConfiguration.SignalGracePeriod/time.Second))
env["BUILDKITE_CANCEL_GRACE_PERIOD"] = strconv.Itoa(r.conf.AgentConfiguration.CancelGracePeriod)
env["BUILDKITE_SIGNAL_GRACE_PERIOD_SECONDS"] = strconv.Itoa(int(r.conf.AgentConfiguration.SignalGracePeriod / time.Second))

if r.conf.KubernetesExec {
env["BUILDKITE_KUBERNETES_EXEC"] = "true"
Expand Down
5 changes: 3 additions & 2 deletions agent/pipeline_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"net/url"
"regexp"
"strconv"
"time"

"github.com/buildkite/agent/v3/api"
Expand Down Expand Up @@ -125,7 +126,7 @@ func (u *PipelineUploader) pipelineUploadAsyncWithRetry(
u.Change,
api.Header{
Name: "X-Buildkite-Backoff-Sequence",
Value: fmt.Sprintf("%d", r.AttemptCount()),
Value: strconv.Itoa(r.AttemptCount()),
},
)
if err != nil {
Expand Down Expand Up @@ -185,7 +186,7 @@ func (u *PipelineUploader) pollForPiplineUploadStatus(ctx context.Context, l log
u.Change.UUID,
api.Header{
Name: "X-Buildkite-Backoff-Sequence",
Value: fmt.Sprintf("%d", r.AttemptCount()),
Value: strconv.Itoa(r.AttemptCount()),
},
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion clicommand/agent_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ var AgentStartCommand = cli.Command{
return fmt.Errorf("invalid log format %q. Only 'text' or 'json' are allowed.", cfg.LogFormat)
}

l.Notice("Starting buildkite-agent v%s with PID: %s", version.Version(), fmt.Sprintf("%d", os.Getpid()))
l.Notice("Starting buildkite-agent v%s with PID: %s", version.Version(), strconv.Itoa(os.Getpid()))
l.Notice("The agent source code can be found here: https://github.com/buildkite/agent")
l.Notice("For questions and support, email us at: [email protected]")

Expand Down
4 changes: 2 additions & 2 deletions internal/job/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ func (e *Executor) runWrappedShellScriptHook(ctx context.Context, hookName strin
return err
}); err != nil {
exitCode := shell.GetExitCode(err)
e.shell.Env.Set("BUILDKITE_LAST_HOOK_EXIT_STATUS", fmt.Sprintf("%d", exitCode))
e.shell.Env.Set("BUILDKITE_LAST_HOOK_EXIT_STATUS", strconv.Itoa(exitCode))

// If the hook exited with a non-zero exit code, then we should pass that back to the executor
// so it may inform the Buildkite API
Expand Down Expand Up @@ -910,7 +910,7 @@ func (e *Executor) CommandPhase(ctx context.Context) (hookErr error, commandErr
// error this will be zero. It's used to set the exit code later, so it's important
e.shell.Env.Set(
"BUILDKITE_COMMAND_EXIT_STATUS",
fmt.Sprintf("%d", shell.GetExitCode(commandErr)),
strconv.Itoa(shell.GetExitCode(commandErr)),
)

// Exit early if there was no error
Expand Down
4 changes: 2 additions & 2 deletions process/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package process

import (
"fmt"
"strconv"
"syscall"

"golang.org/x/sys/unix"
Expand Down Expand Up @@ -62,7 +62,7 @@ func GetPgid(pid int) (int, error) {
func SignalString(s syscall.Signal) string {
name := unix.SignalName(s)
if name == "" {
return fmt.Sprintf("%d", int(s))
return strconv.Itoa(int(s))
}
return name
}

0 comments on commit ab0a68e

Please sign in to comment.