Add telemetry for time spent extracting CodeQL bundle
This commit is contained in:
parent
5c02493ebf
commit
50357f5d12
21 changed files with 190 additions and 99 deletions
|
|
@ -134,7 +134,9 @@ test("downloads and caches explicitly requested bundles that aren't in the toolc
|
|||
t.assert(toolcache.find("CodeQL", `0.0.0-${version}`));
|
||||
t.is(result.toolsVersion, `0.0.0-${version}`);
|
||||
t.is(result.toolsSource, ToolsSource.Download);
|
||||
t.assert(Number.isInteger(result.toolsDownloadDurationMs));
|
||||
t.assert(
|
||||
Number.isInteger(result.toolsDownloadStatusReport?.downloadDurationMs),
|
||||
);
|
||||
}
|
||||
|
||||
t.is(toolcache.findAllVersions("CodeQL").length, 2);
|
||||
|
|
@ -162,7 +164,9 @@ test("caches semantically versioned bundles using their semantic version number"
|
|||
t.assert(toolcache.find("CodeQL", `2.14.0`));
|
||||
t.is(result.toolsVersion, `2.14.0`);
|
||||
t.is(result.toolsSource, ToolsSource.Download);
|
||||
t.assert(Number.isInteger(result.toolsDownloadDurationMs));
|
||||
t.assert(
|
||||
Number.isInteger(result.toolsDownloadStatusReport?.downloadDurationMs),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -191,7 +195,9 @@ test("downloads an explicitly requested bundle even if a different version is ca
|
|||
t.assert(toolcache.find("CodeQL", "0.0.0-20200610"));
|
||||
t.deepEqual(result.toolsVersion, "0.0.0-20200610");
|
||||
t.is(result.toolsSource, ToolsSource.Download);
|
||||
t.assert(Number.isInteger(result.toolsDownloadDurationMs));
|
||||
t.assert(
|
||||
Number.isInteger(result.toolsDownloadStatusReport?.downloadDurationMs),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -233,7 +239,9 @@ for (const {
|
|||
t.assert(toolcache.find("CodeQL", expectedToolcacheVersion));
|
||||
t.deepEqual(result.toolsVersion, expectedToolcacheVersion);
|
||||
t.is(result.toolsSource, ToolsSource.Download);
|
||||
t.assert(Number.isInteger(result.toolsDownloadDurationMs));
|
||||
t.assert(
|
||||
Number.isInteger(result.toolsDownloadStatusReport?.downloadDurationMs),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -268,7 +276,7 @@ for (const toolcacheVersion of [
|
|||
);
|
||||
t.is(result.toolsVersion, SAMPLE_DEFAULT_CLI_VERSION.cliVersion);
|
||||
t.is(result.toolsSource, ToolsSource.Toolcache);
|
||||
t.is(result.toolsDownloadDurationMs, undefined);
|
||||
t.is(result.toolsDownloadStatusReport?.downloadDurationMs, undefined);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
|
@ -298,7 +306,7 @@ test(`uses a cached bundle when no tools input is given on GHES`, async (t) => {
|
|||
);
|
||||
t.deepEqual(result.toolsVersion, "0.0.0-20200601");
|
||||
t.is(result.toolsSource, ToolsSource.Toolcache);
|
||||
t.is(result.toolsDownloadDurationMs, undefined);
|
||||
t.is(result.toolsDownloadStatusReport?.downloadDurationMs, undefined);
|
||||
|
||||
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||
t.is(cachedVersions.length, 1);
|
||||
|
|
@ -332,7 +340,9 @@ test(`downloads bundle if only an unpinned version is cached on GHES`, async (t)
|
|||
);
|
||||
t.deepEqual(result.toolsVersion, defaults.cliVersion);
|
||||
t.is(result.toolsSource, ToolsSource.Download);
|
||||
t.assert(Number.isInteger(result.toolsDownloadDurationMs));
|
||||
t.assert(
|
||||
Number.isInteger(result.toolsDownloadStatusReport?.downloadDurationMs),
|
||||
);
|
||||
|
||||
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||
t.is(cachedVersions.length, 2);
|
||||
|
|
@ -363,7 +373,9 @@ test('downloads bundle if "latest" tools specified but not cached', async (t) =>
|
|||
);
|
||||
t.deepEqual(result.toolsVersion, defaults.cliVersion);
|
||||
t.is(result.toolsSource, ToolsSource.Download);
|
||||
t.assert(Number.isInteger(result.toolsDownloadDurationMs));
|
||||
t.assert(
|
||||
Number.isInteger(result.toolsDownloadStatusReport?.downloadDurationMs),
|
||||
);
|
||||
|
||||
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||
t.is(cachedVersions.length, 2);
|
||||
|
|
@ -398,7 +410,9 @@ test("bundle URL from another repo is cached as 0.0.0-bundleVersion", async (t)
|
|||
|
||||
t.is(result.toolsVersion, "0.0.0-20230203");
|
||||
t.is(result.toolsSource, ToolsSource.Download);
|
||||
t.true(Number.isInteger(result.toolsDownloadDurationMs));
|
||||
t.true(
|
||||
Number.isInteger(result.toolsDownloadStatusReport?.downloadDurationMs),
|
||||
);
|
||||
|
||||
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||
t.is(cachedVersions.length, 1);
|
||||
|
|
|
|||
|
|
@ -350,20 +350,24 @@ export async function setupCodeQL(
|
|||
checkVersion: boolean,
|
||||
): Promise<{
|
||||
codeql: CodeQL;
|
||||
toolsDownloadDurationMs?: number;
|
||||
toolsDownloadStatusReport?: setupCodeql.ToolsDownloadStatusReport;
|
||||
toolsSource: setupCodeql.ToolsSource;
|
||||
toolsVersion: string;
|
||||
}> {
|
||||
try {
|
||||
const { codeqlFolder, toolsDownloadDurationMs, toolsSource, toolsVersion } =
|
||||
await setupCodeql.setupCodeQLBundle(
|
||||
toolsInput,
|
||||
apiDetails,
|
||||
tempDir,
|
||||
variant,
|
||||
defaultCliVersion,
|
||||
logger,
|
||||
);
|
||||
const {
|
||||
codeqlFolder,
|
||||
toolsDownloadStatusReport,
|
||||
toolsSource,
|
||||
toolsVersion,
|
||||
} = await setupCodeql.setupCodeQLBundle(
|
||||
toolsInput,
|
||||
apiDetails,
|
||||
tempDir,
|
||||
variant,
|
||||
defaultCliVersion,
|
||||
logger,
|
||||
);
|
||||
let codeqlCmd = path.join(codeqlFolder, "codeql", "codeql");
|
||||
if (process.platform === "win32") {
|
||||
codeqlCmd += ".exe";
|
||||
|
|
@ -376,7 +380,7 @@ export async function setupCodeQL(
|
|||
cachedCodeQL = await getCodeQLForCmd(codeqlCmd, checkVersion);
|
||||
return {
|
||||
codeql: cachedCodeQL,
|
||||
toolsDownloadDurationMs,
|
||||
toolsDownloadStatusReport,
|
||||
toolsSource,
|
||||
toolsVersion,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -100,7 +100,9 @@ export function addDiagnostic(
|
|||
diagnostic: DiagnosticMessage,
|
||||
) {
|
||||
const logger = getActionsLogger();
|
||||
const databasePath = getCodeQLDatabasePath(config, language);
|
||||
const databasePath = language
|
||||
? getCodeQLDatabasePath(config, language)
|
||||
: config.dbLocation;
|
||||
|
||||
// Check that the database exists before writing to it. If the database does not yet exist,
|
||||
// store the diagnostic in memory and write it later.
|
||||
|
|
@ -124,12 +126,15 @@ export function addDiagnostic(
|
|||
*/
|
||||
function writeDiagnostic(
|
||||
config: Config,
|
||||
language: Language,
|
||||
language: Language | undefined,
|
||||
diagnostic: DiagnosticMessage,
|
||||
) {
|
||||
const logger = getActionsLogger();
|
||||
const databasePath = language
|
||||
? getCodeQLDatabasePath(config, language)
|
||||
: config.dbLocation;
|
||||
const diagnosticsPath = path.resolve(
|
||||
getCodeQLDatabasePath(config, language),
|
||||
databasePath,
|
||||
"diagnostic",
|
||||
"codeql-action",
|
||||
);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import {
|
|||
import { Language } from "./languages";
|
||||
import { getActionsLogger, Logger } from "./logging";
|
||||
import { parseRepositoryNwo } from "./repository";
|
||||
import { ToolsSource } from "./setup-codeql";
|
||||
import { ToolsDownloadStatusReport, ToolsSource } from "./setup-codeql";
|
||||
import {
|
||||
ActionName,
|
||||
StatusReportBase,
|
||||
|
|
@ -114,7 +114,7 @@ interface InitToolsDownloadFields {
|
|||
async function sendCompletedStatusReport(
|
||||
startedAt: Date,
|
||||
config: configUtils.Config | undefined,
|
||||
toolsDownloadDurationMs: number | undefined,
|
||||
toolsDownloadStatusReport: ToolsDownloadStatusReport | undefined,
|
||||
toolsFeatureFlagsValid: boolean | undefined,
|
||||
toolsSource: ToolsSource,
|
||||
toolsVersion: string,
|
||||
|
|
@ -148,9 +148,9 @@ async function sendCompletedStatusReport(
|
|||
|
||||
const initToolsDownloadFields: InitToolsDownloadFields = {};
|
||||
|
||||
if (toolsDownloadDurationMs !== undefined) {
|
||||
if (toolsDownloadStatusReport !== undefined) {
|
||||
initToolsDownloadFields.tools_download_duration_ms =
|
||||
toolsDownloadDurationMs;
|
||||
toolsDownloadStatusReport.downloadDurationMs;
|
||||
}
|
||||
if (toolsFeatureFlagsValid !== undefined) {
|
||||
initToolsDownloadFields.tools_feature_flags_valid = toolsFeatureFlagsValid;
|
||||
|
|
@ -245,7 +245,7 @@ async function run() {
|
|||
|
||||
let config: configUtils.Config | undefined;
|
||||
let codeql: CodeQL;
|
||||
let toolsDownloadDurationMs: number | undefined;
|
||||
let toolsDownloadStatusReport: ToolsDownloadStatusReport | undefined;
|
||||
let toolsFeatureFlagsValid: boolean | undefined;
|
||||
let toolsSource: ToolsSource;
|
||||
let toolsVersion: string;
|
||||
|
|
@ -300,7 +300,7 @@ async function run() {
|
|||
logger,
|
||||
);
|
||||
codeql = initCodeQLResult.codeql;
|
||||
toolsDownloadDurationMs = initCodeQLResult.toolsDownloadDurationMs;
|
||||
toolsDownloadStatusReport = initCodeQLResult.toolsDownloadStatusReport;
|
||||
toolsVersion = initCodeQLResult.toolsVersion;
|
||||
toolsSource = initCodeQLResult.toolsSource;
|
||||
|
||||
|
|
@ -366,6 +366,28 @@ async function run() {
|
|||
try {
|
||||
cleanupDatabaseClusterDirectory(config, logger);
|
||||
|
||||
// Log CodeQL download telemetry, if appropriate
|
||||
if (toolsDownloadStatusReport) {
|
||||
addDiagnostic(
|
||||
config,
|
||||
// Arbitrarily choose the first language. We could also choose all languages, but that
|
||||
// increases the risk of misinterpreting the data.
|
||||
config.languages[0],
|
||||
makeDiagnostic(
|
||||
"codeql-action/bundle-download-telemetry",
|
||||
"CodeQL bundle download telemetry",
|
||||
{
|
||||
attributes: toolsDownloadStatusReport,
|
||||
visibility: {
|
||||
cliSummaryTable: false,
|
||||
statusPage: false,
|
||||
telemetry: true,
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Forward Go flags
|
||||
const goFlags = process.env["GOFLAGS"];
|
||||
if (goFlags) {
|
||||
|
|
@ -603,7 +625,7 @@ async function run() {
|
|||
await sendCompletedStatusReport(
|
||||
startedAt,
|
||||
config,
|
||||
toolsDownloadDurationMs,
|
||||
toolsDownloadStatusReport,
|
||||
toolsFeatureFlagsValid,
|
||||
toolsSource,
|
||||
toolsVersion,
|
||||
|
|
@ -617,7 +639,7 @@ async function run() {
|
|||
await sendCompletedStatusReport(
|
||||
startedAt,
|
||||
config,
|
||||
toolsDownloadDurationMs,
|
||||
toolsDownloadStatusReport,
|
||||
toolsFeatureFlagsValid,
|
||||
toolsSource,
|
||||
toolsVersion,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import * as configUtils from "./config-utils";
|
|||
import { CodeQLDefaultVersionInfo } from "./feature-flags";
|
||||
import { Language, isScannedLanguage } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import { ToolsSource } from "./setup-codeql";
|
||||
import { ToolsDownloadStatusReport, ToolsSource } from "./setup-codeql";
|
||||
import { ToolsFeature } from "./tools-features";
|
||||
import { TracerConfig, getCombinedTracerConfig } from "./tracer-config";
|
||||
import * as util from "./util";
|
||||
|
|
@ -26,12 +26,12 @@ export async function initCodeQL(
|
|||
logger: Logger,
|
||||
): Promise<{
|
||||
codeql: CodeQL;
|
||||
toolsDownloadDurationMs?: number;
|
||||
toolsDownloadStatusReport?: ToolsDownloadStatusReport;
|
||||
toolsSource: ToolsSource;
|
||||
toolsVersion: string;
|
||||
}> {
|
||||
logger.startGroup("Setup CodeQL tools");
|
||||
const { codeql, toolsDownloadDurationMs, toolsSource, toolsVersion } =
|
||||
const { codeql, toolsDownloadStatusReport, toolsSource, toolsVersion } =
|
||||
await setupCodeQL(
|
||||
toolsInput,
|
||||
apiDetails,
|
||||
|
|
@ -43,7 +43,7 @@ export async function initCodeQL(
|
|||
);
|
||||
await codeql.printVersion();
|
||||
logger.endGroup();
|
||||
return { codeql, toolsDownloadDurationMs, toolsSource, toolsVersion };
|
||||
return { codeql, toolsDownloadStatusReport, toolsSource, toolsVersion };
|
||||
}
|
||||
|
||||
export async function initConfig(
|
||||
|
|
|
|||
|
|
@ -152,9 +152,12 @@ test("setupCodeQLBundle logs the CodeQL CLI version being used when asked to use
|
|||
// Stub the downloadCodeQL function to prevent downloading artefacts
|
||||
// during testing from being called.
|
||||
sinon.stub(setupCodeql, "downloadCodeQL").resolves({
|
||||
toolsVersion: LINKED_CLI_VERSION.cliVersion,
|
||||
codeqlFolder: "codeql",
|
||||
toolsDownloadDurationMs: 200,
|
||||
statusReport: {
|
||||
downloadDurationMs: 200,
|
||||
extractionDurationMs: 300,
|
||||
},
|
||||
toolsVersion: LINKED_CLI_VERSION.cliVersion,
|
||||
});
|
||||
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
|
|
@ -195,9 +198,12 @@ test("setupCodeQLBundle logs the CodeQL CLI version being used when asked to dow
|
|||
// Stub the downloadCodeQL function to prevent downloading artefacts
|
||||
// during testing from being called.
|
||||
sinon.stub(setupCodeql, "downloadCodeQL").resolves({
|
||||
toolsVersion: expectedVersion,
|
||||
codeqlFolder: "codeql",
|
||||
toolsDownloadDurationMs: 200,
|
||||
statusReport: {
|
||||
downloadDurationMs: 200,
|
||||
extractionDurationMs: 300,
|
||||
},
|
||||
toolsVersion: expectedVersion,
|
||||
});
|
||||
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
|
|
|
|||
|
|
@ -461,6 +461,11 @@ export async function tryGetFallbackToolcacheVersion(
|
|||
return fallbackVersion;
|
||||
}
|
||||
|
||||
export interface ToolsDownloadStatusReport {
|
||||
downloadDurationMs: number;
|
||||
extractionDurationMs: number;
|
||||
}
|
||||
|
||||
// Exported using `export const` for testing purposes. Specifically, we want to
|
||||
// be able to stub this function and have other functions in this file use that stub.
|
||||
export const downloadCodeQL = async function (
|
||||
|
|
@ -471,9 +476,9 @@ export const downloadCodeQL = async function (
|
|||
tempDir: string,
|
||||
logger: Logger,
|
||||
): Promise<{
|
||||
toolsVersion: string;
|
||||
codeqlFolder: string;
|
||||
toolsDownloadDurationMs: number;
|
||||
statusReport: ToolsDownloadStatusReport;
|
||||
toolsVersion: string;
|
||||
}> {
|
||||
const parsedCodeQLURL = new URL(codeqlURL);
|
||||
const searchParams = new URLSearchParams(parsedCodeQLURL.search);
|
||||
|
|
@ -513,20 +518,18 @@ export const downloadCodeQL = async function (
|
|||
authorization,
|
||||
finalHeaders,
|
||||
);
|
||||
const toolsDownloadDurationMs = Math.round(
|
||||
performance.now() - toolsDownloadStart,
|
||||
);
|
||||
const downloadDurationMs = Math.round(performance.now() - toolsDownloadStart);
|
||||
|
||||
logger.debug(
|
||||
`Finished downloading CodeQL bundle to ${archivedBundlePath} (${toolsDownloadDurationMs} ms).`,
|
||||
`Finished downloading CodeQL bundle to ${archivedBundlePath} (${downloadDurationMs} ms).`,
|
||||
);
|
||||
|
||||
logger.debug("Extracting CodeQL bundle.");
|
||||
const extractionStart = performance.now();
|
||||
const extractedBundlePath = await toolcache.extractTar(archivedBundlePath);
|
||||
const extractionMs = Math.round(performance.now() - extractionStart);
|
||||
const extractionDurationMs = Math.round(performance.now() - extractionStart);
|
||||
logger.debug(
|
||||
`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionMs} ms).`,
|
||||
`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionDurationMs} ms).`,
|
||||
);
|
||||
await cleanUpGlob(archivedBundlePath, "CodeQL bundle archive", logger);
|
||||
|
||||
|
|
@ -539,9 +542,12 @@ export const downloadCodeQL = async function (
|
|||
`URL ${codeqlURL}.`,
|
||||
);
|
||||
return {
|
||||
toolsVersion: maybeCliVersion ?? "unknown",
|
||||
codeqlFolder: extractedBundlePath,
|
||||
toolsDownloadDurationMs,
|
||||
statusReport: {
|
||||
downloadDurationMs,
|
||||
extractionDurationMs,
|
||||
},
|
||||
toolsVersion: maybeCliVersion ?? "unknown",
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -567,9 +573,12 @@ export const downloadCodeQL = async function (
|
|||
}
|
||||
|
||||
return {
|
||||
toolsVersion: maybeCliVersion ?? toolcacheVersion,
|
||||
codeqlFolder: toolcachedBundlePath,
|
||||
toolsDownloadDurationMs,
|
||||
statusReport: {
|
||||
downloadDurationMs,
|
||||
extractionDurationMs,
|
||||
},
|
||||
toolsVersion: maybeCliVersion ?? toolcacheVersion,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -632,7 +641,7 @@ export async function setupCodeQLBundle(
|
|||
logger: Logger,
|
||||
): Promise<{
|
||||
codeqlFolder: string;
|
||||
toolsDownloadDurationMs?: number;
|
||||
toolsDownloadStatusReport?: ToolsDownloadStatusReport;
|
||||
toolsSource: ToolsSource;
|
||||
toolsVersion: string;
|
||||
}> {
|
||||
|
|
@ -646,7 +655,7 @@ export async function setupCodeQLBundle(
|
|||
|
||||
let codeqlFolder: string;
|
||||
let toolsVersion = source.toolsVersion;
|
||||
let toolsDownloadDurationMs: number | undefined;
|
||||
let toolsDownloadStatusReport: ToolsDownloadStatusReport | undefined;
|
||||
let toolsSource: ToolsSource;
|
||||
switch (source.sourceType) {
|
||||
case "local":
|
||||
|
|
@ -669,14 +678,14 @@ export async function setupCodeQLBundle(
|
|||
);
|
||||
toolsVersion = result.toolsVersion;
|
||||
codeqlFolder = result.codeqlFolder;
|
||||
toolsDownloadDurationMs = result.toolsDownloadDurationMs;
|
||||
toolsDownloadStatusReport = result.statusReport;
|
||||
toolsSource = ToolsSource.Download;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
util.assertNever(source);
|
||||
}
|
||||
return { codeqlFolder, toolsDownloadDurationMs, toolsSource, toolsVersion };
|
||||
return { codeqlFolder, toolsDownloadStatusReport, toolsSource, toolsVersion };
|
||||
}
|
||||
|
||||
async function cleanUpGlob(glob: string, name: string, logger: Logger) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue