From 6e4560677d11f65ce9f2c4b0588a789ea25b684f Mon Sep 17 00:00:00 2001 From: Caue Marcondes Date: Wed, 6 Sep 2023 09:51:43 +0100 Subject: [PATCH 1/2] [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({ From b6896023d60e9e61bc012d1c03c50e9645a68827 Mon Sep 17 00:00:00 2001 From: Caue Marcondes Date: Wed, 6 Sep 2023 09:58:25 +0100 Subject: [PATCH 2/2] fix comment --- x-pack/plugins/profiling/server/lib/setup/fleet_policies.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f72f8a4ed87e5..ccba170b5fed9 100644 --- a/x-pack/plugins/profiling/server/lib/setup/fleet_policies.ts +++ b/x-pack/plugins/profiling/server/lib/setup/fleet_policies.ts @@ -201,7 +201,7 @@ export async function validateProfilingInApmPackagePolicy({ }, }; } catch (e) { - // In case apm server is not available ignore the error and return as profiling is not enabled on apm + // In case apm integration is not available ignore the error and return as profiling is not enabled on the integration return { policies: { apm: { profilingEnabled: false } }, };