Skip to content

Commit

Permalink
[8.x] [Fleet] Fix UI error when agent goes to orphaned state (#207746) (
Browse files Browse the repository at this point in the history
#207836)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Fleet] Fix UI error when agent goes to orphaned state
(#207746)](#207746)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Julia
Bardi","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-22T14:20:03Z","message":"[Fleet]
Fix UI error when agent goes to orphaned state (#207746)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/207017\r\n\r\nIt seems that
when the orphaned agent service is restarted, it briefly\r\nhas a
component state string, instead of array, that's why the error.\r\nThe
fix checks that the components is an array before calling map.\r\n\r\nTo
verify:\r\n1. Enroll an agent to an agent policy with endpoint
integration.\r\n2. Stop agent service so that agent gets into orphaned
state.\r\n3. Now restart the service and observe that the
error\r\n`_hit$_source4.components.map is not a function` no longer
appears.\r\n\r\n<img width=\"1531\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/c9a957d7-a0d3-4831-90f9-a57479193ee0\"\r\n/>\r\n<img
width=\"1530\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/c0aa62f0-708b-463e-9184-01d8641c8f21\"\r\n/>","sha":"9800147681323f95f5e951328f9f56a399796350","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","v9.0.0","backport:prev-minor"],"title":"[Fleet]
Fix UI error when agent goes to orphaned
state","number":207746,"url":"https://github.com/elastic/kibana/pull/207746","mergeCommit":{"message":"[Fleet]
Fix UI error when agent goes to orphaned state (#207746)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/207017\r\n\r\nIt seems that
when the orphaned agent service is restarted, it briefly\r\nhas a
component state string, instead of array, that's why the error.\r\nThe
fix checks that the components is an array before calling map.\r\n\r\nTo
verify:\r\n1. Enroll an agent to an agent policy with endpoint
integration.\r\n2. Stop agent service so that agent gets into orphaned
state.\r\n3. Now restart the service and observe that the
error\r\n`_hit$_source4.components.map is not a function` no longer
appears.\r\n\r\n<img width=\"1531\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/c9a957d7-a0d3-4831-90f9-a57479193ee0\"\r\n/>\r\n<img
width=\"1530\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/c0aa62f0-708b-463e-9184-01d8641c8f21\"\r\n/>","sha":"9800147681323f95f5e951328f9f56a399796350"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/207746","number":207746,"mergeCommit":{"message":"[Fleet]
Fix UI error when agent goes to orphaned state (#207746)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/207017\r\n\r\nIt seems that
when the orphaned agent service is restarted, it briefly\r\nhas a
component state string, instead of array, that's why the error.\r\nThe
fix checks that the components is an array before calling map.\r\n\r\nTo
verify:\r\n1. Enroll an agent to an agent policy with endpoint
integration.\r\n2. Stop agent service so that agent gets into orphaned
state.\r\n3. Now restart the service and observe that the
error\r\n`_hit$_source4.components.map is not a function` no longer
appears.\r\n\r\n<img width=\"1531\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/c9a957d7-a0d3-4831-90f9-a57479193ee0\"\r\n/>\r\n<img
width=\"1530\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/c0aa62f0-708b-463e-9184-01d8641c8f21\"\r\n/>","sha":"9800147681323f95f5e951328f9f56a399796350"}}]}]
BACKPORT-->

Co-authored-by: Julia Bardi <[email protected]>
  • Loading branch information
kibanamachine and juliaElastic authored Jan 22, 2025
1 parent a46d990 commit bc65a48
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function searchHitToAgent(
return acc;
}, {} as OutputMap)
: undefined;
const components: FleetServerAgentComponent[] | undefined = hit._source?.components
const components: FleetServerAgentComponent[] | undefined = Array.isArray(hit._source?.components)
? hit._source?.components.map((component) => ({
id: component.id,
type: component.type,
Expand Down

0 comments on commit bc65a48

Please sign in to comment.