Repository navigation
[Fleet] Fix bulk action dropdown - #166475
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
|
@elasticmachine merge upstream |
|
Pinging @elastic/fleet (Team:Fleet) |
joshdover
left a comment
There was a problem hiding this comment.
Is there a test here that reproduces the bug and would fail if the code changes weren't present? It wasn't obvious to me which test covers this scenario
| showInactive, | ||
| }), | ||
| ]); | ||
| const [ |
There was a problem hiding this comment.
This useCallback hook is getting really big - should we extract this into a dedicated hook that can easily be tested in isolation? I worry that we don't have much coverage on this logic simply becuase we have to test the whole component.
| const props: any = { | ||
| totalAgents: 10, | ||
| totalAgentsPaginated: 10, | ||
| totalInactiveAgentsPaginated: 0, |
There was a problem hiding this comment.
What do the paginated variables represent? It would be good to add some explaining comments why we need totalInactiveAgents and totalInactiveAgentsPaginated as separate vars.
There was a problem hiding this comment.
I agree the naming is somewhat cumbersome, this is because there was a confusion about what "total" meant: in the current implementation, totalAgents meant all agents on the page (paginated API call) while totalInactiveAgents meant all inactive agents as it was obtained from getAgentStatus. This confusion caused the bug.
We need to know how many inactive agents there are on the page (so totalInactiveAgentsPaginated) for the Actions menu logic.
As for totalInactiveAgents, it is actually used by the AgentStatusFilter component as part of logic to determine whether there are some newly inactive agents. I had a look at it, but it looks to me like it does rely on the total number of inactive agents.
WDYT? Could there be a way to make the above simpler or clearer?
There was a problem hiding this comment.
Thanks for the explanation, it helps.
I think then we could make the naming clearer, what about renaming totalAgents to totalAgentsOnCurrentPage and totalInactiveAgentsPaginated to inactiveAgentsOnCurrentPage?
|
Hey @juliaElastic - thanks for your question about paginated variables, as I was refactoring the variable names I found out that my understanding hadn't been completely correct. I've made new changes with hopefully clearer naming. In the agent list root page (
I am not completely happy with the data fetching that file in the current state. As Josh pointed out, it is getting very long, plus I am concerned that the additional fetching of managed agents data is not implemented in the most efficient way. I might require a few pointers in order to sort that out. |
|
@elasticmachine merge upstream |
|
@elasticmachine merge upstream |
|
@elasticmachine merge upstream |
|
@elastic/fleet I was checking that the tests cover what we want and I need to clarify the following question: the logic for the number of agents considered for bulk actions is different between manual and query modes. Is this expected? Note that this is existing logic. Edit: found a mention that Details:
|
|
Per conversation with @jlind23 - we'll address the above question separately. |
Is there an extra check/filter that excludes inactive agents in this case? |
| showInactive ? totalInactiveAgentsResponse.data.results.inactive || 0 : 0 | ||
| ); | ||
|
|
||
| const managedAgentPolicies = managedAgentPoliciesResponse.data?.items ?? []; |
There was a problem hiding this comment.
should we add more unit tests on the logic here?
juliaElastic
left a comment
There was a problem hiding this comment.
LGTM, thanks for the changes.
💛 Build succeeded, but was flaky
Failed CI Steps
Test Failures
Metrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: |
|
Thanks @juliaElastic for reviewing! I'll open a separate issue for the inactive agents question, I agree it should be consistent. Regarding unit testing on managed agents, this is tested in children components as it only affects the props the parent is passing down. There is another task on this table coming up (https://github.com/elastic/ingest-dev/issues/1937) which will likely complexify the state, which I think would be a good opportunity to refactor how it is handled. |
|
@jillguyonnet Can we backport this to 8.10.x as well? |
|
@joshdover Ah sorry! Can this be done after merging? |
|
No worries, just wanted to make sure there weren't any technical reasons not to. Yes you can by updating the labels, I went ahead and did it. The automation should pick it up soon. |
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
Closes elastic#164083 Related to elastic/sdh-beats#3759 Related to elastic#157844 This PR addresses two current issues affecting agent selection in Fleet UI: 1. When there are inactive agents that are not listed on the current page and "Select everything on all pages" is clicked, the count of actionable agents is incorrect (cf. [this comment](elastic#164083 (comment)) for details). This can have two consequences: 1. Incorrect and sometimes negative agent count in the "Actions" dropdown. 2. Disabled menu items in the "Actions" dropdown. 2. The "Select everything on all pages button is incorrectly displayed when there are agents on managed policies on the page and there is no pagination (cf. [this comment](elastic#164083 (comment))). (cherry picked from commit 591df70) # Conflicts: # x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/bulk_actions.test.tsx
# Backport This will backport the following commits from `main` to `8.10`: - [[Fleet] Fix bulk action dropdown (#166475)](#166475) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Jill Guyonnet","email":"jill.guyonnet@elastic.co"},"sourceCommit":{"committedDate":"2023-09-26T13:15:08Z","message":"[Fleet] Fix bulk action dropdown (#166475)\n\nCloses https://github.com/elastic/kibana/issues/164083\r\nRelated to https://github.com/elastic/sdh-beats/issues/3759\r\nRelated to https://github.com/elastic/kibana/issues/157844\r\n\r\nThis PR addresses two current issues affecting agent selection in Fleet\r\nUI:\r\n1. When there are inactive agents that are not listed on the current\r\npage and \"Select everything on all pages\" is clicked, the count of\r\nactionable agents is incorrect (cf. [this\r\ncomment](https://github.com/elastic/kibana/issues/164083#issuecomment-1711780591)\r\nfor details). This can have two consequences:\r\n1. Incorrect and sometimes negative agent count in the \"Actions\"\r\ndropdown.\r\n 2. Disabled menu items in the \"Actions\" dropdown.\r\n2. The \"Select everything on all pages button is incorrectly displayed\r\nwhen there are agents on managed policies on the page and there is no\r\npagination (cf. [this\r\ncomment](https://github.com/elastic/kibana/issues/164083#issuecomment-1711781808)).","sha":"591df706da23663c898247f23faa00c015c2d26c","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","backport:prev-minor","v8.11.0"],"number":166475,"url":"https://github.com/elastic/kibana/pull/166475","mergeCommit":{"message":"[Fleet] Fix bulk action dropdown (#166475)\n\nCloses https://github.com/elastic/kibana/issues/164083\r\nRelated to https://github.com/elastic/sdh-beats/issues/3759\r\nRelated to https://github.com/elastic/kibana/issues/157844\r\n\r\nThis PR addresses two current issues affecting agent selection in Fleet\r\nUI:\r\n1. When there are inactive agents that are not listed on the current\r\npage and \"Select everything on all pages\" is clicked, the count of\r\nactionable agents is incorrect (cf. [this\r\ncomment](https://github.com/elastic/kibana/issues/164083#issuecomment-1711780591)\r\nfor details). This can have two consequences:\r\n1. Incorrect and sometimes negative agent count in the \"Actions\"\r\ndropdown.\r\n 2. Disabled menu items in the \"Actions\" dropdown.\r\n2. The \"Select everything on all pages button is incorrectly displayed\r\nwhen there are agents on managed policies on the page and there is no\r\npagination (cf. [this\r\ncomment](https://github.com/elastic/kibana/issues/164083#issuecomment-1711781808)).","sha":"591df706da23663c898247f23faa00c015c2d26c"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/166475","number":166475,"mergeCommit":{"message":"[Fleet] Fix bulk action dropdown (#166475)\n\nCloses https://github.com/elastic/kibana/issues/164083\r\nRelated to https://github.com/elastic/sdh-beats/issues/3759\r\nRelated to https://github.com/elastic/kibana/issues/157844\r\n\r\nThis PR addresses two current issues affecting agent selection in Fleet\r\nUI:\r\n1. When there are inactive agents that are not listed on the current\r\npage and \"Select everything on all pages\" is clicked, the count of\r\nactionable agents is incorrect (cf. [this\r\ncomment](https://github.com/elastic/kibana/issues/164083#issuecomment-1711780591)\r\nfor details). This can have two consequences:\r\n1. Incorrect and sometimes negative agent count in the \"Actions\"\r\ndropdown.\r\n 2. Disabled menu items in the \"Actions\" dropdown.\r\n2. The \"Select everything on all pages button is incorrectly displayed\r\nwhen there are agents on managed policies on the page and there is no\r\npagination (cf. [this\r\ncomment](https://github.com/elastic/kibana/issues/164083#issuecomment-1711781808)).","sha":"591df706da23663c898247f23faa00c015c2d26c"}}]}] BACKPORT-->
Summary
Closes #164083
Related to #157844
This PR addresses two current issues affecting agent selection in Fleet UI:
Testing steps
Reproduce the bug (main branch)
fleet-server-policyid and run the following in Dev Tools:Agent policy 1), enroll 30 agents, have them all inactive except for one. This can be achieved like so:Test the fixes (this branch)
With the above setup:
Additional testing
The following scenarios should be checked as they depend on the area of the code that was amended:
Checklist