mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
added retry_on_conflict and report errors from bulk agent update (#142088)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
16ca2d2895
commit
13824dd0dd
3 changed files with 33 additions and 1 deletions
|
@ -405,6 +405,7 @@ export async function bulkUpdateAgents(
|
|||
{
|
||||
update: {
|
||||
_id: agentId,
|
||||
retry_on_conflict: 3,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
@ -96,4 +96,29 @@ describe('reassignAgents (plural)', () => {
|
|||
});
|
||||
expect(calledWithActionResults.body?.[1] as any).toEqual(expectedObject);
|
||||
});
|
||||
|
||||
it('should report errors from ES agent update call', async () => {
|
||||
const { soClient, esClient, agentInRegularDoc, regularAgentPolicySO2 } = createClientMock();
|
||||
esClient.bulk.mockResponse({
|
||||
items: [
|
||||
{
|
||||
update: {
|
||||
_id: agentInRegularDoc._id,
|
||||
error: new Error('version conflict'),
|
||||
},
|
||||
},
|
||||
],
|
||||
} as any);
|
||||
const idsToReassign = [agentInRegularDoc._id];
|
||||
await reassignAgents(soClient, esClient, { agentIds: idsToReassign }, regularAgentPolicySO2.id);
|
||||
|
||||
const calledWithActionResults = esClient.bulk.mock.calls[1][0] as estypes.BulkRequest;
|
||||
const expectedObject = expect.objectContaining({
|
||||
'@timestamp': expect.anything(),
|
||||
action_id: expect.anything(),
|
||||
agent_id: agentInRegularDoc._id,
|
||||
error: 'version conflict',
|
||||
});
|
||||
expect(calledWithActionResults.body?.[1] as any).toEqual(expectedObject);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -72,7 +72,7 @@ export async function reassignBatch(
|
|||
throw new AgentReassignmentError('No agents to reassign, already assigned or hosted agents');
|
||||
}
|
||||
|
||||
await bulkUpdateAgents(
|
||||
const res = await bulkUpdateAgents(
|
||||
esClient,
|
||||
agentsToUpdate.map((agent) => ({
|
||||
agentId: agent.id,
|
||||
|
@ -83,6 +83,12 @@ export async function reassignBatch(
|
|||
}))
|
||||
);
|
||||
|
||||
res.items
|
||||
.filter((item) => !item.success)
|
||||
.forEach((item) => {
|
||||
errors[item.id] = item.error!;
|
||||
});
|
||||
|
||||
const actionId = options.actionId ?? uuid();
|
||||
const errorCount = Object.keys(errors).length;
|
||||
const total = options.total ?? agentsToUpdate.length + errorCount;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue