[Fleet] Fix bumpAllPolicy to fetch all policies (#122277) (#122331)

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
This commit is contained in:
Kibana Machine 2022-01-05 09:57:31 -05:00 committed by GitHub
parent 4b2c69ef50
commit b707eef56a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,14 +8,14 @@
import { uniq, omit } from 'lodash';
import uuid from 'uuid/v4';
import uuidv5 from 'uuid/v5';
import { safeDump } from 'js-yaml';
import pMap from 'p-map';
import type {
ElasticsearchClient,
SavedObjectsClientContract,
SavedObjectsBulkUpdateResponse,
} from 'src/core/server';
import { safeDump } from 'js-yaml';
import { SavedObjectsErrorHelpers } from '../../../../../src/core/server';
import type { AuthenticatedUser } from '../../../security/server';
@ -23,6 +23,7 @@ import {
AGENT_POLICY_SAVED_OBJECT_TYPE,
AGENTS_PREFIX,
PRECONFIGURATION_DELETION_RECORD_SAVED_OBJECT_TYPE,
SO_SEARCH_LIMIT,
} from '../constants';
import type {
PackagePolicy,
@ -477,6 +478,7 @@ class AgentPolicyService {
fields: ['revision', 'data_output_id', 'monitoring_output_id'],
searchFields: ['data_output_id', 'monitoring_output_id'],
search: escapeSearchQueryPhrase(outputId),
perPage: SO_SEARCH_LIMIT,
});
const bumpedPolicies = currentPolicies.saved_objects.map((policy) => {
policy.attributes = {
@ -488,11 +490,10 @@ class AgentPolicyService {
return policy;
});
const res = await soClient.bulkUpdate<AgentPolicySOAttributes>(bumpedPolicies);
await Promise.all(
currentPolicies.saved_objects.map((policy) =>
this.triggerAgentPolicyUpdatedEvent(soClient, esClient, 'updated', policy.id)
)
await pMap(
currentPolicies.saved_objects,
(policy) => this.triggerAgentPolicyUpdatedEvent(soClient, esClient, 'updated', policy.id),
{ concurrency: 50 }
);
return res;
@ -506,6 +507,7 @@ class AgentPolicyService {
const currentPolicies = await soClient.find<AgentPolicySOAttributes>({
type: SAVED_OBJECT_TYPE,
fields: ['revision'],
perPage: SO_SEARCH_LIMIT,
});
const bumpedPolicies = currentPolicies.saved_objects.map((policy) => {
policy.attributes = {
@ -518,10 +520,10 @@ class AgentPolicyService {
});
const res = await soClient.bulkUpdate<AgentPolicySOAttributes>(bumpedPolicies);
await Promise.all(
currentPolicies.saved_objects.map((policy) =>
this.triggerAgentPolicyUpdatedEvent(soClient, esClient, 'updated', policy.id)
)
await pMap(
currentPolicies.saved_objects,
(policy) => this.triggerAgentPolicyUpdatedEvent(soClient, esClient, 'updated', policy.id),
{ concurrency: 50 }
);
return res;