Skip to content

Commit

Permalink
changed cardinality agg logic in action_status (#144162) (#144166)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4c52d09)

Co-authored-by: Julia Bardi <[email protected]>
  • Loading branch information
kibanamachine and juliaElastic authored Oct 31, 2022
1 parent eb0cc9b commit 1045c00
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions x-pack/plugins/fleet/server/services/agents/action_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import type { FleetServerAgentAction, ActionStatus, ListWithKuery } from '../../
import { AGENT_ACTIONS_INDEX, AGENT_ACTIONS_RESULTS_INDEX } from '../../../common';
import { appContextService } from '..';

const PRECISION_THRESHOLD = 40000;

/**
* Return current bulk actions
*/
Expand Down Expand Up @@ -42,7 +44,7 @@ export async function getActionStatuses(
agent_count: {
cardinality: {
field: 'agent_id',
precision_threshold: 40000, // max value
precision_threshold: PRECISION_THRESHOLD, // max value
},
},
},
Expand All @@ -65,9 +67,12 @@ export async function getActionStatuses(
(bucket: any) => bucket.key === action.actionId
);
const nbAgentsActioned = action.nbAgentsActioned || action.nbAgentsActionCreated;
const cardinalityCount = (matchingBucket?.agent_count as any)?.value ?? 0;
const docCount = matchingBucket?.doc_count ?? 0;
const nbAgentsAck = Math.min(
matchingBucket?.doc_count ?? 0,
(matchingBucket?.agent_count as any)?.value ?? 0,
docCount,
// only using cardinality count when count lower than precision threshold
docCount > PRECISION_THRESHOLD ? docCount : cardinalityCount,
nbAgentsActioned
);
const completionTime = (matchingBucket?.max_timestamp as any)?.value_as_string;
Expand Down

0 comments on commit 1045c00

Please sign in to comment.