Skip to content

Commit

Permalink
Add telemetry for uploading failed runs
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Mercer committed Dec 9, 2022
1 parent 8960790 commit e67ad6a
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 26 deletions.
2 changes: 1 addition & 1 deletion lib/actions-util.js.map

Large diffs are not rendered by default.

23 changes: 19 additions & 4 deletions lib/init-action-post-helper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action-post-helper.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions lib/init-action-post.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action-post.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/actions-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,12 @@ function getRefFromEnv(): string {
return refEnv;
}

type ActionName = "init" | "autobuild" | "finish" | "upload-sarif";
type ActionName =
| "init"
| "autobuild"
| "finish"
| "upload-sarif"
| "init-post";
type ActionStatus =
| "starting"
| "aborted"
Expand Down
44 changes: 39 additions & 5 deletions src/init-action-post-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,29 @@ import {
getWorkflow,
} from "./workflow";

export interface UploadFailedSarifResult {
/** Size in bytes of the unzipped SARIF payload uploaded for the failed run. */
upload_failed_run_raw_upload_size_bytes?: number;
/** Size in bytes of actual SARIF payload uploaded for the failed run. */
upload_failed_run_zipped_upload_size_bytes?: number;

/** Error encountered during uploading the failed run. */
upload_failed_run_error?: string;
/** Reason why we did not upload a SARIF payload with `executionSuccessful: false`. */
upload_failed_run_skipped_because?: string;
}

export async function uploadFailedSarif(
config: Config,
repositoryNwo: RepositoryNwo,
featureEnablement: FeatureEnablement,
logger: Logger
) {
): Promise<UploadFailedSarifResult> {
if (!config.codeQLCmd) {
logger.warning(
"CodeQL command not found. Unable to upload failed SARIF file."
);
return;
return { upload_failed_run_skipped_because: "CodeQL command not found" };
}
const codeql = await getCodeQL(config.codeQLCmd);
if (
Expand All @@ -36,7 +48,7 @@ export async function uploadFailedSarif(
))
) {
logger.debug("Uploading failed SARIF is disabled.");
return;
return { upload_failed_run_skipped_because: "Feature disabled" };
}
const workflow = await getWorkflow();
const jobName = getRequiredEnvParam("GITHUB_JOB");
Expand All @@ -48,7 +60,7 @@ export async function uploadFailedSarif(
logger.debug(
"Won't upload a failed SARIF file since SARIF upload is disabled."
);
return;
return { upload_failed_run_skipped_because: "SARIF upload is disabled" };
}
const category = getCategoryInputOrThrow(workflow, jobName, matrix);
const checkoutPath = getCheckoutPathInputOrThrow(workflow, jobName, matrix);
Expand All @@ -69,6 +81,12 @@ export async function uploadFailedSarif(
logger,
{ isUnsuccessfulExecution: true }
);
return {
upload_failed_run_raw_upload_size_bytes:
uploadResult?.statusReport?.raw_upload_size_bytes,
upload_failed_run_zipped_upload_size_bytes:
uploadResult?.statusReport?.zipped_upload_size_bytes,
};
}

export async function run(
Expand All @@ -91,9 +109,16 @@ export async function run(
const expectFailedSarifUpload =
process.env["CODEQL_ACTION_EXPECT_UPLOAD_FAILED_SARIF"] === "true";

let uploadFailedSarifResult: UploadFailedSarifResult;

if (process.env[CODEQL_ACTION_ANALYZE_DID_UPLOAD_SARIF] !== "true") {
try {
await uploadFailedSarif(config, repositoryNwo, featureEnablement, logger);
uploadFailedSarifResult = await uploadFailedSarif(
config,
repositoryNwo,
featureEnablement,
logger
);
} catch (e) {
if (expectFailedSarifUpload) {
throw new Error(
Expand All @@ -104,11 +129,18 @@ export async function run(
logger.info(
`Failed to upload a SARIF file for the failed run. Error: ${e}`
);
uploadFailedSarifResult = {
upload_failed_run_error: e instanceof Error ? e.message : String(e),
};
}
} else if (expectFailedSarifUpload) {
throw new Error(
"Expected to upload a SARIF file for the failed run, but didn't."
);
} else {
uploadFailedSarifResult = {
upload_failed_run_skipped_because: "SARIF file already uploaded",
};
}

// Upload appropriate Actions artifacts for debugging
Expand All @@ -121,4 +153,6 @@ export async function run(

await printDebugLogs(config);
}

return uploadFailedSarifResult;
}
Loading

0 comments on commit e67ad6a

Please sign in to comment.