Add telemetry for compression method

This commit is contained in:
Henry Mercer 2024-08-13 15:56:38 +01:00
parent e2572269a1
commit cf64c3e3a3
9 changed files with 66 additions and 32 deletions

1
lib/codeql.js generated
View file

@ -121,6 +121,7 @@ const CODEQL_VERSION_INCLUDE_QUERY_HELP = "2.15.2";
async function setupCodeQL(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, logger, checkVersion) {
try {
const { codeqlFolder, toolsDownloadStatusReport, toolsSource, toolsVersion, } = await setupCodeql.setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, logger);
logger.debug(`Bundle download status report: ${JSON.stringify(toolsDownloadStatusReport)}`);
let codeqlCmd = path.join(codeqlFolder, "codeql", "codeql");
if (process.platform === "win32") {
codeqlCmd += ".exe";

File diff suppressed because one or more lines are too long

26
lib/setup-codeql.js generated
View file

@ -397,7 +397,7 @@ const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVe
logger.debug(`Finished downloading CodeQL bundle to ${archivedBundlePath} (${downloadDurationMs} ms).`);
logger.debug("Extracting CodeQL bundle.");
const extractionStart = perf_hooks_1.performance.now();
const extractedBundlePath = await extractBundle(archivedBundlePath);
const { extractedBundlePath, compressionMethod } = await extractBundle(archivedBundlePath);
const extractionDurationMs = Math.round(perf_hooks_1.performance.now() - extractionStart);
logger.debug(`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionDurationMs} ms).`);
await cleanUpGlob(archivedBundlePath, "CodeQL bundle archive", logger);
@ -408,6 +408,7 @@ const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVe
return {
codeqlFolder: extractedBundlePath,
statusReport: {
compressionMethod,
downloadDurationMs,
extractionDurationMs,
},
@ -424,6 +425,7 @@ const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVe
return {
codeqlFolder: toolcachedBundlePath,
statusReport: {
compressionMethod,
downloadDurationMs,
extractionDurationMs,
},
@ -463,14 +465,6 @@ function getCanonicalToolcacheVersion(cliVersion, bundleVersion, logger) {
/**
* 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
*/
async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, logger) {
@ -522,8 +516,18 @@ async function cleanUpGlob(glob, name, logger) {
}
async function extractBundle(archivedBundlePath) {
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"),
};
}
//# sourceMappingURL=setup-codeql.js.map

File diff suppressed because one or more lines are too long

View file

@ -116,6 +116,7 @@ ava_1.default.beforeEach(() => {
sinon.stub(setupCodeql, "downloadCodeQL").resolves({
codeqlFolder: "codeql",
statusReport: {
compressionMethod: "gzip",
downloadDurationMs: 200,
extractionDurationMs: 300,
},
@ -143,6 +144,7 @@ ava_1.default.beforeEach(() => {
sinon.stub(setupCodeql, "downloadCodeQL").resolves({
codeqlFolder: "codeql",
statusReport: {
compressionMethod: "gzip",
downloadDurationMs: 200,
extractionDurationMs: 300,
},

File diff suppressed because one or more lines are too long

View file

@ -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";

View file

@ -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,
},
@ -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,
},

View file

@ -461,7 +461,10 @@ export async function tryGetFallbackToolcacheVersion(
return fallbackVersion;
}
type CompressionMethod = "gzip" | "zstd";
export interface ToolsDownloadStatusReport {
compressionMethod: CompressionMethod;
downloadDurationMs: number;
extractionDurationMs: number;
}
@ -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).`,
@ -544,6 +549,7 @@ export const downloadCodeQL = async function (
return {
codeqlFolder: extractedBundlePath,
statusReport: {
compressionMethod,
downloadDurationMs,
extractionDurationMs,
},
@ -575,6 +581,7 @@ export const downloadCodeQL = async function (
return {
codeqlFolder: toolcachedBundlePath,
statusReport: {
compressionMethod,
downloadDurationMs,
extractionDurationMs,
},
@ -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(
@ -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,
@ -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",
),
};
}