Skip to content

Commit 98a7764

Browse files
authored
Merge pull request #1030 from buildkite/tracing-backends
Make tracing easier to configure
2 parents 90138a9 + f96fad6 commit 98a7764

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

packer/linux/conf/bin/bk-install-elastic-stack.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,13 @@ spawn=${BUILDKITE_AGENTS_PER_INSTANCE}
182182
no-color=true
183183
disconnect-after-idle-timeout=${BUILDKITE_SCALE_IN_IDLE_PERIOD}
184184
disconnect-after-job=${BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB}
185+
tracing-backend=${BUILDKITE_AGENT_TRACING_BACKEND}
185186
EOF
186187

188+
if [[ "${BUILDKITE_ENV_FILE_URL}" != "" ]]; then
189+
/usr/local/bin/bk-fetch.sh "${BUILDKITE_ENV_FILE_URL}" /var/lib/buildkite-agent/env
190+
fi
191+
187192
chown buildkite-agent: /etc/buildkite-agent/buildkite-agent.cfg
188193

189194
if [[ -n "${BUILDKITE_AUTHORIZED_USERS_URL}" ]] ; then

packer/linux/conf/buildkite-agent/systemd/buildkite-agent.service

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ User=buildkite-agent
1111
Environment="HOME=/var/lib/buildkite-agent"
1212
Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
1313
Environment="USER=buildkite-agent"
14+
# The =- (rather than just = ) in the line below means that systemd won't complain if it can't find the file
15+
EnvironmentFile=-/var/lib/buildkite-agent/env
1416
ExecStart=/usr/bin/buildkite-agent start
1517
ExecStopPost=/usr/local/bin/terminate-instance
1618
RestartSec=5

packer/windows/conf/bin/bk-install-elastic-stack.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ no-color=true
138138
shell=powershell
139139
disconnect-after-idle-timeout=${Env:BUILDKITE_SCALE_IN_IDLE_PERIOD}
140140
disconnect-after-job=${Env:BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB}
141+
tracing-backend=${Env:BUILDKITE_AGENT_TRACING_BACKEND}
141142
"@
142143
$OFS=" "
143144

@@ -199,6 +200,10 @@ If (![string]::IsNullOrEmpty($Env:BUILDKITE_ELASTIC_BOOTSTRAP_SCRIPT)) {
199200
Remove-Item -Path C:\buildkite-agent\elastic_bootstrap.ps1
200201
}
201202

203+
If (![string]::IsNullOrEmpty($Env:BUILDKITE_ENV_FILE_URL)) {
204+
C:\buildkite-agent\bin\bk-fetch.ps1 -From "$Env:BUILDKITE_ENV_FILE_URL" -To C:\buildkite-agent\env
205+
}
206+
202207
Write-Output "Starting the Buildkite Agent"
203208

204209
nssm install buildkite-agent C:\buildkite-agent\bin\buildkite-agent.exe start
@@ -210,6 +215,14 @@ If ($lastexitcode -ne 0) { Exit $lastexitcode }
210215
nssm set buildkite-agent AppStderr C:\buildkite-agent\buildkite-agent.log
211216
If ($lastexitcode -ne 0) { Exit $lastexitcode }
212217
nssm set buildkite-agent AppEnvironmentExtra :HOME=C:\buildkite-agent
218+
219+
If ((![string]::IsNullOrEmpty($Env:BUILDKITE_ENV_FILE_URL)) -And (Test-Path -Path C:\buildkite-agent\env -PathType leaf)) {
220+
foreach ($var in Get-Content C:\buildkite-agent\env) {
221+
nssm set buildkite-agent AppEnvironmentExtra $var
222+
If ($lastexitcode -ne 0) { Exit $lastexitcode }
223+
}
224+
}
225+
213226
If ($lastexitcode -ne 0) { Exit $lastexitcode }
214227
nssm set buildkite-agent AppExit Default Restart
215228
If ($lastexitcode -ne 0) { Exit $lastexitcode }

templates/aws-stack.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Metadata:
4141
- BuildkiteAgentTags
4242
- BuildkiteAgentTimestampLines
4343
- BuildkiteAgentExperiments
44+
- BuildkiteAgentTracingBackend
4445
- BuildkiteTerminateInstanceAfterJob
4546
- BuildkiteAdditionalSudoPermissions
4647
- BuildkiteWindowsAdministrator
@@ -69,6 +70,7 @@ Metadata:
6970
- ArtifactsBucket
7071
- AuthorizedUsersUrl
7172
- BootstrapScriptUrl
73+
- AgentEnvFileUrl
7274
- RootVolumeSize
7375
- RootVolumeName
7476
- RootVolumeType
@@ -163,6 +165,15 @@ Parameters:
163165
Type: String
164166
Default: ""
165167

168+
BuildkiteAgentTracingBackend:
169+
Description: The tracing backend to use for CI tracing. See https://buildkite.com/docs/agent/v3/tracing
170+
Type: String
171+
AllowedValues:
172+
- ""
173+
- "datadog"
174+
- "opentelemetry"
175+
Default: ""
176+
166177
BuildkiteTerminateInstanceAfterJob:
167178
Description: Set to "true" to terminate the instance after a job has completed.
168179
Type: String
@@ -212,7 +223,12 @@ Parameters:
212223
Default: ""
213224

214225
BootstrapScriptUrl:
215-
Description: Optional - HTTPS or S3 URL to run on each instance during boot
226+
Description: Optional - HTTPS or S3 URL for a script to run on each instance during boot
227+
Type: String
228+
Default: ""
229+
230+
AgentEnvFileUrl:
231+
Description: Optional - HTTPS or S3 URL for a list of environment variables to propagate into the agent's execution environment. Note that these environment variables **will not** be passed into builds running on the agent, only to the agent process itself.
216232
Type: String
217233
Default: ""
218234

@@ -443,7 +459,7 @@ Parameters:
443459
- "true"
444460
- "false"
445461
Default: "false"
446-
462+
447463
EnableDetailedMonitoring:
448464
Type: String
449465
Description: Enable detailed EC2 monitoring
@@ -993,10 +1009,12 @@ Resources:
9931009
$Env:BUILDKITE_AGENT_TAGS="${BuildkiteAgentTags}"
9941010
$Env:BUILDKITE_AGENT_TIMESTAMP_LINES="${BuildkiteAgentTimestampLines}"
9951011
$Env:BUILDKITE_AGENT_EXPERIMENTS="${BuildkiteAgentExperiments}"
1012+
$Env:BUILDKITE_AGENT_TRACING_BACKEND="${BuildkiteAgentTracingBackend}"
9961013
$Env:BUILDKITE_AGENT_RELEASE="${BuildkiteAgentRelease}"
9971014
$Env:BUILDKITE_QUEUE="${BuildkiteQueue}"
9981015
$Env:BUILDKITE_AGENT_ENABLE_GIT_MIRRORS_EXPERIMENT="${EnableAgentGitMirrorsExperiment}"
9991016
$Env:BUILDKITE_ELASTIC_BOOTSTRAP_SCRIPT="${BootstrapScriptUrl}"
1017+
$Env:BUILDKITE_ENV_FILE_URL="${AgentEnvFileUrl}"
10001018
$Env:BUILDKITE_AUTHORIZED_USERS_URL="${AuthorizedUsersUrl}"
10011019
$Env:BUILDKITE_ECR_POLICY="${ECRAccessPolicy}"
10021020
$Env:BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB="${BuildkiteTerminateInstanceAfterJob}"
@@ -1041,10 +1059,12 @@ Resources:
10411059
BUILDKITE_AGENT_TAGS="${BuildkiteAgentTags}" \
10421060
BUILDKITE_AGENT_TIMESTAMP_LINES="${BuildkiteAgentTimestampLines}" \
10431061
BUILDKITE_AGENT_EXPERIMENTS="${BuildkiteAgentExperiments}" \
1062+
BUILDKITE_AGENT_TRACING_BACKEND="${BuildkiteAgentTracingBackend}" \
10441063
BUILDKITE_AGENT_RELEASE="${BuildkiteAgentRelease}" \
10451064
BUILDKITE_QUEUE="${BuildkiteQueue}" \
10461065
BUILDKITE_AGENT_ENABLE_GIT_MIRRORS_EXPERIMENT="${EnableAgentGitMirrorsExperiment}" \
10471066
BUILDKITE_ELASTIC_BOOTSTRAP_SCRIPT="${BootstrapScriptUrl}" \
1067+
BUILDKITE_ENV_FILE_URL=${AgentEnvFileUrl} \
10481068
BUILDKITE_ENABLE_INSTANCE_STORAGE="${EnableInstanceStorage}" \
10491069
BUILDKITE_AUTHORIZED_USERS_URL="${AuthorizedUsersUrl}" \
10501070
BUILDKITE_ECR_POLICY="${ECRAccessPolicy}" \

0 commit comments

Comments
 (0)