Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Jun 11, 2024
1 parent 7e3bec6 commit fac1b82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
27 changes: 2 additions & 25 deletions x-pack/plugins/fleet/server/collectors/agents_per_output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ import type { ElasticsearchClient, SavedObjectsClientContract } from '@kbn/core/

import _ from 'lodash';

import pMap from 'p-map';

import { outputTypeSupportPresets } from '../../common/services/output_helpers';
import type { AgentPolicy } from '../../common/types';

import { AGENTS_PREFIX, SO_SEARCH_LIMIT } from '../../common';
import { SO_SEARCH_LIMIT } from '../../common';
import { agentPolicyService, outputService } from '../services';
import { getAgentsByKuery } from '../services/agents';

export interface AgentsPerOutputType {
output_type: string;
Expand All @@ -31,25 +28,6 @@ export interface AgentsPerOutputType {
};
}

async function populateAssignedAgentsCount(
esClient: ElasticsearchClient,
soClient: SavedObjectsClientContract,
agentPolicies: AgentPolicy[]
) {
await pMap(
agentPolicies,
(agentPolicy: AgentPolicy) => {
return getAgentsByKuery(esClient, soClient, {
showInactive: true,
perPage: 0,
page: 1,
kuery: `${AGENTS_PREFIX}.policy_id:${agentPolicy.id}`,
}).then(({ total }) => (agentPolicy.agents = total));
},
{ concurrency: 10 }
);
}

export async function getAgentsPerOutput(
soClient: SavedObjectsClientContract,
esClient: ElasticsearchClient
Expand All @@ -70,10 +48,9 @@ export async function getAgentsPerOutput(
esClient,
page: 1,
perPage: SO_SEARCH_LIMIT,
withAgentCount: true,
});

await populateAssignedAgentsCount(esClient, soClient, agentPolicies);

const outputTypes: { [key: string]: AgentsPerOutputType } = {};

agentPolicies
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/fleet/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,19 @@ class AgentPolicyService {
agentPolicy.package_policies =
(await packagePolicyService.findAllForAgentPolicy(soClient, agentPolicySO.id)) || [];
}
if (options.withAgentCount) {
await getAgentsByKuery(
appContextService.getInternalUserESClient(),
appContextService.getInternalUserSOClientForSpaceId(agentPolicy.space_id),
{
showInactive: true,
perPage: 0,
page: 1,
kuery: `${AGENTS_PREFIX}.policy_id:${agentPolicy.id}`,
}
).then(({ total }) => (agentPolicy.agents = total));
}

return agentPolicy;
},
{ concurrency: 50 }
Expand Down

0 comments on commit fac1b82

Please sign in to comment.