Skip to content

Commit

Permalink
[Profiling] fix bug when APM integration is no available (#165809)
Browse files Browse the repository at this point in the history
We've identified a buggy scenario when a user has a cluster prior 8.5
and wants to upgrade to >8.9. In this case, Profiling looks after the
`elastic-cloud-apm` integration to see if Profiling had been enabled
previously. But for the versions before 8.5 this integration did not
exist under this name causing the set up to crash.

I fixed the issue by catching the exception and returning that profiling
is not enabled on the apm server, as it's not installed.

Before:
```
Error: Saved object [ingest-package-policies/elastic-cloud-apm] not found
    at Function.createGenericNotFoundError (saved_objects_error_helpers.ts:258:28)
    at performGet (get.ts:80:36)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at SavedObjectsRepository.get (repository.ts:370:12)
    at SavedObjectsClient.get (saved_objects_client.ts:119:12)
    at PackagePolicyClientImpl.get (package_policy.ts:495:29)
    at validateProfilingInApmPackagePolicy (fleet_policies.ts:193:23)
    at async Promise.all (index 5)
    at setup.ts:99:31
    at Router.handle (router.ts:212:30)
    at handler (router.ts:162:13)
    at exports.Manager.execute (/Users/caue.marcondes/elastic/other_kibana/node_modules/@hapi/hapi/lib
```

After:
```
{
  "has_setup": false,
  "has_data": false,
  "pre_8_9_1_data": false
}
```

---------

Co-authored-by: Francesco Gualazzi <[email protected]>
  • Loading branch information
cauemarcondes and inge4pres authored Sep 6, 2023
1 parent 015b910 commit a00e5e3
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions x-pack/plugins/profiling/server/lib/setup/fleet_policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,23 @@ export async function validateProfilingInApmPackagePolicy({
soClient,
packagePolicyClient,
}: ProfilingSetupOptions): Promise<PartialSetupState> {
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({
Expand Down

0 comments on commit a00e5e3

Please sign in to comment.