[8.x] [Fleet] Fix agents count in agent list table and add tooltip with correct info (#197834) (#198002)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Fleet] Fix agents count in agent list table and add tooltip with
correct info (#197834)](https://github.com/elastic/kibana/pull/197834)

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

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

<!--BACKPORT [{"author":{"name":"Cristina
Amico","email":"criamico@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-10-28T14:00:00Z","message":"[Fleet]
Fix agents count in agent list table and add tooltip with correct info
(#197834)\n\nFixes
https://github.com/elastic/kibana/issues/195441\r\n\r\n##
Summary\r\nSelection agent count on agent list table gets incorrect when
there are\r\nmultiple hosted agents, especially if they are on inactive
state. In\r\nfact to calculate the selected number of agents we were
getting hosted\r\nagents, but without taking into account the filtering
applied on the\r\npage, i.e. we were always getting all the hosted agent
(inactive too).\r\nThis caused the final calculation to be off.
\r\n\r\nIn this PR I'm fixing
[the\r\nquery](https://github.com/elastic/kibana/pull/197834/files#diff-9707a4b93a96749876e4cf173a0b39cd5a620e311e2652c5ed4b8670ca7e6becR309-R320)\r\nused
to get those agents to take in account the filters and I'm
also\r\nadding a small tooltip that breaks up the number of agents
(selected,\r\ntotal, hosted)\r\n\r\n### Testing\r\n- Make sure to have
many agents, hosted and not in different states\r\n(inactive,
unenrolled)\r\n- To make a hosted agent inactive follow the steps
explained\r\n[here](https://github.com/elastic/kibana/issues/195441)\r\n-
Verify that the selection numbers are correct: select agents on
all\r\npages and hover on the new tooltip shown besides the \"selected
agents\".\r\nThis number should match the number shown on the actions
dropdown\r\n\r\n\r\n### Screenshots\r\n<img width=\"2376\"
alt=\"Screenshot 2024-10-25 at 17 00
44\"\r\nsrc=\"https://github.com/user-attachments/assets/81d2836a-f997-4ccb-a23c-3d2cfbfa62d3\">\r\n<img
width=\"2409\" alt=\"Screenshot 2024-10-25 at 17 00
59\"\r\nsrc=\"c153c491-29a1-481c-a3e3-25bab6412963\r\n\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"079e929a1cfaac103dea4e301c9b697e561ffd17","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","backport:prev-minor"],"title":"[Fleet]
Fix agents count in agent list table and add tooltip with correct
info","number":197834,"url":"https://github.com/elastic/kibana/pull/197834","mergeCommit":{"message":"[Fleet]
Fix agents count in agent list table and add tooltip with correct info
(#197834)\n\nFixes
https://github.com/elastic/kibana/issues/195441\r\n\r\n##
Summary\r\nSelection agent count on agent list table gets incorrect when
there are\r\nmultiple hosted agents, especially if they are on inactive
state. In\r\nfact to calculate the selected number of agents we were
getting hosted\r\nagents, but without taking into account the filtering
applied on the\r\npage, i.e. we were always getting all the hosted agent
(inactive too).\r\nThis caused the final calculation to be off.
\r\n\r\nIn this PR I'm fixing
[the\r\nquery](https://github.com/elastic/kibana/pull/197834/files#diff-9707a4b93a96749876e4cf173a0b39cd5a620e311e2652c5ed4b8670ca7e6becR309-R320)\r\nused
to get those agents to take in account the filters and I'm
also\r\nadding a small tooltip that breaks up the number of agents
(selected,\r\ntotal, hosted)\r\n\r\n### Testing\r\n- Make sure to have
many agents, hosted and not in different states\r\n(inactive,
unenrolled)\r\n- To make a hosted agent inactive follow the steps
explained\r\n[here](https://github.com/elastic/kibana/issues/195441)\r\n-
Verify that the selection numbers are correct: select agents on
all\r\npages and hover on the new tooltip shown besides the \"selected
agents\".\r\nThis number should match the number shown on the actions
dropdown\r\n\r\n\r\n### Screenshots\r\n<img width=\"2376\"
alt=\"Screenshot 2024-10-25 at 17 00
44\"\r\nsrc=\"https://github.com/user-attachments/assets/81d2836a-f997-4ccb-a23c-3d2cfbfa62d3\">\r\n<img
width=\"2409\" alt=\"Screenshot 2024-10-25 at 17 00
59\"\r\nsrc=\"c153c491-29a1-481c-a3e3-25bab6412963\r\n\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"079e929a1cfaac103dea4e301c9b697e561ffd17"}},"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/197834","number":197834,"mergeCommit":{"message":"[Fleet]
Fix agents count in agent list table and add tooltip with correct info
(#197834)\n\nFixes
https://github.com/elastic/kibana/issues/195441\r\n\r\n##
Summary\r\nSelection agent count on agent list table gets incorrect when
there are\r\nmultiple hosted agents, especially if they are on inactive
state. In\r\nfact to calculate the selected number of agents we were
getting hosted\r\nagents, but without taking into account the filtering
applied on the\r\npage, i.e. we were always getting all the hosted agent
(inactive too).\r\nThis caused the final calculation to be off.
\r\n\r\nIn this PR I'm fixing
[the\r\nquery](https://github.com/elastic/kibana/pull/197834/files#diff-9707a4b93a96749876e4cf173a0b39cd5a620e311e2652c5ed4b8670ca7e6becR309-R320)\r\nused
to get those agents to take in account the filters and I'm
also\r\nadding a small tooltip that breaks up the number of agents
(selected,\r\ntotal, hosted)\r\n\r\n### Testing\r\n- Make sure to have
many agents, hosted and not in different states\r\n(inactive,
unenrolled)\r\n- To make a hosted agent inactive follow the steps
explained\r\n[here](https://github.com/elastic/kibana/issues/195441)\r\n-
Verify that the selection numbers are correct: select agents on
all\r\npages and hover on the new tooltip shown besides the \"selected
agents\".\r\nThis number should match the number shown on the actions
dropdown\r\n\r\n\r\n### Screenshots\r\n<img width=\"2376\"
alt=\"Screenshot 2024-10-25 at 17 00
44\"\r\nsrc=\"https://github.com/user-attachments/assets/81d2836a-f997-4ccb-a23c-3d2cfbfa62d3\">\r\n<img
width=\"2409\" alt=\"Screenshot 2024-10-25 at 17 00
59\"\r\nsrc=\"c153c491-29a1-481c-a3e3-25bab6412963\r\n\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"079e929a1cfaac103dea4e301c9b697e561ffd17"}}]}]
BACKPORT-->

Co-authored-by: Cristina Amico <criamico@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2024-10-29 04:45:37 +11:00 committed by GitHub
parent f9c8127c06
commit a01ce27674
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 62 additions and 15 deletions

View file

@ -7,7 +7,7 @@
import React from 'react';
import styled from 'styled-components';
import { EuiFlexGroup, EuiFlexItem, EuiText, EuiButtonEmpty } from '@elastic/eui';
import { EuiFlexGroup, EuiFlexItem, EuiText, EuiButtonEmpty, EuiIconTip } from '@elastic/eui';
import { FormattedMessage, FormattedNumber } from '@kbn/i18n-react';
import { SO_SEARCH_LIMIT } from '../../../../constants';
@ -33,6 +33,7 @@ const Button = styled(EuiButtonEmpty)`
export const AgentsSelectionStatus: React.FunctionComponent<{
totalAgents: number;
totalManagedAgents: number;
selectableAgents: number;
managedAgentsOnCurrentPage: number;
selectionMode: SelectionMode;
@ -41,6 +42,7 @@ export const AgentsSelectionStatus: React.FunctionComponent<{
setSelectedAgents: (agents: Agent[]) => void;
}> = ({
totalAgents,
totalManagedAgents,
selectableAgents,
managedAgentsOnCurrentPage,
selectionMode,
@ -71,11 +73,28 @@ export const AgentsSelectionStatus: React.FunctionComponent<{
}}
/>
) : (
<FormattedMessage
id="xpack.fleet.agentBulkActions.totalAgents"
defaultMessage="Showing {count, plural, one {# agent} other {# agents}}"
values={{ count: totalAgents }}
/>
<>
<FormattedMessage
id="xpack.fleet.agentBulkActions.totalAgents"
defaultMessage="Showing {count, plural, one {# agent} other {# agents}}"
values={{ count: totalAgents }}
/>{' '}
<EuiIconTip
type="iInCircle"
content={
<FormattedMessage
data-test-subj="selectedAgentCountTooltip"
id="xpack.fleet.agentBulkActions.agentsBreakDownTooltip"
defaultMessage=" {totalAgents} total agents: {totalSelected} user-managed agents, {totalManagedAgents} on hosted policies"
values={{
totalAgents,
totalManagedAgents,
totalSelected: totalAgents - totalManagedAgents,
}}
/>
}
/>
</>
)}
</EuiText>
</EuiFlexItem>
@ -96,7 +115,24 @@ export const AgentsSelectionStatus: React.FunctionComponent<{
selectionMode,
count: selectedAgents.length,
}}
/>
/>{' '}
{selectionMode === 'query' && (
<EuiIconTip
type="iInCircle"
content={
<FormattedMessage
data-test-subj="selectedAgentCountTooltip"
id="xpack.fleet.agentBulkActions.agentsSelectedTooltip"
defaultMessage="{totalSelected} user-managed agents selected: {totalAgents} total agents, {totalManagedAgents} on hosted policies. Most actions are only available to user-managed agents."
values={{
totalAgents,
totalManagedAgents,
totalSelected: totalAgents - totalManagedAgents,
}}
/>
}
/>
)}
</EuiText>
</EuiFlexItem>
{showSelectEverything ? (

View file

@ -77,7 +77,7 @@ export const AgentBulkActions: React.FunctionComponent<Props> = ({
const [isRequestDiagnosticsModalOpen, setIsRequestDiagnosticsModalOpen] =
useState<boolean>(false);
// update the query removing the "managed" agents
// update the query removing the "managed" agents in any state (unenrolled, offline, etc)
const selectionQuery = useMemo(() => {
if (totalManagedAgentIds.length) {
const excludedKuery = `${AGENTS_PREFIX}.agent.id : (${totalManagedAgentIds

View file

@ -21,6 +21,7 @@ export const AgentTableHeader: React.FunctionComponent<{
agentStatus?: { [k in SimplifiedAgentStatus]: number };
totalAgents: number;
selectableAgents: number;
totalManagedAgents: number;
managedAgentsOnCurrentPage: number;
selectionMode: SelectionMode;
setSelectionMode: (mode: SelectionMode) => void;
@ -31,6 +32,7 @@ export const AgentTableHeader: React.FunctionComponent<{
}> = ({
agentStatus,
totalAgents,
totalManagedAgents,
selectableAgents,
managedAgentsOnCurrentPage,
selectionMode,
@ -47,6 +49,7 @@ export const AgentTableHeader: React.FunctionComponent<{
<EuiFlexItem grow={false}>
<AgentsSelectionStatus
totalAgents={totalAgents}
totalManagedAgents={totalManagedAgents}
selectableAgents={selectableAgents}
managedAgentsOnCurrentPage={managedAgentsOnCurrentPage}
selectionMode={selectionMode}

View file

@ -306,14 +306,18 @@ export function useFetchAgentsData() {
setTotalManagedAgentIds([]);
setManagedAgentsOnCurrentPage(0);
} else {
// Find all the agents that have managed policies and are not unenrolled
const policiesKuery = managedAgentPolicies
.map((policy) => `policy_id:"${policy.id}"`)
.join(' or ');
// Find all the agents that have managed policies
// to the correct ids we need to build the kuery applying the same filters as the global ones
const managedPoliciesKuery = getKuery({
search,
selectedAgentPolicies: managedAgentPolicies.map((policy) => policy.id),
selectedTags,
selectedStatus,
});
const response = await sendGetAgents({
kuery: `NOT (status:unenrolled) and ${policiesKuery}`,
kuery: `${managedPoliciesKuery}`,
perPage: SO_SEARCH_LIMIT,
showInactive: true,
showInactive,
});
if (response.error) {
throw new Error(response.error.message);
@ -350,7 +354,6 @@ export function useFetchAgentsData() {
fetchDataAsync();
},
[
fullAgentPolicyFecher,
pagination.currentPage,
pagination.pageSize,
kuery,
@ -359,8 +362,12 @@ export function useFetchAgentsData() {
showInactive,
showUpgradeable,
displayAgentMetrics,
fullAgentPolicyFecher,
allTags,
latestAgentActionErrors,
search,
selectedTags,
selectedStatus,
notifications.toasts,
]
);

View file

@ -434,6 +434,7 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
{/* Agent total, bulk actions and status bar */}
<AgentTableHeader
totalAgents={nAgentsInTable}
totalManagedAgents={totalManagedAgentIds.length || 0}
agentStatus={agentsStatus}
selectableAgents={agentsOnCurrentPage?.filter(isAgentSelectable).length || 0}
managedAgentsOnCurrentPage={managedAgentsOnCurrentPage}