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
Generated
+1
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";
+1 -1
View File
File diff suppressed because one or more lines are too long
+24 -20
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
+2
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
+6
View File
@@ -421,6 +421,12 @@ export async function setupCodeQL(
logger,
);
logger.debug(
`Bundle download status report: ${JSON.stringify(
toolsDownloadStatusReport,
)}`,
);
let codeqlCmd = path.join(codeqlFolder, "codeql", "codeql");
if (process.platform === "win32") {
codeqlCmd += ".exe";
+2
View File
@@ -157,6 +157,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,
},
@@ -204,6 +205,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,
},
+37 -21
View File
@@ -45,11 +45,9 @@ function getCodeQLBundleBaseName(): string {
return `codeql-bundle-${platform}`;
}
async function getCodeQLBundleName(useStdBundle: boolean): Promise<string> {
if (useStdBundle) {
return `${getCodeQLBundleBaseName()}.tar.zst`;
}
return `${getCodeQLBundleBaseName()}.tar.gz`;
async function getCodeQLBundleName(useZstdBundle: boolean): Promise<string> {
const extension = useZstdBundle ? "tar.zst" : "tar.gz";
return `${getCodeQLBundleBaseName()}.${extension}`;
}
export function getCodeQLActionRepository(logger: Logger): string {
@@ -69,7 +67,7 @@ export function getCodeQLActionRepository(logger: Logger): string {
async function getCodeQLBundleDownloadURL(
tagName: string,
apiDetails: api.GitHubApiDetails,
useStdBundle: boolean,
useZstdBundle: boolean,
logger: Logger,
): Promise<string> {
const codeQLActionRepository = getCodeQLActionRepository(logger);
@@ -88,7 +86,7 @@ async function getCodeQLBundleDownloadURL(
return !self.slice(0, index).some((other) => deepEqual(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.
@@ -238,7 +236,7 @@ export async function getCodeQLSource(
defaultCliVersion: CodeQLDefaultVersionInfo,
apiDetails: api.GitHubApiDetails,
variant: util.GitHubVariant,
useStdBundle: boolean,
useZstdBundle: boolean,
logger: Logger,
): Promise<CodeQLToolsSource> {
if (
@@ -435,7 +433,7 @@ export async function getCodeQLSource(
url = await getCodeQLBundleDownloadURL(
tagName!,
apiDetails,
useStdBundle,
useZstdBundle,
logger,
);
}
@@ -475,7 +473,10 @@ export async function tryGetFallbackToolcacheVersion(
return fallbackVersion;
}
type CompressionMethod = "gzip" | "zstd";
export interface ToolsDownloadStatusReport {
compressionMethod: CompressionMethod;
downloadDurationMs: number;
extractionDurationMs: number;
}
@@ -540,7 +541,9 @@ export const downloadCodeQL = async function (
logger.debug("Extracting CodeQL bundle.");
const extractionStart = performance.now();
const extractedBundlePath = await extractBundle(archivedBundlePath);
const { compressionMethod, extractedBundlePath } = await extractBundle(
archivedBundlePath,
);
const extractionDurationMs = Math.round(performance.now() - extractionStart);
logger.debug(
`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionDurationMs} ms).`,
@@ -558,6 +561,7 @@ export const downloadCodeQL = async function (
return {
codeqlFolder: extractedBundlePath,
statusReport: {
compressionMethod,
downloadDurationMs,
extractionDurationMs,
},
@@ -589,6 +593,7 @@ export const downloadCodeQL = async function (
return {
codeqlFolder: toolcachedBundlePath,
statusReport: {
compressionMethod,
downloadDurationMs,
extractionDurationMs,
},
@@ -643,12 +648,6 @@ export interface SetupCodeQLResult {
/**
* 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
@@ -659,7 +658,7 @@ export async function setupCodeQLBundle(
tempDir: string,
variant: util.GitHubVariant,
defaultCliVersion: CodeQLDefaultVersionInfo,
useStdBundle: boolean,
useZstdBundle: boolean,
logger: Logger,
): Promise<SetupCodeQLResult> {
const source = await getCodeQLSource(
@@ -667,7 +666,7 @@ export async function setupCodeQLBundle(
defaultCliVersion,
apiDetails,
variant,
useStdBundle,
useZstdBundle,
logger,
);
@@ -724,9 +723,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",
),
};
}