From ddc1ba3074d21425a34baa7895999e5cd62a2b17 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 6 Sep 2023 08:47:29 -0400 Subject: [PATCH] [8.10] [Profiling] fix bug when APM integration is no available (#165809) (#165833) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Backport This will backport the following commits from `main` to `8.10`: - [[Profiling] fix bug when APM integration is no available (#165809)](https://github.com/elastic/kibana/pull/165809) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: CauĂȘ Marcondes <55978943+cauemarcondes@users.noreply.github.com> --- .../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..ccba170b5fed9 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 integration is not available ignore the error and return as profiling is not enabled on the integration + return { + policies: { apm: { profilingEnabled: false } }, + }; + } } export async function removeProfilingFromApmPackagePolicy({