Merge pull request #4105 from github/henrymercer/tools-download-telem… · github/codeql-action@3e93618 · GitHub
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

‎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

0 commit comments

Comments
 (0)