mirror of
https://github.com/github/codeql-action.git
synced 2026-10-03 17:41:28 +00:00
Centralize CodeQL download telemetry fields
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
79
lib/entry-points.js
generated
79
lib/entry-points.js
generated
@@ -147621,6 +147621,28 @@ async function sendStatusReport(statusReport) {
|
||||
);
|
||||
}
|
||||
}
|
||||
function createInitToolsDownloadFields(report, toolsFeatureFlagsValid) {
|
||||
const fields = {};
|
||||
if (report?.downloadDurationMs !== void 0) {
|
||||
fields.tools_download_duration_ms = report.downloadDurationMs;
|
||||
}
|
||||
if (report?.extractionDurationMs !== void 0) {
|
||||
fields.tools_extraction_duration_ms = report.extractionDurationMs;
|
||||
}
|
||||
if (report?.totalDurationMs !== void 0) {
|
||||
fields.tools_total_duration_ms = report.totalDurationMs;
|
||||
}
|
||||
if (report?.bundleLanguage !== void 0) {
|
||||
fields.tools_bundle_language = report.bundleLanguage;
|
||||
}
|
||||
if (report?.perLanguageBundleFallback !== void 0) {
|
||||
fields.tools_per_language_bundle_fallback = report.perLanguageBundleFallback;
|
||||
}
|
||||
if (toolsFeatureFlagsValid !== void 0) {
|
||||
fields.tools_feature_flags_valid = toolsFeatureFlagsValid;
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
async function createInitWithConfigStatusReport(config, initStatusReport, configFile, totalCacheSize, overlayBaseDatabaseStats, dependencyCachingResults) {
|
||||
const languages = config.languages.join(",");
|
||||
const paths = (config.originalUserInput.paths || []).join(",");
|
||||
@@ -152532,7 +152554,7 @@ var downloadCodeQL = async function(source, apiDetails, tarVersion, tempDir, log
|
||||
}
|
||||
return {
|
||||
codeqlFolder: extractedBundlePath,
|
||||
statusReport
|
||||
statusReport: bundle.kind === "per-language" ? { ...statusReport, bundleLanguage: bundle.language } : statusReport
|
||||
};
|
||||
};
|
||||
function getToolcacheDestination(source, logger) {
|
||||
@@ -152645,20 +152667,13 @@ async function downloadCodeQLBundle(action, source, apiDetails, tarVersion, temp
|
||||
await tryDeleteToolcacheBundles(action);
|
||||
const startTime = import_perf_hooks3.performance.now();
|
||||
try {
|
||||
const result = await downloadCodeQL(
|
||||
return await downloadCodeQL(
|
||||
source,
|
||||
apiDetails,
|
||||
tarVersion,
|
||||
tempDir,
|
||||
logger
|
||||
);
|
||||
return bundle.kind === "combined" ? result : {
|
||||
...result,
|
||||
statusReport: {
|
||||
...result.statusReport,
|
||||
bundleLanguage: bundle.language
|
||||
}
|
||||
};
|
||||
} catch (e) {
|
||||
if (bundle.kind !== "per-language" || bundle.combinedBundleURL === void 0 || asHTTPError(e)?.status !== 404) {
|
||||
throw e;
|
||||
@@ -162161,25 +162176,10 @@ async function sendCompletedStatusReport2(startedAt, config, configFile, toolsIn
|
||||
if (toolsInput !== void 0) {
|
||||
initStatusReport.computed_inputs.tools = toolsInput;
|
||||
}
|
||||
const initToolsDownloadFields = {};
|
||||
if (toolsDownloadStatusReport?.downloadDurationMs !== void 0) {
|
||||
initToolsDownloadFields.tools_download_duration_ms = toolsDownloadStatusReport.downloadDurationMs;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.extractionDurationMs !== void 0) {
|
||||
initToolsDownloadFields.tools_extraction_duration_ms = toolsDownloadStatusReport.extractionDurationMs;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.totalDurationMs !== void 0) {
|
||||
initToolsDownloadFields.tools_total_duration_ms = toolsDownloadStatusReport.totalDurationMs;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.bundleLanguage !== void 0) {
|
||||
initToolsDownloadFields.tools_bundle_language = toolsDownloadStatusReport.bundleLanguage;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.perLanguageBundleFallback !== void 0) {
|
||||
initToolsDownloadFields.tools_per_language_bundle_fallback = toolsDownloadStatusReport.perLanguageBundleFallback;
|
||||
}
|
||||
if (toolsFeatureFlagsValid !== void 0) {
|
||||
initToolsDownloadFields.tools_feature_flags_valid = toolsFeatureFlagsValid;
|
||||
}
|
||||
const initToolsDownloadFields = createInitToolsDownloadFields(
|
||||
toolsDownloadStatusReport,
|
||||
toolsFeatureFlagsValid
|
||||
);
|
||||
if (config !== void 0) {
|
||||
const initWithConfigStatusReport = await createInitWithConfigStatusReport(
|
||||
config,
|
||||
@@ -163215,25 +163215,10 @@ async function sendCompletedStatusReport3(startedAt, toolsInput, toolsDownloadSt
|
||||
if (toolsInput !== void 0) {
|
||||
initStatusReport.computed_inputs.tools = toolsInput;
|
||||
}
|
||||
const initToolsDownloadFields = {};
|
||||
if (toolsDownloadStatusReport?.downloadDurationMs !== void 0) {
|
||||
initToolsDownloadFields.tools_download_duration_ms = toolsDownloadStatusReport.downloadDurationMs;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.extractionDurationMs !== void 0) {
|
||||
initToolsDownloadFields.tools_extraction_duration_ms = toolsDownloadStatusReport.extractionDurationMs;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.totalDurationMs !== void 0) {
|
||||
initToolsDownloadFields.tools_total_duration_ms = toolsDownloadStatusReport.totalDurationMs;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.bundleLanguage !== void 0) {
|
||||
initToolsDownloadFields.tools_bundle_language = toolsDownloadStatusReport.bundleLanguage;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.perLanguageBundleFallback !== void 0) {
|
||||
initToolsDownloadFields.tools_per_language_bundle_fallback = toolsDownloadStatusReport.perLanguageBundleFallback;
|
||||
}
|
||||
if (toolsFeatureFlagsValid !== void 0) {
|
||||
initToolsDownloadFields.tools_feature_flags_valid = toolsFeatureFlagsValid;
|
||||
}
|
||||
const initToolsDownloadFields = createInitToolsDownloadFields(
|
||||
toolsDownloadStatusReport,
|
||||
toolsFeatureFlagsValid
|
||||
);
|
||||
await sendStatusReport({ ...initStatusReport, ...initToolsDownloadFields });
|
||||
}
|
||||
async function run6(actionState) {
|
||||
|
||||
@@ -63,9 +63,9 @@ import { ToolsSource } from "./setup-codeql";
|
||||
import {
|
||||
ActionName,
|
||||
InitStatusReport,
|
||||
InitToolsDownloadFields,
|
||||
InitWithConfigStatusReport,
|
||||
createInitWithConfigStatusReport,
|
||||
createInitToolsDownloadFields,
|
||||
createStatusReportBase,
|
||||
getActionsStatus,
|
||||
sendStatusReport,
|
||||
@@ -168,31 +168,10 @@ async function sendCompletedStatusReport(
|
||||
initStatusReport.computed_inputs.tools = toolsInput;
|
||||
}
|
||||
|
||||
const initToolsDownloadFields: InitToolsDownloadFields = {};
|
||||
|
||||
if (toolsDownloadStatusReport?.downloadDurationMs !== undefined) {
|
||||
initToolsDownloadFields.tools_download_duration_ms =
|
||||
toolsDownloadStatusReport.downloadDurationMs;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.extractionDurationMs !== undefined) {
|
||||
initToolsDownloadFields.tools_extraction_duration_ms =
|
||||
toolsDownloadStatusReport.extractionDurationMs;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.totalDurationMs !== undefined) {
|
||||
initToolsDownloadFields.tools_total_duration_ms =
|
||||
toolsDownloadStatusReport.totalDurationMs;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.bundleLanguage !== undefined) {
|
||||
initToolsDownloadFields.tools_bundle_language =
|
||||
toolsDownloadStatusReport.bundleLanguage;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.perLanguageBundleFallback !== undefined) {
|
||||
initToolsDownloadFields.tools_per_language_bundle_fallback =
|
||||
toolsDownloadStatusReport.perLanguageBundleFallback;
|
||||
}
|
||||
if (toolsFeatureFlagsValid !== undefined) {
|
||||
initToolsDownloadFields.tools_feature_flags_valid = toolsFeatureFlagsValid;
|
||||
}
|
||||
const initToolsDownloadFields = createInitToolsDownloadFields(
|
||||
toolsDownloadStatusReport,
|
||||
toolsFeatureFlagsValid,
|
||||
);
|
||||
|
||||
if (config !== undefined) {
|
||||
// Append fields that are dependent on `config`
|
||||
|
||||
@@ -22,7 +22,7 @@ import { ToolsSource } from "./setup-codeql";
|
||||
import {
|
||||
ActionName,
|
||||
InitStatusReport,
|
||||
InitToolsDownloadFields,
|
||||
createInitToolsDownloadFields,
|
||||
createStatusReportBase,
|
||||
getActionsStatus,
|
||||
sendStatusReport,
|
||||
@@ -79,31 +79,10 @@ async function sendCompletedStatusReport(
|
||||
initStatusReport.computed_inputs.tools = toolsInput;
|
||||
}
|
||||
|
||||
const initToolsDownloadFields: InitToolsDownloadFields = {};
|
||||
|
||||
if (toolsDownloadStatusReport?.downloadDurationMs !== undefined) {
|
||||
initToolsDownloadFields.tools_download_duration_ms =
|
||||
toolsDownloadStatusReport.downloadDurationMs;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.extractionDurationMs !== undefined) {
|
||||
initToolsDownloadFields.tools_extraction_duration_ms =
|
||||
toolsDownloadStatusReport.extractionDurationMs;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.totalDurationMs !== undefined) {
|
||||
initToolsDownloadFields.tools_total_duration_ms =
|
||||
toolsDownloadStatusReport.totalDurationMs;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.bundleLanguage !== undefined) {
|
||||
initToolsDownloadFields.tools_bundle_language =
|
||||
toolsDownloadStatusReport.bundleLanguage;
|
||||
}
|
||||
if (toolsDownloadStatusReport?.perLanguageBundleFallback !== undefined) {
|
||||
initToolsDownloadFields.tools_per_language_bundle_fallback =
|
||||
toolsDownloadStatusReport.perLanguageBundleFallback;
|
||||
}
|
||||
if (toolsFeatureFlagsValid !== undefined) {
|
||||
initToolsDownloadFields.tools_feature_flags_valid = toolsFeatureFlagsValid;
|
||||
}
|
||||
const initToolsDownloadFields = createInitToolsDownloadFields(
|
||||
toolsDownloadStatusReport,
|
||||
toolsFeatureFlagsValid,
|
||||
);
|
||||
|
||||
await sendStatusReport({ ...initStatusReport, ...initToolsDownloadFields });
|
||||
}
|
||||
|
||||
@@ -1275,6 +1275,10 @@ for (const bundle of ["per-language", "combined", "fallback"] as const) {
|
||||
);
|
||||
t.is(result.toolsDownloadStatusReport?.downloadDurationMs, 200);
|
||||
t.is(result.toolsDownloadStatusReport?.extractionDurationMs, 100);
|
||||
t.is(
|
||||
(await downloadSpy.lastCall.returnValue).statusReport.bundleLanguage,
|
||||
bundle === "per-language" ? BuiltInLanguage.javascript : undefined,
|
||||
);
|
||||
t.is(extractStub.callCount, bundle === "fallback" ? 2 : 1);
|
||||
t.is(downloadSpy.callCount, extractStub.callCount);
|
||||
t.is(
|
||||
|
||||
@@ -920,7 +920,10 @@ export const downloadCodeQL = async function (
|
||||
|
||||
return {
|
||||
codeqlFolder: extractedBundlePath,
|
||||
statusReport,
|
||||
statusReport:
|
||||
bundle.kind === "per-language"
|
||||
? { ...statusReport, bundleLanguage: bundle.language }
|
||||
: statusReport,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1141,22 +1144,13 @@ export async function downloadCodeQLBundle(
|
||||
|
||||
const startTime = performance.now();
|
||||
try {
|
||||
const result = await downloadCodeQL(
|
||||
return await downloadCodeQL(
|
||||
source,
|
||||
apiDetails,
|
||||
tarVersion,
|
||||
tempDir,
|
||||
logger,
|
||||
);
|
||||
return bundle.kind === "combined"
|
||||
? result
|
||||
: {
|
||||
...result,
|
||||
statusReport: {
|
||||
...result.statusReport,
|
||||
bundleLanguage: bundle.language,
|
||||
},
|
||||
};
|
||||
} catch (e) {
|
||||
if (
|
||||
bundle.kind !== "per-language" ||
|
||||
|
||||
@@ -31,6 +31,7 @@ import type { OverlayBaseDatabaseDownloadStats } from "./overlay/caching";
|
||||
import { getRepositoryNwo } from "./repository";
|
||||
import type { ToolsSource } from "./setup-codeql";
|
||||
import { registryBaseSchema } from "./start-proxy/types";
|
||||
import type { ToolsDownloadStatusReport } from "./tools-download";
|
||||
import {
|
||||
ConfigurationError,
|
||||
getRequiredEnvParam,
|
||||
@@ -630,28 +631,56 @@ export interface InitToolsDownloadFields {
|
||||
* Time taken to download the bundle, in milliseconds. Not populated when the bundle is downloaded
|
||||
* and extracted concurrently.
|
||||
*/
|
||||
tools_download_duration_ms?: number;
|
||||
tools_download_duration_ms?: ToolsDownloadStatusReport["downloadDurationMs"];
|
||||
/**
|
||||
* Time taken to extract the bundle, in milliseconds. Not populated when the bundle is downloaded
|
||||
* and extracted concurrently.
|
||||
*/
|
||||
tools_extraction_duration_ms?: number;
|
||||
tools_extraction_duration_ms?: ToolsDownloadStatusReport["extractionDurationMs"];
|
||||
/**
|
||||
* Total time taken to make the bundle available on disk, in milliseconds. This includes any time
|
||||
* spent on a streaming attempt that failed and fell back to downloading before extracting.
|
||||
* Total time taken to make the bundle available on disk, including failed download attempts
|
||||
* before a fallback, in milliseconds.
|
||||
*/
|
||||
tools_total_duration_ms?: number;
|
||||
tools_total_duration_ms?: ToolsDownloadStatusReport["totalDurationMs"];
|
||||
/**
|
||||
* Whether the relevant tools dotcom feature flags have been misconfigured.
|
||||
* Only populated if we attempt to determine the default version based on the dotcom feature flags. */
|
||||
tools_feature_flags_valid?: boolean;
|
||||
/** The language of the single-language bundle that was downloaded, if any. */
|
||||
tools_bundle_language?: string;
|
||||
tools_bundle_language?: ToolsDownloadStatusReport["bundleLanguage"];
|
||||
/**
|
||||
* Whether we tried to download a single-language bundle, but it did not exist and we fell back to
|
||||
* the combined bundle.
|
||||
*/
|
||||
tools_per_language_bundle_fallback?: boolean;
|
||||
tools_per_language_bundle_fallback?: ToolsDownloadStatusReport["perLanguageBundleFallback"];
|
||||
}
|
||||
|
||||
/** Converts download results to telemetry fields shared by the init and setup-codeql Actions. */
|
||||
export function createInitToolsDownloadFields(
|
||||
report: ToolsDownloadStatusReport | undefined,
|
||||
toolsFeatureFlagsValid: boolean | undefined,
|
||||
): InitToolsDownloadFields {
|
||||
const fields: InitToolsDownloadFields = {};
|
||||
if (report?.downloadDurationMs !== undefined) {
|
||||
fields.tools_download_duration_ms = report.downloadDurationMs;
|
||||
}
|
||||
if (report?.extractionDurationMs !== undefined) {
|
||||
fields.tools_extraction_duration_ms = report.extractionDurationMs;
|
||||
}
|
||||
if (report?.totalDurationMs !== undefined) {
|
||||
fields.tools_total_duration_ms = report.totalDurationMs;
|
||||
}
|
||||
if (report?.bundleLanguage !== undefined) {
|
||||
fields.tools_bundle_language = report.bundleLanguage;
|
||||
}
|
||||
if (report?.perLanguageBundleFallback !== undefined) {
|
||||
fields.tools_per_language_bundle_fallback =
|
||||
report.perLanguageBundleFallback;
|
||||
}
|
||||
if (toolsFeatureFlagsValid !== undefined) {
|
||||
fields.tools_feature_flags_valid = toolsFeatureFlagsValid;
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
76
src/tools-download-status-report.test.ts
Normal file
76
src/tools-download-status-report.test.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import test from "ava";
|
||||
|
||||
import { BuiltInLanguage } from "./languages";
|
||||
import { createInitToolsDownloadFields } from "./status-report";
|
||||
|
||||
test("createInitToolsDownloadFields omits absent download data", (t) => {
|
||||
t.deepEqual(createInitToolsDownloadFields(undefined, undefined), {});
|
||||
});
|
||||
|
||||
test("createInitToolsDownloadFields reports feature flags without a download", (t) => {
|
||||
t.deepEqual(createInitToolsDownloadFields(undefined, false), {
|
||||
tools_feature_flags_valid: false,
|
||||
});
|
||||
});
|
||||
|
||||
test("createInitToolsDownloadFields reports only the total for a streaming download", (t) => {
|
||||
t.deepEqual(
|
||||
createInitToolsDownloadFields({ totalDurationMs: 300 }, undefined),
|
||||
{ tools_total_duration_ms: 300 },
|
||||
);
|
||||
});
|
||||
|
||||
test("createInitToolsDownloadFields preserves per-language metadata", (t) => {
|
||||
t.deepEqual(
|
||||
createInitToolsDownloadFields(
|
||||
{ totalDurationMs: 300, bundleLanguage: BuiltInLanguage.java },
|
||||
true,
|
||||
),
|
||||
{
|
||||
tools_total_duration_ms: 300,
|
||||
tools_bundle_language: BuiltInLanguage.java,
|
||||
tools_feature_flags_valid: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test("createInitToolsDownloadFields preserves fallback and per-attempt timings", (t) => {
|
||||
t.deepEqual(
|
||||
createInitToolsDownloadFields(
|
||||
{
|
||||
downloadDurationMs: 200,
|
||||
extractionDurationMs: 100,
|
||||
totalDurationMs: 1000,
|
||||
perLanguageBundleFallback: true,
|
||||
},
|
||||
undefined,
|
||||
),
|
||||
{
|
||||
tools_download_duration_ms: 200,
|
||||
tools_extraction_duration_ms: 100,
|
||||
tools_total_duration_ms: 1000,
|
||||
tools_per_language_bundle_fallback: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test("createInitToolsDownloadFields preserves zero durations and false flags", (t) => {
|
||||
t.deepEqual(
|
||||
createInitToolsDownloadFields(
|
||||
{
|
||||
downloadDurationMs: 0,
|
||||
extractionDurationMs: 0,
|
||||
totalDurationMs: 0,
|
||||
perLanguageBundleFallback: false,
|
||||
},
|
||||
false,
|
||||
),
|
||||
{
|
||||
tools_download_duration_ms: 0,
|
||||
tools_extraction_duration_ms: 0,
|
||||
tools_total_duration_ms: 0,
|
||||
tools_per_language_bundle_fallback: false,
|
||||
tools_feature_flags_valid: false,
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -50,8 +50,8 @@ export type ToolsDownloadStatusReport = {
|
||||
*/
|
||||
extractionDurationMs?: number;
|
||||
/**
|
||||
* Total time taken to make the bundle available on disk, in milliseconds. This includes any time
|
||||
* spent on a streaming attempt that failed and fell back to downloading before extracting.
|
||||
* Total time taken to make the bundle available on disk, including failed download attempts
|
||||
* before a fallback, in milliseconds.
|
||||
*/
|
||||
totalDurationMs: number;
|
||||
/** The language of the single-language bundle that was downloaded, if any. */
|
||||
|
||||
Reference in New Issue
Block a user