Status report: Handle failures determining disk usage

This commit is contained in:
Henry Mercer 2024-02-02 16:31:04 +00:00
parent 81eb6b2bf4
commit f9dea84e29
6 changed files with 66 additions and 42 deletions

6
lib/status-report.js generated
View file

@ -103,9 +103,7 @@ async function createStatusReportBase(actionName, status, actionStartedAt, diskI
job_name: jobName, job_name: jobName,
job_run_uuid: jobRunUUID, job_run_uuid: jobRunUUID,
ref, ref,
runner_available_disk_space_bytes: diskInfo.numAvailableBytes,
runner_os: runnerOs, runner_os: runnerOs,
runner_total_disk_space_bytes: diskInfo.numTotalBytes,
started_at: workflowStartedAt, started_at: workflowStartedAt,
status, status,
testing_environment: testingEnvironment, testing_environment: testingEnvironment,
@ -113,6 +111,10 @@ async function createStatusReportBase(actionName, status, actionStartedAt, diskI
workflow_run_attempt: workflowRunAttempt, workflow_run_attempt: workflowRunAttempt,
workflow_run_id: workflowRunID, workflow_run_id: workflowRunID,
}; };
if (diskInfo) {
statusReport.runner_available_disk_space_bytes = diskInfo.numAvailableBytes;
statusReport.runner_total_disk_space_bytes = diskInfo.numTotalBytes;
}
// Add optional parameters // Add optional parameters
if (cause) { if (cause) {
statusReport.cause = cause; statusReport.cause = cause;

File diff suppressed because one or more lines are too long

38
lib/util.js generated
View file

@ -789,23 +789,31 @@ function prettyPrintPack(pack) {
} }
exports.prettyPrintPack = prettyPrintPack; exports.prettyPrintPack = prettyPrintPack;
async function checkDiskUsage(logger) { async function checkDiskUsage(logger) {
const diskUsage = await (0, check_disk_space_1.default)(getRequiredEnvParam("GITHUB_WORKSPACE")); try {
const gbInBytes = 1024 * 1024 * 1024; const diskUsage = await (0, check_disk_space_1.default)(getRequiredEnvParam("GITHUB_WORKSPACE"));
if (logger && diskUsage.free < 2 * gbInBytes) { const gbInBytes = 1024 * 1024 * 1024;
const message = "The Actions runner is running low on disk space " + if (logger && diskUsage.free < 2 * gbInBytes) {
`(${(diskUsage.free / gbInBytes).toPrecision(4)} GB available).`; const message = "The Actions runner is running low on disk space " +
if (process.env[environment_1.EnvVar.HAS_WARNED_ABOUT_DISK_SPACE] !== "true") { `(${(diskUsage.free / gbInBytes).toPrecision(4)} GB available).`;
logger.warning(message); if (process.env[environment_1.EnvVar.HAS_WARNED_ABOUT_DISK_SPACE] !== "true") {
logger.warning(message);
}
else {
logger.debug(message);
}
core.exportVariable(environment_1.EnvVar.HAS_WARNED_ABOUT_DISK_SPACE, "true");
} }
else { return {
logger.debug(message); numAvailableBytes: diskUsage.free,
} numTotalBytes: diskUsage.size,
core.exportVariable(environment_1.EnvVar.HAS_WARNED_ABOUT_DISK_SPACE, "true"); };
}
catch (error) {
if (logger) {
logger.warning(`Failed to check available disk space: ${getErrorMessage(error)}`);
}
return undefined;
} }
return {
numAvailableBytes: diskUsage.free,
numTotalBytes: diskUsage.size,
};
} }
exports.checkDiskUsage = checkDiskUsage; exports.checkDiskUsage = checkDiskUsage;
/** /**

File diff suppressed because one or more lines are too long

View file

@ -96,7 +96,7 @@ export interface StatusReportBase {
/** Action runner hardware architecture (context runner.arch). */ /** Action runner hardware architecture (context runner.arch). */
runner_arch?: string; runner_arch?: string;
/** Available disk space on the runner, in bytes. */ /** Available disk space on the runner, in bytes. */
runner_available_disk_space_bytes: number; runner_available_disk_space_bytes?: number;
/** /**
* Version of the runner image, for workflows running on GitHub-hosted runners. Absent otherwise. * Version of the runner image, for workflows running on GitHub-hosted runners. Absent otherwise.
*/ */
@ -106,7 +106,7 @@ export interface StatusReportBase {
/** Action runner operating system release (x.y.z from os.release()). */ /** Action runner operating system release (x.y.z from os.release()). */
runner_os_release?: string; runner_os_release?: string;
/** Total disk space on the runner, in bytes. */ /** Total disk space on the runner, in bytes. */
runner_total_disk_space_bytes: number; runner_total_disk_space_bytes?: number;
/** Time the first action started. Normally the init action. */ /** Time the first action started. Normally the init action. */
started_at: string; started_at: string;
/** State this action is currently in. */ /** State this action is currently in. */
@ -192,7 +192,7 @@ export async function createStatusReportBase(
actionName: ActionName, actionName: ActionName,
status: ActionStatus, status: ActionStatus,
actionStartedAt: Date, actionStartedAt: Date,
diskInfo: DiskUsage, diskInfo: DiskUsage | undefined,
cause?: string, cause?: string,
exception?: string, exception?: string,
): Promise<StatusReportBase> { ): Promise<StatusReportBase> {
@ -230,9 +230,7 @@ export async function createStatusReportBase(
job_name: jobName, job_name: jobName,
job_run_uuid: jobRunUUID, job_run_uuid: jobRunUUID,
ref, ref,
runner_available_disk_space_bytes: diskInfo.numAvailableBytes,
runner_os: runnerOs, runner_os: runnerOs,
runner_total_disk_space_bytes: diskInfo.numTotalBytes,
started_at: workflowStartedAt, started_at: workflowStartedAt,
status, status,
testing_environment: testingEnvironment, testing_environment: testingEnvironment,
@ -241,6 +239,11 @@ export async function createStatusReportBase(
workflow_run_id: workflowRunID, workflow_run_id: workflowRunID,
}; };
if (diskInfo) {
statusReport.runner_available_disk_space_bytes = diskInfo.numAvailableBytes;
statusReport.runner_total_disk_space_bytes = diskInfo.numTotalBytes;
}
// Add optional parameters // Add optional parameters
if (cause) { if (cause) {
statusReport.cause = cause; statusReport.cause = cause;

View file

@ -1011,26 +1011,37 @@ export interface DiskUsage {
numTotalBytes: number; numTotalBytes: number;
} }
export async function checkDiskUsage(logger?: Logger): Promise<DiskUsage> { export async function checkDiskUsage(
const diskUsage = await checkDiskSpace( logger?: Logger,
getRequiredEnvParam("GITHUB_WORKSPACE"), ): Promise<DiskUsage | undefined> {
); try {
const gbInBytes = 1024 * 1024 * 1024; const diskUsage = await checkDiskSpace(
if (logger && diskUsage.free < 2 * gbInBytes) { getRequiredEnvParam("GITHUB_WORKSPACE"),
const message = );
"The Actions runner is running low on disk space " + const gbInBytes = 1024 * 1024 * 1024;
`(${(diskUsage.free / gbInBytes).toPrecision(4)} GB available).`; if (logger && diskUsage.free < 2 * gbInBytes) {
if (process.env[EnvVar.HAS_WARNED_ABOUT_DISK_SPACE] !== "true") { const message =
logger.warning(message); "The Actions runner is running low on disk space " +
} else { `(${(diskUsage.free / gbInBytes).toPrecision(4)} GB available).`;
logger.debug(message); if (process.env[EnvVar.HAS_WARNED_ABOUT_DISK_SPACE] !== "true") {
logger.warning(message);
} else {
logger.debug(message);
}
core.exportVariable(EnvVar.HAS_WARNED_ABOUT_DISK_SPACE, "true");
} }
core.exportVariable(EnvVar.HAS_WARNED_ABOUT_DISK_SPACE, "true"); return {
numAvailableBytes: diskUsage.free,
numTotalBytes: diskUsage.size,
};
} catch (error) {
if (logger) {
logger.warning(
`Failed to check available disk space: ${getErrorMessage(error)}`,
);
}
return undefined;
} }
return {
numAvailableBytes: diskUsage.free,
numTotalBytes: diskUsage.size,
};
} }
/** /**