@@ -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