From dd853998daf2b7064e9d044cff5e6a5e77c69728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20Haro?= Date: Mon, 11 Jan 2021 14:27:41 +0000 Subject: [PATCH] [Application Usage] Use `Promise.allSettled` during rollups (#87675) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../server/collectors/application_usage/rollups.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/plugins/kibana_usage_collection/server/collectors/application_usage/rollups.ts b/src/plugins/kibana_usage_collection/server/collectors/application_usage/rollups.ts index 48e9068eeda7a..0dc205675bd30 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/application_usage/rollups.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/application_usage/rollups.ts @@ -96,11 +96,22 @@ export async function rollDailyData(logger: Logger, savedObjectsClient?: ISavedO })), { overwrite: true } ); - await Promise.all( + const promiseStatuses = await Promise.allSettled( rawApplicationUsageTransactional.map( ({ id }) => savedObjectsClient.delete(SAVED_OBJECTS_TRANSACTIONAL_TYPE, id) // There is no bulkDelete :( ) ); + const rejectedPromises = promiseStatuses.filter( + (settledResult): settledResult is PromiseRejectedResult => + settledResult.status === 'rejected' + ); + if (rejectedPromises.length > 0) { + throw new Error( + `Failed to delete some items in ${SAVED_OBJECTS_TRANSACTIONAL_TYPE}: ${JSON.stringify( + rejectedPromises.map(({ reason }) => reason) + )}` + ); + } } } while (toCreate.size > 0); } catch (err) {