Skip to content

Commit 3e93618

Browse files
authored
Merge pull request #4105 from github/henrymercer/tools-download-telemetry
Improve CodeQL tools download time telemetry
2 parents 920ba7c + 9d89e2d commit 3e93618

7 files changed

Lines changed: 86 additions & 19 deletions

File tree

lib/entry-points.js

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

src/init-action.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ async function sendCompletedStatusReport(
174174
initToolsDownloadFields.tools_download_duration_ms =
175175
toolsDownloadStatusReport.downloadDurationMs;
176176
}
177+
if (toolsDownloadStatusReport?.extractionDurationMs !== undefined) {
178+
initToolsDownloadFields.tools_extraction_duration_ms =
179+
toolsDownloadStatusReport.extractionDurationMs;
180+
}
181+
if (toolsDownloadStatusReport?.totalDurationMs !== undefined) {
182+
initToolsDownloadFields.tools_total_duration_ms =
183+
toolsDownloadStatusReport.totalDurationMs;
184+
}
177185
if (toolsFeatureFlagsValid !== undefined) {
178186
initToolsDownloadFields.tools_feature_flags_valid = toolsFeatureFlagsValid;
179187
}

src/setup-codeql-action.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ async function sendCompletedStatusReport(
8585
initToolsDownloadFields.tools_download_duration_ms =
8686
toolsDownloadStatusReport.downloadDurationMs;
8787
}
88+
if (toolsDownloadStatusReport?.extractionDurationMs !== undefined) {
89+
initToolsDownloadFields.tools_extraction_duration_ms =
90+
toolsDownloadStatusReport.extractionDurationMs;
91+
}
92+
if (toolsDownloadStatusReport?.totalDurationMs !== undefined) {
93+
initToolsDownloadFields.tools_total_duration_ms =
94+
toolsDownloadStatusReport.totalDurationMs;
95+
}
8896
if (toolsFeatureFlagsValid !== undefined) {
8997
initToolsDownloadFields.tools_feature_flags_valid = toolsFeatureFlagsValid;
9098
}

src/setup-codeql.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ test.serial(
234234
codeqlFolder: "codeql",
235235
statusReport: {
236236
downloadDurationMs: 200,
237+
totalDurationMs: 300,
237238
},
238239
toolsVersion: LINKED_CLI_VERSION.cliVersion,
239240
});
@@ -286,6 +287,7 @@ test.serial(
286287
codeqlFolder: "codeql",
287288
statusReport: {
288289
downloadDurationMs: 200,
290+
totalDurationMs: 300,
289291
},
290292
toolsVersion: expectedVersion,
291293
});

src/status-report.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,21 @@ export interface InitWithConfigStatusReport extends InitStatusReport {
620620

621621
/** Fields of the init status report populated when the tools source is `download`. */
622622
export interface InitToolsDownloadFields {
623-
/** Time taken to download the bundle, in milliseconds. */
623+
/**
624+
* Time taken to download the bundle, in milliseconds. Not populated when the bundle is downloaded
625+
* and extracted concurrently.
626+
*/
624627
tools_download_duration_ms?: number;
628+
/**
629+
* Time taken to extract the bundle, in milliseconds. Not populated when the bundle is downloaded
630+
* and extracted concurrently.
631+
*/
632+
tools_extraction_duration_ms?: number;
633+
/**
634+
* Total time taken to make the bundle available on disk, in milliseconds. This includes any time
635+
* spent on a streaming attempt that failed and fell back to downloading before extracting.
636+
*/
637+
tools_total_duration_ms?: number;
625638
/**
626639
* Whether the relevant tools dotcom feature flags have been misconfigured.
627640
* Only populated if we attempt to determine the default version based on the dotcom feature flags. */

src/tools-download.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { withTmpDir } from "./util";
1515
setupTests(test);
1616

1717
test.serial(
18-
"downloadAndExtract reports the duration when downloading before extracting",
18+
"downloadAndExtract reports the durations when downloading before extracting",
1919
async (t) => {
2020
await withTmpDir(async (tmpDir) => {
2121
const archivePath = path.join(tmpDir, "codeql-bundle.tar.gz");
@@ -34,6 +34,8 @@ test.serial(
3434
);
3535

3636
t.assert(Number.isInteger(statusReport.downloadDurationMs));
37+
t.assert(Number.isInteger(statusReport.extractionDurationMs));
38+
t.assert(Number.isInteger(statusReport.totalDurationMs));
3739
});
3840
},
3941
);
@@ -67,6 +69,7 @@ test.serial(
6769
);
6870

6971
t.assert(Number.isInteger(statusReport.downloadDurationMs));
72+
t.assert(Number.isInteger(statusReport.totalDurationMs));
7073
t.true(request.isDone());
7174
t.false(extractTarZst.called);
7275
t.true(downloadTool.calledOnce);
@@ -76,7 +79,7 @@ test.serial(
7679
);
7780

7881
test.serial(
79-
"downloadAndExtract omits the download duration when streaming extraction",
82+
"downloadAndExtract reports only the total duration when streaming extraction",
8083
async (t) => {
8184
await withTmpDir(async (tmpDir) => {
8285
sinon.stub(process, "platform").value("linux");
@@ -106,7 +109,9 @@ test.serial(
106109
getRunnerLogger(true),
107110
);
108111

109-
t.deepEqual(statusReport, {});
112+
t.assert(Number.isInteger(statusReport.totalDurationMs));
113+
t.is(statusReport.downloadDurationMs, undefined);
114+
t.is(statusReport.extractionDurationMs, undefined);
110115
t.false(downloadTool.called);
111116
t.true(extractTarZst.calledOnce);
112117
t.true(request.isDone());

src/tools-download.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,21 @@ const STREAMING_STALL_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
3131
const TOOLCACHE_TOOL_NAME = "CodeQL";
3232

3333
export type ToolsDownloadStatusReport = {
34+
/**
35+
* Time spent downloading the bundle, in milliseconds. Not populated when the bundle is downloaded
36+
* and extracted concurrently, since the two cannot be told apart.
37+
*/
3438
downloadDurationMs?: number;
39+
/**
40+
* Time spent extracting the bundle, in milliseconds. Not populated when the bundle is downloaded
41+
* and extracted concurrently, since the two cannot be told apart.
42+
*/
43+
extractionDurationMs?: number;
44+
/**
45+
* Total time taken to make the bundle available on disk, in milliseconds. This includes any time
46+
* spent on a streaming attempt that failed and fell back to downloading before extracting.
47+
*/
48+
totalDurationMs: number;
3549
};
3650

3751
export async function downloadAndExtract(
@@ -47,11 +61,12 @@ export async function downloadAndExtract(
4761
`Downloading CodeQL tools from ${codeqlURL} . This may take a while.`,
4862
);
4963

64+
const startTime = performance.now();
65+
5066
try {
5167
if (compressionMethod === "zstd" && process.platform === "linux") {
5268
logger.info(`Streaming the extraction of the CodeQL bundle.`);
5369

54-
const toolsInstallStart = performance.now();
5570
await downloadAndExtractZstdWithStreaming(
5671
codeqlURL,
5772
dest,
@@ -61,16 +76,14 @@ export async function downloadAndExtract(
6176
logger,
6277
);
6378

64-
const combinedDurationMs = Math.round(
65-
performance.now() - toolsInstallStart,
66-
);
79+
const totalDurationMs = Math.round(performance.now() - startTime);
6780
logger.info(
6881
`Finished downloading and extracting CodeQL bundle to ${dest} (${formatDuration(
69-
combinedDurationMs,
82+
totalDurationMs,
7083
)}).`,
7184
);
7285

73-
return {};
86+
return { totalDurationMs };
7487
}
7588
} catch (e) {
7689
core.warning(
@@ -98,7 +111,7 @@ export async function downloadAndExtract(
98111
)}).`,
99112
);
100113

101-
let extractionDurationMs: number;
114+
let extractionDurationMs: number | undefined;
102115

103116
try {
104117
logger.info("Extracting CodeQL bundle.");
@@ -120,7 +133,11 @@ export async function downloadAndExtract(
120133
await cleanUpPath(archivedBundlePath, "CodeQL bundle archive", logger);
121134
}
122135

123-
return { downloadDurationMs };
136+
return {
137+
downloadDurationMs,
138+
extractionDurationMs,
139+
totalDurationMs: Math.round(performance.now() - startTime),
140+
};
124141
}
125142

126143
async function downloadAndExtractZstdWithStreaming(

0 commit comments

Comments
 (0)