Skip to content

[Fleet] Fix bulk actions incorrectly selecting agents with namespaces filter#224036

Merged
juliaElastic merged 5 commits intoelastic:mainfrom
juliaElastic:fix-namespaces-filter
Jun 19, 2025
Merged

[Fleet] Fix bulk actions incorrectly selecting agents with namespaces filter#224036
juliaElastic merged 5 commits intoelastic:mainfrom
juliaElastic:fix-namespaces-filter

Conversation

@juliaElastic
Copy link
Contributor

@juliaElastic juliaElastic commented Jun 16, 2025

Summary

Fix bulk actions incorrectly selecting agents with namespaces filter.
The namespaces filter namespaces:(default) or not namespaces:* was introduced with space awareness feature, it is incorrectly concatenated with other filters, ending up selecting all agents.

To verify:

  • Enroll Fleet Server and 10 agents with horde
  • Search on horde agents by filtering on eh*
  • Select rows per page to be 5
  • Select all agents on all pages (should be 10)
  • Click on bulk unenroll action
  • Verify that only the selected 10 agents are unenrolled
  • Previously with the bug, all agents were unenrolled, including Fleet Server

Filters included in the search:
[ "(namespaces:(default) or not namespaces:*) AND (eh*) and (status:online or (status:error or status:degraded) or status:orphaned or (status:updating or status:unenrolling or status:enrolling) or status:offline)", "NOT status:unenrolled" ]

image image

Checklist

@juliaElastic juliaElastic self-assigned this Jun 16, 2025
@juliaElastic juliaElastic requested a review from a team as a code owner June 16, 2025 09:47
@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Jun 16, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

}
if (spaceId === DEFAULT_SPACE_ID) {
return [`namespaces:"${DEFAULT_SPACE_ID}" or not namespaces:*`];
return [`(namespaces:"${DEFAULT_SPACE_ID}" or not namespaces:*)`];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it makes sense to extract these queries to a constant and put it in a common place

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, done

}
return namespace === DEFAULT_NAMESPACE_STRING
? `namespaces:(${DEFAULT_NAMESPACE_STRING}) or not namespaces:*`
? `(namespaces:(${DEFAULT_NAMESPACE_STRING}) or not namespaces:*)`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that DEFAULT_NAMESPACE_STRING here and DEFAULT_SPACE_ID above are the same, what do you think of using only one of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@juliaElastic juliaElastic requested a review from criamico June 19, 2025 08:23
Copy link
Contributor

@criamico criamico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes! LGTM 🚀

@juliaElastic juliaElastic enabled auto-merge (squash) June 19, 2025 08:37
@elasticmachine
Copy link
Contributor

⏳ Build in-progress, with failures

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #11 / agentsKueryNamespaceFilter with isSpaceAwarenessEnabled returning true returns a kuery for the default space
  • [job] [logs] Jest Tests #11 / agentsKueryNamespaceFilter with isSpaceAwarenessEnabled returning true returns a kuery for the default space
  • [job] [logs] Jest Tests #11 / update_agent_tags with isSpaceAwarenessEnabled return true should add namespace filter to kuery in the default space
  • [job] [logs] Jest Tests #11 / update_agent_tags with isSpaceAwarenessEnabled return true should add namespace filter to kuery in the default space

History

cc @juliaElastic

@juliaElastic juliaElastic merged commit 4ec50a0 into elastic:main Jun 19, 2025
10 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 9.0

https://github.com/elastic/kibana/actions/runs/15758537152

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
9.0 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 224036

Questions ?

Please refer to the Backport tool documentation

juliaElastic added a commit to juliaElastic/kibana that referenced this pull request Jun 19, 2025
… filter (elastic#224036)

Fix bulk actions incorrectly selecting agents with namespaces filter.
The namespaces filter `namespaces:(default) or not namespaces:*` was
introduced with space awareness feature, it is incorrectly concatenated
with other filters, ending up selecting all agents.

To verify:
- Enroll Fleet Server and 10 agents with horde
- Search on horde agents by filtering on `eh*`
- Select rows per page to be 5
- Select all agents on all pages (should be 10)
- Click on bulk unenroll action
- Verify that only the selected 10 agents are unenrolled
- Previously with the bug, all agents were unenrolled, including Fleet
Server

Filters included in the search:
`[
"(namespaces:(default) or not namespaces:*) AND (eh*) and (status:online
or (status:error or status:degraded) or status:orphaned or
(status:updating or status:unenrolling or status:enrolling) or
status:offline)",
  "NOT status:unenrolled"
]`

<img width="1412" alt="image"
src="https://github.com/user-attachments/assets/4740f0c7-67ab-41c3-9dd4-0b122ed472aa"
/>
<img width="1278" alt="image"
src="https://github.com/user-attachments/assets/b7944d43-c4a6-42ca-b1c8-c8be78fc40cf"
/>

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 20, 2025
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @juliaElastic

juliaElastic added a commit that referenced this pull request Jun 20, 2025
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 23, 2025
@mistic mistic added the v9.0.4 label Jun 24, 2025
@mistic
Copy link
Contributor

mistic commented Jun 24, 2025

This PR didn't make it into the latest BC for v9.0.3. Updating the labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:fix Team:Fleet Team label for Observability Data Collection Fleet team v9.0.4 v9.1.0

5 participants