changing fleet server query to include more than first 1000 (#132893)

This commit is contained in:
Julia Bardi 2022-05-25 14:04:39 +02:00 committed by GitHub
parent f1d3127011
commit c6a6abd325
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,7 +13,7 @@ import { useFleetStatus, useGetAgents } from '../../hooks';
import { FleetServerRequirementPage } from '../../applications/fleet/sections/agents/agent_requirements_page';
import { FLEET_SERVER_PACKAGE } from '../../constants';
import { AGENTS_PREFIX, FLEET_SERVER_PACKAGE, SO_SEARCH_LIMIT } from '../../constants';
import { useFleetServerUnhealthy } from '../../applications/fleet/sections/agents/hooks/use_fleet_server_unhealthy';
@ -43,20 +43,23 @@ export const Instructions = (props: InstructionProps) => {
const fleetStatus = useFleetStatus();
const { isUnhealthy: isFleetServerUnhealthy } = useFleetServerUnhealthy();
const fleetServerAgentPolicies: string[] = useMemo(
() => agentPolicies.filter((pol) => policyHasFleetServer(pol)).map((pol) => pol.id),
[agentPolicies]
);
const { data: agents, isLoading: isLoadingAgents } = useGetAgents({
page: 1,
perPage: 1000,
perPage: SO_SEARCH_LIMIT,
showInactive: false,
kuery:
fleetServerAgentPolicies.length === 0
? ''
: `${AGENTS_PREFIX}.policy_id:${fleetServerAgentPolicies
.map((id) => `"${id}"`)
.join(' or ')}`,
});
const fleetServers = useMemo(() => {
const fleetServerAgentPolicies: string[] = agentPolicies
.filter((pol) => policyHasFleetServer(pol))
.map((pol) => pol.id);
return (agents?.items ?? []).filter((agent) =>
fleetServerAgentPolicies.includes(agent.policy_id ?? '')
);
}, [agents, agentPolicies]);
const fleetServers = agents?.items || [];
const fleetServerHosts = useMemo(() => {
return settings?.fleet_server_hosts || [];