-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fleet] refactored bulk update tags retry #147594
Changes from 12 commits
0f92d07
9bfc39f
c098438
ed60158
2c3660d
3db4cb6
0edb432
4c25056
1e12eee
b003d9b
c5eb223
53e670b
7fe37bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,7 @@ import type { ElasticsearchClient, SavedObjectsClientContract } from '@kbn/core/ | |
import type { Agent } from '../../types'; | ||
import { AgentReassignmentError } from '../../errors'; | ||
|
||
import { SO_SEARCH_LIMIT } from '../../constants'; | ||
|
||
import { getAgentDocuments, getAgentsByKuery } from './crud'; | ||
import { getAgentDocuments } from './crud'; | ||
import type { GetAgentsOptions } from '.'; | ||
import { searchHitToAgent } from './helpers'; | ||
import { UpdateAgentTagsActionRunner, updateTagsBatch } from './update_agent_tags_action_runner'; | ||
|
@@ -30,7 +28,7 @@ export async function updateAgentTags( | |
tagsToRemove: string[] | ||
): Promise<{ actionId: string }> { | ||
const outgoingErrors: Record<Agent['id'], Error> = {}; | ||
let givenAgents: Agent[] = []; | ||
const givenAgents: Agent[] = []; | ||
|
||
if ('agentIds' in options) { | ||
const givenAgentsResults = await getAgentDocuments(esClient, options.agentIds); | ||
|
@@ -44,30 +42,17 @@ export async function updateAgentTags( | |
} | ||
} | ||
} else if ('kuery' in options) { | ||
const batchSize = options.batchSize ?? SO_SEARCH_LIMIT; | ||
const res = await getAgentsByKuery(esClient, { | ||
kuery: options.kuery, | ||
showInactive: options.showInactive ?? false, | ||
page: 1, | ||
perPage: batchSize, | ||
}); | ||
if (res.total <= batchSize) { | ||
givenAgents = res.agents; | ||
} else { | ||
return await new UpdateAgentTagsActionRunner( | ||
esClient, | ||
soClient, | ||
{ | ||
...options, | ||
batchSize, | ||
total: res.total, | ||
kuery: options.kuery, | ||
tagsToAdd, | ||
tagsToRemove, | ||
}, | ||
{ pitId: '' } | ||
).runActionAsyncWithRetry(); | ||
} | ||
return await new UpdateAgentTagsActionRunner( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. simplified the logic to use retry for all update tags kuery actions Could reproduce in an ECE instance by adding a tag on 5k horde agents and getting this response from bulk API:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
esClient, | ||
soClient, | ||
{ | ||
...options, | ||
kuery: options.kuery, | ||
tagsToAdd, | ||
tagsToRemove, | ||
}, | ||
{ pitId: '' } | ||
).runActionAsyncWithRetry(); | ||
} | ||
|
||
return await updateTagsBatch(soClient, esClient, givenAgents, outgoingErrors, { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside: Why is
cardinalityCount
used, can't we always use the docCount here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cardinality was introduced for actions that can potentially be acked multiple times by agents e.g. upgrade. So we count acks by one agent once.