Add telemetry for TRAP caching

This commit is contained in:
Edoardo Pirovano 2022-08-15 14:44:43 +01:00
parent ca10a6d552
commit 4139682b64
No known key found for this signature in database
GPG key ID: 047556B5D93FFE28
63 changed files with 1195 additions and 126 deletions

22
lib/analyze-action.js generated
View file

@ -35,7 +35,7 @@ const upload_lib = __importStar(require("./upload-lib"));
const util = __importStar(require("./util"));
// eslint-disable-next-line import/no-commonjs
const pkg = require("../package.json");
async function sendStatusReport(startedAt, config, stats, error) {
async function sendStatusReport(startedAt, config, stats, error, trapCacheUploadTime, didUploadTrapCaches) {
const status = actionsUtil.getActionsStatus(error, stats === null || stats === void 0 ? void 0 : stats.analyze_failure_language);
const statusReportBase = await actionsUtil.createStatusReportBase("finish", status, startedAt, error === null || error === void 0 ? void 0 : error.message, error === null || error === void 0 ? void 0 : error.stack);
const statusReport = {
@ -46,6 +46,10 @@ async function sendStatusReport(startedAt, config, stats, error) {
}
: {}),
...(stats || {}),
trap_cache_upload_duration_ms: trapCacheUploadTime || 0,
trap_cache_upload_size_bytes: config && didUploadTrapCaches
? await (0, trap_caching_1.getTotalCacheSize)(config.trapCaches)
: 0,
};
await actionsUtil.sendStatusReport(statusReport);
}
@ -55,6 +59,8 @@ async function run() {
let uploadResult = undefined;
let runStats = undefined;
let config = undefined;
let trapCacheUploadTime = undefined;
let didUploadTrapCaches = false;
util.initializeEnvironment(util.Mode.actions, pkg.version);
await util.checkActionVersion(pkg.version);
try {
@ -100,8 +106,10 @@ async function run() {
// Possibly upload the database bundles for remote queries
await (0, database_upload_1.uploadDatabases)(repositoryNwo, config, apiDetails, logger);
// Possibly upload the TRAP caches for later re-use
const trapCacheUploadStartTime = Date.now();
const codeql = await (0, codeql_1.getCodeQL)(config.codeQLCmd);
await (0, trap_caching_1.uploadTrapCaches)(codeql, config, logger);
trapCacheUploadTime = Date.now() - trapCacheUploadStartTime;
didUploadTrapCaches = await (0, trap_caching_1.uploadTrapCaches)(codeql, config, logger);
// We don't upload results in test mode, so don't wait for processing
if (util.isInTestMode()) {
core.debug("In test mode. Waiting for processing is disabled.");
@ -117,10 +125,10 @@ async function run() {
console.log(error);
if (error instanceof analyze_1.CodeQLAnalysisError) {
const stats = { ...error.queriesStatusReport };
await sendStatusReport(startedAt, config, stats, error);
await sendStatusReport(startedAt, config, stats, error, trapCacheUploadTime, didUploadTrapCaches);
}
else {
await sendStatusReport(startedAt, config, undefined, error);
await sendStatusReport(startedAt, config, undefined, error, trapCacheUploadTime, didUploadTrapCaches);
}
return;
}
@ -128,13 +136,13 @@ async function run() {
await sendStatusReport(startedAt, config, {
...runStats,
...uploadResult.statusReport,
});
}, undefined, trapCacheUploadTime, didUploadTrapCaches);
}
else if (runStats) {
await sendStatusReport(startedAt, config, { ...runStats });
await sendStatusReport(startedAt, config, { ...runStats }, undefined, trapCacheUploadTime, didUploadTrapCaches);
}
else {
await sendStatusReport(startedAt, config, undefined);
await sendStatusReport(startedAt, config, undefined, undefined, trapCacheUploadTime, didUploadTrapCaches);
}
}
exports.runPromise = run();