Add telemetry for compression method

This commit is contained in:
Henry Mercer
2024-08-13 15:56:38 +01:00
parent 6ece038d8b
commit 59c874ecee
9 changed files with 75 additions and 44 deletions

1
lib/codeql.js generated
View File

@@ -138,6 +138,7 @@ async function setupCodeQLBundlePreferringZstd(toolsInput, apiDetails, tempDir,
async function setupCodeQL(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger, checkVersion) {
try {
const { codeqlFolder, toolsDownloadStatusReport, toolsSource, toolsVersion, } = await setupCodeQLBundlePreferringZstd(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, 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

44
lib/setup-codeql.js generated
View File

@@ -75,11 +75,9 @@ function getCodeQLBundleBaseName() {
}
return `codeql-bundle-${platform}`;
}
async function getCodeQLBundleName(useStdBundle) {
if (useStdBundle) {
return `${getCodeQLBundleBaseName()}.tar.zst`;
}
return `${getCodeQLBundleBaseName()}.tar.gz`;
async function getCodeQLBundleName(useZstdBundle) {
const extension = useZstdBundle ? "tar.zst" : "tar.gz";
return `${getCodeQLBundleBaseName()}.${extension}`;
}
function getCodeQLActionRepository(logger) {
if ((0, actions_util_1.isRunningLocalAction)()) {
@@ -91,7 +89,7 @@ function getCodeQLActionRepository(logger) {
}
return util.getRequiredEnvParam("GITHUB_ACTION_REPOSITORY");
}
async function getCodeQLBundleDownloadURL(tagName, apiDetails, useStdBundle, logger) {
async function getCodeQLBundleDownloadURL(tagName, apiDetails, useZstdBundle, logger) {
const codeQLActionRepository = getCodeQLActionRepository(logger);
const potentialDownloadSources = [
// This GitHub instance, and this Action.
@@ -106,7 +104,7 @@ async function getCodeQLBundleDownloadURL(tagName, apiDetails, useStdBundle, log
const uniqueDownloadSources = potentialDownloadSources.filter((source, index, self) => {
return !self.slice(0, index).some((other) => (0, fast_deep_equal_1.default)(source, other));
});
const codeQLBundleName = await getCodeQLBundleName(useStdBundle);
const codeQLBundleName = await getCodeQLBundleName(useZstdBundle);
for (const downloadSource of uniqueDownloadSources) {
const [apiURL, repository] = downloadSource;
// If we've reached the final case, short-circuit the API check since we know the bundle exists and is public.
@@ -198,7 +196,7 @@ async function findOverridingToolsInCache(humanReadableVersion, logger) {
}
return undefined;
}
async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, useStdBundle, logger) {
async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, useZstdBundle, logger) {
if (toolsInput &&
!CODEQL_BUNDLE_VERSION_ALIAS.includes(toolsInput) &&
!toolsInput.startsWith("http")) {
@@ -340,7 +338,7 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian
}
}
if (!url) {
url = await getCodeQLBundleDownloadURL(tagName, apiDetails, useStdBundle, logger);
url = await getCodeQLBundleDownloadURL(tagName, apiDetails, useZstdBundle, logger);
}
if (cliVersion) {
logger.info(`Using CodeQL CLI version ${cliVersion} sourced from ${url}.`);
@@ -403,7 +401,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 { compressionMethod, extractedBundlePath } = 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);
@@ -414,6 +412,7 @@ const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVe
return {
codeqlFolder: extractedBundlePath,
statusReport: {
compressionMethod,
downloadDurationMs,
extractionDurationMs,
},
@@ -430,6 +429,7 @@ const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVe
return {
codeqlFolder: toolcachedBundlePath,
statusReport: {
compressionMethod,
downloadDurationMs,
extractionDurationMs,
},
@@ -469,18 +469,12 @@ 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, useStdBundle, logger) {
const source = await getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, useStdBundle, logger);
async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, useZstdBundle, logger) {
const source = await getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, useZstdBundle, logger);
let codeqlFolder;
let toolsVersion = source.toolsVersion;
let toolsDownloadStatusReport;
@@ -528,8 +522,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