Skip to content

Commit 5fe3b77

Browse files
authored
improve observability and readiness timeout for buildkitd startup (#112)
1 parent ab5c1da commit 5fe3b77

4 files changed

Lines changed: 43 additions & 27 deletions

File tree

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
getNumCPUs,
2525
pruneBuildkitCache,
2626
logBuildCacheContents,
27+
logBuildkitdLogTail,
2728
logDatabaseHashes,
2829
writeDockerContainerBuildkitdTomlFile,
2930
} from "./setup_builder";
@@ -494,16 +495,20 @@ async function startBlacksmithBuilder(
494495

495496
// Start buildkitd
496497
const buildkitdStartTime = Date.now();
497-
const buildkitdAddr = await startAndConfigureBuildkitd(
498-
parallelism,
499-
buildkitdPath,
500-
inputs["driver-opts"],
501-
);
502-
const buildkitdDurationMs = Date.now() - buildkitdStartTime;
503-
await reporter.reportMetric(
504-
Metric_MetricType.BPA_BUILDKITD_READY_DURATION_MS,
505-
buildkitdDurationMs,
506-
);
498+
let buildkitdAddr: string;
499+
try {
500+
buildkitdAddr = await startAndConfigureBuildkitd(
501+
parallelism,
502+
buildkitdPath,
503+
inputs["driver-opts"],
504+
);
505+
} finally {
506+
const buildkitdDurationMs = Date.now() - buildkitdStartTime;
507+
await reporter.reportMetric(
508+
Metric_MetricType.BPA_BUILDKITD_READY_DURATION_MS,
509+
buildkitdDurationMs,
510+
);
511+
}
507512

508513
// Save state for post action
509514
stateHelper.setExposeId(stickyDiskSetup.exposeId);
@@ -555,7 +560,7 @@ async function maybeShutdownBuildkitd(): Promise<void> {
555560
core.warning(
556561
"buildkitd process has crashed - expected to be running but not found",
557562
);
558-
await logBuildkitdCrashLogs();
563+
await logBuildkitdLogTail();
559564
return;
560565
}
561566

@@ -600,18 +605,6 @@ async function maybeShutdownBuildkitd(): Promise<void> {
600605
}
601606
}
602607

603-
async function logBuildkitdCrashLogs(): Promise<void> {
604-
try {
605-
const { stdout } = await execAsync(
606-
"tail -n 100 /tmp/buildkitd.log 2>/dev/null || echo 'No buildkitd.log found'",
607-
);
608-
core.info("Last 100 lines of buildkitd.log:");
609-
core.info(stdout);
610-
} catch (error) {
611-
core.warning(`Could not read buildkitd logs: ${(error as Error).message}`);
612-
}
613-
}
614-
615608
void actionsToolkit.run(
616609
// main action
617610
async () => {

src/setup_builder.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,25 @@ export async function getStickyDisk(options?: {
408408

409409
// buildkitdTimeoutMs states the max amount of time this action will wait for the buildkitd
410410
// daemon to start have its socket ready. It also additionally governs how long we will wait for
411-
// the buildkitd workers to be ready.
412-
const buildkitdTimeoutMs = 30000;
411+
// the buildkitd workers to be ready. Worker init can be slow when loading a large cache from
412+
// the sticky disk; falling back to a cold local builder costs far more than waiting here.
413+
const buildkitdTimeoutMs = 120000;
414+
415+
/**
416+
* Logs the tail of the buildkitd daemon log so failures during startup are
417+
* visible in the job logs (and shipped to the observability pipeline).
418+
*/
419+
export async function logBuildkitdLogTail(): Promise<void> {
420+
try {
421+
const { stdout } = await execAsync(
422+
"tail -n 100 /tmp/buildkitd.log 2>/dev/null || echo 'No buildkitd.log found'",
423+
);
424+
core.info("Last 100 lines of buildkitd.log:");
425+
core.info(stdout);
426+
} catch (error) {
427+
core.warning(`Could not read buildkitd logs: ${(error as Error).message}`);
428+
}
429+
}
413430

414431
export async function startAndConfigureBuildkitd(
415432
parallelism: number,
@@ -470,6 +487,12 @@ export async function startAndConfigureBuildkitd(
470487
core.warning(
471488
`Error checking buildkit workers: ${(error as Error).message}`,
472489
);
490+
await logBuildkitdLogTail();
491+
await reporter.reportBuildPushActionFailure(
492+
"BUILDER_STARTUP",
493+
error as Error,
494+
"buildkitd worker readiness",
495+
);
473496
throw error;
474497
}
475498

0 commit comments

Comments
 (0)