Skip to content

Commit 6f8864c

Browse files
committed
Address review comments
1 parent e90a71a commit 6f8864c

3 files changed

Lines changed: 105 additions & 62 deletions

File tree

lib/entry-points.js

Lines changed: 24 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/database-upload.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,48 @@ test.serial("Does not measure clear cleanup size in debug mode", async (t) => {
481481
t.is(results[0].clear_cleanup_measurement_duration_ms, undefined);
482482
});
483483
});
484+
485+
test.serial(
486+
"Does not record a clear cleanup duration when the clear cleanup fails",
487+
async (t) => {
488+
await withTmpDir(async (tmpDir) => {
489+
setupActionsVars(tmpDir, tmpDir);
490+
sinon
491+
.stub(actionsUtil, "getRequiredInput")
492+
.withArgs("upload-database")
493+
.returns("true");
494+
sinon.stub(gitUtils, "isAnalyzingDefaultBranch").resolves(true);
495+
496+
await mockHttpRequests(201);
497+
498+
const codeql = createStubCodeQL({
499+
async databaseCleanupCluster(_config, cleanupLevel) {
500+
if (cleanupLevel === CleanupLevel.Clear) {
501+
throw new Error("clear cleanup failed");
502+
}
503+
},
504+
async databaseBundle(_databasePath, outputFilePath) {
505+
fs.writeFileSync(outputFilePath, "x".repeat(100));
506+
},
507+
});
508+
509+
const config = getTestConfig(tmpDir);
510+
config.overlayDatabaseMode = OverlayDatabaseMode.OverlayBase;
511+
512+
const results = await cleanupAndUploadDatabases(
513+
testRepoName,
514+
codeql,
515+
config,
516+
testApiDetails,
517+
createFeatures([Feature.UploadOverlayDbToApi]),
518+
getRecordingLogger([]),
519+
);
520+
521+
// When the `clear` cleanup fails, no size is measured, so we should not
522+
// report a measurement duration either.
523+
t.is(results[0].is_overlay_base, true);
524+
t.is(results[0].clear_cleanup_zipped_size_bytes, undefined);
525+
t.is(results[0].clear_cleanup_measurement_duration_ms, undefined);
526+
});
527+
},
528+
);

src/database-upload.ts

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ export async function cleanupAndUploadDatabases(
189189

190190
/**
191191
* Cleans up the databases at the `clear` cleanup level and records the resulting zipped size for
192-
* each language in `clear_cleanup_zipped_size_bytes`, along with the time spent taking the
193-
* measurement in `clear_cleanup_measurement_duration_ms`.
192+
* each language in `clear_cleanup_zipped_size_bytes`. If the cleanup succeeds, also records the
193+
* time spent taking the measurement in `clear_cleanup_measurement_duration_ms`.
194194
*
195195
* This mutates the entries of `reports` in place. It must run only after all overlay-base uploads
196196
* have completed, since the `clear` cleanup discards overlay data that the uploaded database
@@ -206,46 +206,47 @@ async function recordClearCleanupSizes(
206206
logger: Logger,
207207
): Promise<void> {
208208
const startTime = performance.now();
209+
209210
try {
211+
await codeql.databaseCleanupCluster(config, CleanupLevel.Clear);
212+
} catch (e) {
213+
// The cleanup didn't run, so there are no sizes to measure. Return without recording a
214+
// duration, so that we don't report a measurement duration with no accompanying sizes.
215+
logger.warning(
216+
`Failed to clean up databases at the '${CleanupLevel.Clear}' level for ` +
217+
`size measurement: ${util.getErrorMessage(e)}`,
218+
);
219+
return;
220+
}
221+
222+
for (const language of config.languages) {
223+
const report = reports.find((r) => r.language === language);
224+
if (report === undefined) {
225+
continue;
226+
}
210227
try {
211-
await codeql.databaseCleanupCluster(config, CleanupLevel.Clear);
228+
const bundledDb = await bundleDb(config, language, codeql, language, {
229+
includeDiagnostics: false,
230+
});
231+
report.clear_cleanup_zipped_size_bytes = fs.statSync(bundledDb).size;
232+
logger.debug(
233+
`Database for ${language} is ` +
234+
`${report.clear_cleanup_zipped_size_bytes} bytes zipped at the ` +
235+
`'${CleanupLevel.Clear}' cleanup level ` +
236+
`(vs. ${report.zipped_upload_size_bytes ?? "unknown"} bytes at the ` +
237+
`'${CleanupLevel.Overlay}' level).`,
238+
);
212239
} catch (e) {
213240
logger.warning(
214-
`Failed to clean up databases at the '${CleanupLevel.Clear}' level for ` +
215-
`size measurement: ${util.getErrorMessage(e)}`,
241+
`Failed to measure the '${CleanupLevel.Clear}' cleanup database size ` +
242+
`for ${language}: ${util.getErrorMessage(e)}`,
216243
);
217-
return;
218244
}
245+
}
219246

220-
for (const language of config.languages) {
221-
const report = reports.find((r) => r.language === language);
222-
if (report === undefined) {
223-
continue;
224-
}
225-
try {
226-
const bundledDb = await bundleDb(config, language, codeql, language, {
227-
includeDiagnostics: false,
228-
});
229-
report.clear_cleanup_zipped_size_bytes = fs.statSync(bundledDb).size;
230-
logger.debug(
231-
`Database for ${language} is ` +
232-
`${report.clear_cleanup_zipped_size_bytes} bytes zipped at the ` +
233-
`'${CleanupLevel.Clear}' cleanup level ` +
234-
`(vs. ${report.zipped_upload_size_bytes} bytes at the ` +
235-
`'${CleanupLevel.Overlay}' level).`,
236-
);
237-
} catch (e) {
238-
logger.warning(
239-
`Failed to measure the '${CleanupLevel.Clear}' cleanup database size ` +
240-
`for ${language}: ${util.getErrorMessage(e)}`,
241-
);
242-
}
243-
}
244-
} finally {
245-
const durationMs = performance.now() - startTime;
246-
for (const report of reports) {
247-
report.clear_cleanup_measurement_duration_ms = durationMs;
248-
}
247+
const durationMs = performance.now() - startTime;
248+
for (const report of reports) {
249+
report.clear_cleanup_measurement_duration_ms = durationMs;
249250
}
250251
}
251252

0 commit comments

Comments
 (0)