From 77a86a16721938276d96d3cf10dbfa90f47c7f3d Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Mon, 25 Jan 2021 11:39:31 +0100 Subject: [PATCH 1/3] clean up Lens usage collector --- .../plugins/lens/server/usage/collectors.ts | 32 +++++-------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/x-pack/plugins/lens/server/usage/collectors.ts b/x-pack/plugins/lens/server/usage/collectors.ts index c32fc0371ed8..59517aba3e3d 100644 --- a/x-pack/plugins/lens/server/usage/collectors.ts +++ b/x-pack/plugins/lens/server/usage/collectors.ts @@ -16,11 +16,6 @@ export function registerLensUsageCollector( usageCollection: UsageCollectionSetup, taskManager: Promise ) { - let isCollectorReady = false; - taskManager.then(() => { - // mark lensUsageCollector as ready to collect when the TaskManager is ready - isCollectorReady = true; - }); const lensUsageCollector = usageCollection.makeUsageCollector({ type: 'lens', async fetch() { @@ -55,7 +50,10 @@ export function registerLensUsageCollector( }; } }, - isReady: () => isCollectorReady, + isReady: async () => { + await taskManager; + return true; + }, schema: lensUsageSchema, }); @@ -69,24 +67,10 @@ function addEvents(prevEvents: Record, newEvents: Record>) { From ac61dcf635969c5527757b60451f36131ad4855a Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 27 Jan 2021 11:59:58 +0100 Subject: [PATCH 2/3] introduce try catch again --- .../plugins/lens/server/usage/collectors.ts | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/lens/server/usage/collectors.ts b/x-pack/plugins/lens/server/usage/collectors.ts index 59517aba3e3d..2ffa4b8dffc4 100644 --- a/x-pack/plugins/lens/server/usage/collectors.ts +++ b/x-pack/plugins/lens/server/usage/collectors.ts @@ -67,10 +67,24 @@ function addEvents(prevEvents: Record, newEvents: Record>) { From 60deb686f73c401668d8d2905eaa13c687f62c6c Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 27 Jan 2021 12:00:41 +0100 Subject: [PATCH 3/3] restore --- x-pack/plugins/lens/server/usage/collectors.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/lens/server/usage/collectors.ts b/x-pack/plugins/lens/server/usage/collectors.ts index 2ffa4b8dffc4..71a699aadb86 100644 --- a/x-pack/plugins/lens/server/usage/collectors.ts +++ b/x-pack/plugins/lens/server/usage/collectors.ts @@ -75,10 +75,10 @@ async function getLatestTaskState(taskManager: TaskManagerStartContract) { } catch (err) { const errMessage = err && err.message ? err.message : err.toString(); /* - The usage service WILL to try to fetch from this collector before the task manager has been initialized, because the - task manager has to wait for all plugins to initialize first. It's fine to ignore it as next time around it will be - initialized (or it will throw a different type of error) - */ + The usage service WILL to try to fetch from this collector before the task manager has been initialized, because the + task manager has to wait for all plugins to initialize first. It's fine to ignore it as next time around it will be + initialized (or it will throw a different type of error) + */ if (!errMessage.includes('NotInitialized')) { throw err; }