Skip to content

Commit

Permalink
Add telemetry for compression method
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Mercer committed Aug 29, 2024
1 parent e257226 commit cf64c3e
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 32 deletions.
1 change: 1 addition & 0 deletions lib/codeql.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/codeql.js.map

Large diffs are not rendered by default.

26 changes: 15 additions & 11 deletions lib/setup-codeql.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/setup-codeql.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/setup-codeql.test.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/setup-codeql.test.js.map

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

7 changes: 7 additions & 0 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ export async function setupCodeQL(
defaultCliVersion,
logger,
);

logger.debug(
`Bundle download status report: ${JSON.stringify(
toolsDownloadStatusReport,
)}`,
);

let codeqlCmd = path.join(codeqlFolder, "codeql", "codeql");
if (process.platform === "win32") {
codeqlCmd += ".exe";
Expand Down
2 changes: 2 additions & 0 deletions src/setup-codeql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ test("setupCodeQLBundle logs the CodeQL CLI version being used when asked to use
sinon.stub(setupCodeql, "downloadCodeQL").resolves({
codeqlFolder: "codeql",
statusReport: {
compressionMethod: "gzip",
downloadDurationMs: 200,
extractionDurationMs: 300,
},
Expand Down Expand Up @@ -200,6 +201,7 @@ test("setupCodeQLBundle logs the CodeQL CLI version being used when asked to dow
sinon.stub(setupCodeql, "downloadCodeQL").resolves({
codeqlFolder: "codeql",
statusReport: {
compressionMethod: "gzip",
downloadDurationMs: 200,
extractionDurationMs: 300,
},
Expand Down
54 changes: 36 additions & 18 deletions src/setup-codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,10 @@ export async function tryGetFallbackToolcacheVersion(
return fallbackVersion;
}

type CompressionMethod = "gzip" | "zstd";

export interface ToolsDownloadStatusReport {
compressionMethod: CompressionMethod;
downloadDurationMs: number;
extractionDurationMs: number;
}
Expand Down Expand Up @@ -526,7 +529,9 @@ export const downloadCodeQL = async function (

logger.debug("Extracting CodeQL bundle.");
const extractionStart = performance.now();
const extractedBundlePath = await extractBundle(archivedBundlePath);
const { extractedBundlePath, compressionMethod } = await extractBundle(
archivedBundlePath,
);
const extractionDurationMs = Math.round(performance.now() - extractionStart);
logger.debug(
`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionDurationMs} ms).`,
Expand All @@ -544,6 +549,7 @@ export const downloadCodeQL = async function (
return {
codeqlFolder: extractedBundlePath,
statusReport: {
compressionMethod,
downloadDurationMs,
extractionDurationMs,
},
Expand Down Expand Up @@ -575,6 +581,7 @@ export const downloadCodeQL = async function (
return {
codeqlFolder: toolcachedBundlePath,
statusReport: {
compressionMethod,
downloadDurationMs,
extractionDurationMs,
},
Expand Down Expand Up @@ -619,17 +626,16 @@ function getCanonicalToolcacheVersion(
return cliVersion;
}

export interface SetupCodeQLResult {
codeqlFolder: string;
toolsDownloadStatusReport?: ToolsDownloadStatusReport;
toolsSource: ToolsSource;
toolsVersion: string;
}

/**
* Obtains the CodeQL bundle, installs it in the toolcache if appropriate, and extracts it.
*
* @param toolsInput
* @param apiDetails
* @param tempDir
* @param variant
* @param defaultCliVersion
* @param logger
* @param checkVersion Whether to check that CodeQL CLI meets the minimum
* version requirement. Must be set to true outside tests.
* @returns the path to the extracted bundle, and the version of the tools
*/
export async function setupCodeQLBundle(
Expand All @@ -639,12 +645,7 @@ export async function setupCodeQLBundle(
variant: util.GitHubVariant,
defaultCliVersion: CodeQLDefaultVersionInfo,
logger: Logger,
): Promise<{
codeqlFolder: string;
toolsDownloadStatusReport?: ToolsDownloadStatusReport;
toolsSource: ToolsSource;
toolsVersion: string;
}> {
): Promise<SetupCodeQLResult> {
const source = await getCodeQLSource(
toolsInput,
defaultCliVersion,
Expand Down Expand Up @@ -706,9 +707,26 @@ async function cleanUpGlob(glob: string, name: string, logger: Logger) {
}
}

async function extractBundle(archivedBundlePath: string): Promise<string> {
async function extractBundle(archivedBundlePath: string): Promise<{
compressionMethod: CompressionMethod;
extractedBundlePath: string;
}> {
if (archivedBundlePath.endsWith(".tar.gz")) {
return await toolcache.extractTar(archivedBundlePath);
return {
compressionMethod: "gzip",
// While we could also ask tar to autodetect the compression method,
// we defensively keep the gzip call identical as requesting a gzipped
// bundle will soon be a fallback option.
extractedBundlePath: await toolcache.extractTar(archivedBundlePath),
};
}
return await toolcache.extractTar(archivedBundlePath, undefined, "x");
return {
compressionMethod: "zstd",
// tar will autodetect the compression method
extractedBundlePath: await toolcache.extractTar(
archivedBundlePath,
undefined,
"x",
),
};
}

0 comments on commit cf64c3e

Please sign in to comment.