Skip to content

Commit

Permalink
[Fleet] Use same action_id for all batches in an uprade
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Jul 19, 2022
1 parent d5c4156 commit e44c2f3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion x-pack/plugins/fleet/server/services/agents/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { ElasticsearchClient, SavedObjectsClientContract } from '@kbn/core/server';
import moment from 'moment';
import pMap from 'p-map';
import uuid from 'uuid/v4';

import type { Agent, BulkActionResult, FleetServerAgentAction, CurrentUpgrade } from '../../types';
import {
Expand Down Expand Up @@ -100,6 +101,7 @@ export async function sendUpgradeAgentsActions(
}
}
} else if ('kuery' in options) {
const actionId = uuid();
return await processAgentsInBatches(
esClient,
{
Expand All @@ -108,7 +110,14 @@ export async function sendUpgradeAgentsActions(
batchSize: options.batchSize,
},
async (agents: Agent[], skipSuccess: boolean) =>
await upgradeBatch(soClient, esClient, agents, outgoingErrors, options, skipSuccess)
await upgradeBatch(
soClient,
esClient,
agents,
outgoingErrors,
{ ...options, actionId },
skipSuccess
)
);
}

Expand All @@ -121,6 +130,7 @@ async function upgradeBatch(
givenAgents: Agent[],
outgoingErrors: Record<Agent['id'], Error>,
options: ({ agents: Agent[] } | GetAgentsOptions) & {
actionId?: string;
version: string;
sourceUri?: string | undefined;
force?: boolean;
Expand Down Expand Up @@ -183,6 +193,7 @@ async function upgradeBatch(
);

await createAgentAction(esClient, {
id: options.actionId,
created_at: now,
data,
ack_data: data,
Expand Down

0 comments on commit e44c2f3

Please sign in to comment.