Skip to content

Commit cf64c3e

Browse files
committed
Add telemetry for compression method
1 parent e257226 commit cf64c3e

File tree

9 files changed

+66
-32
lines changed

9 files changed

+66
-32
lines changed

lib/codeql.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql.js

Lines changed: 15 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql.test.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/codeql.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,13 @@ export async function setupCodeQL(
368368
defaultCliVersion,
369369
logger,
370370
);
371+
372+
logger.debug(
373+
`Bundle download status report: ${JSON.stringify(
374+
toolsDownloadStatusReport,
375+
)}`,
376+
);
377+
371378
let codeqlCmd = path.join(codeqlFolder, "codeql", "codeql");
372379
if (process.platform === "win32") {
373380
codeqlCmd += ".exe";

src/setup-codeql.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ test("setupCodeQLBundle logs the CodeQL CLI version being used when asked to use
154154
sinon.stub(setupCodeql, "downloadCodeQL").resolves({
155155
codeqlFolder: "codeql",
156156
statusReport: {
157+
compressionMethod: "gzip",
157158
downloadDurationMs: 200,
158159
extractionDurationMs: 300,
159160
},
@@ -200,6 +201,7 @@ test("setupCodeQLBundle logs the CodeQL CLI version being used when asked to dow
200201
sinon.stub(setupCodeql, "downloadCodeQL").resolves({
201202
codeqlFolder: "codeql",
202203
statusReport: {
204+
compressionMethod: "gzip",
203205
downloadDurationMs: 200,
204206
extractionDurationMs: 300,
205207
},

src/setup-codeql.ts

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,10 @@ export async function tryGetFallbackToolcacheVersion(
461461
return fallbackVersion;
462462
}
463463

464+
type CompressionMethod = "gzip" | "zstd";
465+
464466
export interface ToolsDownloadStatusReport {
467+
compressionMethod: CompressionMethod;
465468
downloadDurationMs: number;
466469
extractionDurationMs: number;
467470
}
@@ -526,7 +529,9 @@ export const downloadCodeQL = async function (
526529

527530
logger.debug("Extracting CodeQL bundle.");
528531
const extractionStart = performance.now();
529-
const extractedBundlePath = await extractBundle(archivedBundlePath);
532+
const { extractedBundlePath, compressionMethod } = await extractBundle(
533+
archivedBundlePath,
534+
);
530535
const extractionDurationMs = Math.round(performance.now() - extractionStart);
531536
logger.debug(
532537
`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionDurationMs} ms).`,
@@ -544,6 +549,7 @@ export const downloadCodeQL = async function (
544549
return {
545550
codeqlFolder: extractedBundlePath,
546551
statusReport: {
552+
compressionMethod,
547553
downloadDurationMs,
548554
extractionDurationMs,
549555
},
@@ -575,6 +581,7 @@ export const downloadCodeQL = async function (
575581
return {
576582
codeqlFolder: toolcachedBundlePath,
577583
statusReport: {
584+
compressionMethod,
578585
downloadDurationMs,
579586
extractionDurationMs,
580587
},
@@ -619,17 +626,16 @@ function getCanonicalToolcacheVersion(
619626
return cliVersion;
620627
}
621628

629+
export interface SetupCodeQLResult {
630+
codeqlFolder: string;
631+
toolsDownloadStatusReport?: ToolsDownloadStatusReport;
632+
toolsSource: ToolsSource;
633+
toolsVersion: string;
634+
}
635+
622636
/**
623637
* Obtains the CodeQL bundle, installs it in the toolcache if appropriate, and extracts it.
624638
*
625-
* @param toolsInput
626-
* @param apiDetails
627-
* @param tempDir
628-
* @param variant
629-
* @param defaultCliVersion
630-
* @param logger
631-
* @param checkVersion Whether to check that CodeQL CLI meets the minimum
632-
* version requirement. Must be set to true outside tests.
633639
* @returns the path to the extracted bundle, and the version of the tools
634640
*/
635641
export async function setupCodeQLBundle(
@@ -639,12 +645,7 @@ export async function setupCodeQLBundle(
639645
variant: util.GitHubVariant,
640646
defaultCliVersion: CodeQLDefaultVersionInfo,
641647
logger: Logger,
642-
): Promise<{
643-
codeqlFolder: string;
644-
toolsDownloadStatusReport?: ToolsDownloadStatusReport;
645-
toolsSource: ToolsSource;
646-
toolsVersion: string;
647-
}> {
648+
): Promise<SetupCodeQLResult> {
648649
const source = await getCodeQLSource(
649650
toolsInput,
650651
defaultCliVersion,
@@ -706,9 +707,26 @@ async function cleanUpGlob(glob: string, name: string, logger: Logger) {
706707
}
707708
}
708709

709-
async function extractBundle(archivedBundlePath: string): Promise<string> {
710+
async function extractBundle(archivedBundlePath: string): Promise<{
711+
compressionMethod: CompressionMethod;
712+
extractedBundlePath: string;
713+
}> {
710714
if (archivedBundlePath.endsWith(".tar.gz")) {
711-
return await toolcache.extractTar(archivedBundlePath);
715+
return {
716+
compressionMethod: "gzip",
717+
// While we could also ask tar to autodetect the compression method,
718+
// we defensively keep the gzip call identical as requesting a gzipped
719+
// bundle will soon be a fallback option.
720+
extractedBundlePath: await toolcache.extractTar(archivedBundlePath),
721+
};
712722
}
713-
return await toolcache.extractTar(archivedBundlePath, undefined, "x");
723+
return {
724+
compressionMethod: "zstd",
725+
// tar will autodetect the compression method
726+
extractedBundlePath: await toolcache.extractTar(
727+
archivedBundlePath,
728+
undefined,
729+
"x",
730+
),
731+
};
714732
}

0 commit comments

Comments
 (0)