Add telemetry for TRAP cache cleanup

This commit is contained in:
Henry Mercer 2024-05-22 12:38:40 +01:00
parent 59af9fc5ab
commit 4f2b1826e9
6 changed files with 57 additions and 25 deletions

18
lib/trap-caching.js generated
View file

@ -133,9 +133,13 @@ async function uploadTrapCaches(codeql, config, logger) {
}
exports.uploadTrapCaches = uploadTrapCaches;
async function cleanupTrapCaches(config, logger) {
if (!(await actionsUtil.isAnalyzingDefaultBranch()))
return;
if (!(await actionsUtil.isAnalyzingDefaultBranch())) {
return {
trap_cache_cleanup_skipped_because: "not analyzing default branch",
};
}
try {
let totalBytesCleanedUp = 0;
for (const language of config.languages) {
if (config.trapCaches[language]) {
const cachesToRemove = await getTrapCachesForLanguage(language, logger);
@ -148,12 +152,13 @@ async function cleanupTrapCaches(config, logger) {
logger.debug(`Deleting old TRAP cache (${JSON.stringify(cache)})`);
await apiClient.deleteActionsCache(cache.id);
}
const totalBytesCleanedUp = cachesToRemove.reduce((acc, item) => acc + item.size_in_bytes, 0);
const totalMegabytesCleanedUp = (totalBytesCleanedUp /
(1024 * 1024)).toFixed(2);
logger.info(`Cleaned up ${totalMegabytesCleanedUp} MiB of old TRAP caches for ${language}.`);
const bytesCleanedUp = cachesToRemove.reduce((acc, item) => acc + item.size_in_bytes, 0);
totalBytesCleanedUp += bytesCleanedUp;
const megabytesCleanedUp = (bytesCleanedUp / (1024 * 1024)).toFixed(2);
logger.info(`Cleaned up ${megabytesCleanedUp} MiB of old TRAP caches for ${language}.`);
}
}
return { trap_cache_cleanup_size_bytes: totalBytesCleanedUp };
}
catch (e) {
if ((0, util_1.isHTTPError)(e) && e.status === 403) {
@ -164,6 +169,7 @@ async function cleanupTrapCaches(config, logger) {
else {
logger.info(`Failed to cleanup TRAP caches, continuing. Details: ${e}`);
}
return { trap_cache_cleanup_error: (0, util_1.wrapError)(e).message };
}
}
exports.cleanupTrapCaches = cleanupTrapCaches;