[8.9] [Profiling] fix bug when APM integration is no available (#165809) (#165835)

# Backport

This will backport the following commits from `main` to `8.9`:
- [[Profiling] fix bug when APM integration is no available
(#165809)](https://github.com/elastic/kibana/pull/165809)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Cauê
Marcondes","email":"55978943+cauemarcondes@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-09-06T11:29:42Z","message":"[Profiling]
fix bug when APM integration is no available (#165809)\n\nWe've
identified a buggy scenario when a user has a cluster prior 8.5\r\nand
wants to upgrade to >8.9. In this case, Profiling looks after
the\r\n`elastic-cloud-apm` integration to see if Profiling had been
enabled\r\npreviously. But for the versions before 8.5 this integration
did not\r\nexist under this name causing the set up to crash.\r\n\r\nI
fixed the issue by catching the exception and returning that
profiling\r\nis not enabled on the apm server, as it's not
installed.\r\n\r\nBefore:\r\n```\r\nError: Saved object
[ingest-package-policies/elastic-cloud-apm] not found\r\n at
Function.createGenericNotFoundError
(saved_objects_error_helpers.ts:258:28)\r\n at performGet
(get.ts:80:36)\r\n at processTicksAndRejections
(node:internal/process/task_queues:95:5)\r\n at
SavedObjectsRepository.get (repository.ts:370:12)\r\n at
SavedObjectsClient.get (saved_objects_client.ts:119:12)\r\n at
PackagePolicyClientImpl.get (package_policy.ts:495:29)\r\n at
validateProfilingInApmPackagePolicy (fleet_policies.ts:193:23)\r\n at
async Promise.all (index 5)\r\n at setup.ts:99:31\r\n at Router.handle
(router.ts:212:30)\r\n at handler (router.ts:162:13)\r\n at
exports.Manager.execute
(/Users/caue.marcondes/elastic/other_kibana/node_modules/@hapi/hapi/lib\r\n```\r\n\r\nAfter:\r\n```\r\n{\r\n
\"has_setup\": false,\r\n \"has_data\": false,\r\n \"pre_8_9_1_data\":
false\r\n}\r\n```\r\n\r\n---------\r\n\r\nCo-authored-by: Francesco
Gualazzi
<inge4pres@users.noreply.github.com>","sha":"a00e5e378800d0eda047b59228a48b816541e132","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["backport","release_note:skip","ci:build-cloud-image","v8.10.0","v8.11.0","v8.9.3"],"number":165809,"url":"https://github.com/elastic/kibana/pull/165809","mergeCommit":{"message":"[Profiling]
fix bug when APM integration is no available (#165809)\n\nWe've
identified a buggy scenario when a user has a cluster prior 8.5\r\nand
wants to upgrade to >8.9. In this case, Profiling looks after
the\r\n`elastic-cloud-apm` integration to see if Profiling had been
enabled\r\npreviously. But for the versions before 8.5 this integration
did not\r\nexist under this name causing the set up to crash.\r\n\r\nI
fixed the issue by catching the exception and returning that
profiling\r\nis not enabled on the apm server, as it's not
installed.\r\n\r\nBefore:\r\n```\r\nError: Saved object
[ingest-package-policies/elastic-cloud-apm] not found\r\n at
Function.createGenericNotFoundError
(saved_objects_error_helpers.ts:258:28)\r\n at performGet
(get.ts:80:36)\r\n at processTicksAndRejections
(node:internal/process/task_queues:95:5)\r\n at
SavedObjectsRepository.get (repository.ts:370:12)\r\n at
SavedObjectsClient.get (saved_objects_client.ts:119:12)\r\n at
PackagePolicyClientImpl.get (package_policy.ts:495:29)\r\n at
validateProfilingInApmPackagePolicy (fleet_policies.ts:193:23)\r\n at
async Promise.all (index 5)\r\n at setup.ts:99:31\r\n at Router.handle
(router.ts:212:30)\r\n at handler (router.ts:162:13)\r\n at
exports.Manager.execute
(/Users/caue.marcondes/elastic/other_kibana/node_modules/@hapi/hapi/lib\r\n```\r\n\r\nAfter:\r\n```\r\n{\r\n
\"has_setup\": false,\r\n \"has_data\": false,\r\n \"pre_8_9_1_data\":
false\r\n}\r\n```\r\n\r\n---------\r\n\r\nCo-authored-by: Francesco
Gualazzi
<inge4pres@users.noreply.github.com>","sha":"a00e5e378800d0eda047b59228a48b816541e132"}},"sourceBranch":"main","suggestedTargetBranches":["8.10","8.9"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/165809","number":165809,"mergeCommit":{"message":"[Profiling]
fix bug when APM integration is no available (#165809)\n\nWe've
identified a buggy scenario when a user has a cluster prior 8.5\r\nand
wants to upgrade to >8.9. In this case, Profiling looks after
the\r\n`elastic-cloud-apm` integration to see if Profiling had been
enabled\r\npreviously. But for the versions before 8.5 this integration
did not\r\nexist under this name causing the set up to crash.\r\n\r\nI
fixed the issue by catching the exception and returning that
profiling\r\nis not enabled on the apm server, as it's not
installed.\r\n\r\nBefore:\r\n```\r\nError: Saved object
[ingest-package-policies/elastic-cloud-apm] not found\r\n at
Function.createGenericNotFoundError
(saved_objects_error_helpers.ts:258:28)\r\n at performGet
(get.ts:80:36)\r\n at processTicksAndRejections
(node:internal/process/task_queues:95:5)\r\n at
SavedObjectsRepository.get (repository.ts:370:12)\r\n at
SavedObjectsClient.get (saved_objects_client.ts:119:12)\r\n at
PackagePolicyClientImpl.get (package_policy.ts:495:29)\r\n at
validateProfilingInApmPackagePolicy (fleet_policies.ts:193:23)\r\n at
async Promise.all (index 5)\r\n at setup.ts:99:31\r\n at Router.handle
(router.ts:212:30)\r\n at handler (router.ts:162:13)\r\n at
exports.Manager.execute
(/Users/caue.marcondes/elastic/other_kibana/node_modules/@hapi/hapi/lib\r\n```\r\n\r\nAfter:\r\n```\r\n{\r\n
\"has_setup\": false,\r\n \"has_data\": false,\r\n \"pre_8_9_1_data\":
false\r\n}\r\n```\r\n\r\n---------\r\n\r\nCo-authored-by: Francesco
Gualazzi
<inge4pres@users.noreply.github.com>","sha":"a00e5e378800d0eda047b59228a48b816541e132"}},{"branch":"8.9","label":"v8.9.3","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Cauê Marcondes <55978943+cauemarcondes@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2023-09-06 08:47:19 -04:00 committed by GitHub
parent e813730f26
commit da60b1cb7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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({