From 6e4560677d11f65ce9f2c4b0588a789ea25b684f Mon Sep 17 00:00:00 2001 From: Caue Marcondes Date: Wed, 6 Sep 2023 09:51:43 +0100 Subject: [PATCH] [Profiling] fix bug when APM server is no available --- .../server/lib/setup/fleet_policies.ts | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/profiling/server/lib/setup/fleet_policies.ts b/x-pack/plugins/profiling/server/lib/setup/fleet_policies.ts index 8ffe13695cddb..f72f8a4ed87e5 100644 --- a/x-pack/plugins/profiling/server/lib/setup/fleet_policies.ts +++ b/x-pack/plugins/profiling/server/lib/setup/fleet_policies.ts @@ -189,17 +189,23 @@ export async function validateProfilingInApmPackagePolicy({ soClient, packagePolicyClient, }: ProfilingSetupOptions): Promise { - const apmPolicy = await getApmPolicy({ packagePolicyClient, soClient }); - - return { - policies: { - apm: { - profilingEnabled: !!( - apmPolicy && apmPolicy?.inputs[0].config?.['apm-server'].value?.profiling - ), + try { + const apmPolicy = await getApmPolicy({ packagePolicyClient, soClient }); + return { + policies: { + apm: { + profilingEnabled: !!( + apmPolicy && apmPolicy?.inputs[0].config?.['apm-server'].value?.profiling + ), + }, }, - }, - }; + }; + } catch (e) { + // In case apm server is not available ignore the error and return as profiling is not enabled on apm + return { + policies: { apm: { profilingEnabled: false } }, + }; + } } export async function removeProfilingFromApmPackagePolicy({