From cb646e0e069e5d6ffff41da9f012840968c90fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Marcondes?= <55978943+cauemarcondes@users.noreply.github.com> Date: Mon, 25 Sep 2023 16:52:10 +0100 Subject: [PATCH] [Profiling] Fix set up process 8.10 (#167068) So clients reported that they got stuck in the set up screen In the Universal Profling UI. And when the set up button was clicked an error happened: ``` An integration policy with the name elastic-universal-profiling-collector already exists. Please rename it or choose a different name. ``` This happens because when we were checking if the Collector and Symbolizer integrations were installed we weren't taking into consideration that the Fleet API is paginated. So if neither integration was available on the first page we just assumed the Profiling wasn't set up. This PR fixes it by adding a kuery filter in the Fleet API call to only look for out integrations. So we don't need to worry about paginating. Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../plugins/profiling/server/lib/setup/fleet_policies.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 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 ccba170b5fed9e..e49dc4d066f09f 100644 --- a/x-pack/plugins/profiling/server/lib/setup/fleet_policies.ts +++ b/x-pack/plugins/profiling/server/lib/setup/fleet_policies.ts @@ -9,6 +9,7 @@ import { SavedObjectsClientContract } from '@kbn/core/server'; import { PackagePolicyClient } from '@kbn/fleet-plugin/server'; import { fetchFindLatestPackageOrThrow } from '@kbn/fleet-plugin/server/services/epm/registry'; import { omit } from 'lodash'; +import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common'; import { PackageInputType } from '../..'; import { PartialSetupState } from '../../../common/setup'; import { ELASTIC_CLOUD_APM_POLICY, getApmPolicy } from './get_apm_policy'; @@ -27,8 +28,10 @@ async function getPackagePolicy({ soClient: SavedObjectsClientContract; packageName: string; }) { - const packagePolicies = await packagePolicyClient.list(soClient, {}); - return packagePolicies.items.find((pkg) => pkg.name === packageName); + const packagePolicies = await packagePolicyClient.list(soClient, { + kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.name:${packageName}`, + }); + return packagePolicies.items[0]; } export async function getCollectorPolicy({