Skip to content

Commit

Permalink
[8.11] [Fleet] Fix agent metrics aggregation for > 10 agents (elastic…
Browse files Browse the repository at this point in the history
…#172016) (elastic#172029)

# Backport

This will backport the following commits from `main` to `8.11`:
- [[Fleet] Fix agent metrics aggregation for > 10 agents
(elastic#172016)](elastic#172016)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nicolas
Chaulet","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-11-27T22:26:51Z","message":"[Fleet]
Fix agent metrics aggregation for > 10 agents (elastic#172016)\n\n##
Summary\n\nTo compute agent metrics we do a term aggregation there was
an error as\nwe were not specifying size it was only fetching 10 items
for that\naggregation resolving in incomplete results\n\n## Release
note\n\nFix agents metrics retrieval on the agent list page, that was
displaying\nN/A for agent with metrics for users with more than 10
agents.\n\n## Example \n### Before \n<img width=\"557\" alt=\"Screenshot
2023-11-27 at 2 20
57 PM\"\nsrc=\"https://github.com/elastic/kibana/assets/1336873/d7928238-011a-4503-87e7-a39b50a98b50\">\n\n###
After\n<img width=\"588\" alt=\"Screenshot 2023-11-27 at 2 21
29 PM\"\nsrc=\"https://github.com/elastic/kibana/assets/1336873/6c9c2101-9cba-421d-ae13-a9b5ad892798\">\n\n\n##
Tests\n\nIt seems adding automated tests for that issue to the existing
test is\nnot trivial, not sure if it really add value to test
that.\n\nCo-authored-by: Kibana Machine
<[email protected]>","sha":"2cfc72240383a909b537677b7a73bebee67eb8b9","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Team:Fleet","backport:prev-minor","v8.12.0"],"number":172016,"url":"https://github.com/elastic/kibana/pull/172016","mergeCommit":{"message":"[Fleet]
Fix agent metrics aggregation for > 10 agents (elastic#172016)\n\n##
Summary\n\nTo compute agent metrics we do a term aggregation there was
an error as\nwe were not specifying size it was only fetching 10 items
for that\naggregation resolving in incomplete results\n\n## Release
note\n\nFix agents metrics retrieval on the agent list page, that was
displaying\nN/A for agent with metrics for users with more than 10
agents.\n\n## Example \n### Before \n<img width=\"557\" alt=\"Screenshot
2023-11-27 at 2 20
57 PM\"\nsrc=\"https://github.com/elastic/kibana/assets/1336873/d7928238-011a-4503-87e7-a39b50a98b50\">\n\n###
After\n<img width=\"588\" alt=\"Screenshot 2023-11-27 at 2 21
29 PM\"\nsrc=\"https://github.com/elastic/kibana/assets/1336873/6c9c2101-9cba-421d-ae13-a9b5ad892798\">\n\n\n##
Tests\n\nIt seems adding automated tests for that issue to the existing
test is\nnot trivial, not sure if it really add value to test
that.\n\nCo-authored-by: Kibana Machine
<[email protected]>","sha":"2cfc72240383a909b537677b7a73bebee67eb8b9"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/172016","number":172016,"mergeCommit":{"message":"[Fleet]
Fix agent metrics aggregation for > 10 agents (elastic#172016)\n\n##
Summary\n\nTo compute agent metrics we do a term aggregation there was
an error as\nwe were not specifying size it was only fetching 10 items
for that\naggregation resolving in incomplete results\n\n## Release
note\n\nFix agents metrics retrieval on the agent list page, that was
displaying\nN/A for agent with metrics for users with more than 10
agents.\n\n## Example \n### Before \n<img width=\"557\" alt=\"Screenshot
2023-11-27 at 2 20
57 PM\"\nsrc=\"https://github.com/elastic/kibana/assets/1336873/d7928238-011a-4503-87e7-a39b50a98b50\">\n\n###
After\n<img width=\"588\" alt=\"Screenshot 2023-11-27 at 2 21
29 PM\"\nsrc=\"https://github.com/elastic/kibana/assets/1336873/6c9c2101-9cba-421d-ae13-a9b5ad892798\">\n\n\n##
Tests\n\nIt seems adding automated tests for that issue to the existing
test is\nnot trivial, not sure if it really add value to test
that.\n\nCo-authored-by: Kibana Machine
<[email protected]>","sha":"2cfc72240383a909b537677b7a73bebee67eb8b9"}}]}]
BACKPORT-->

Co-authored-by: Nicolas Chaulet <[email protected]>
  • Loading branch information
kibanamachine and nchaulet authored Nov 27, 2023
1 parent 75cdadf commit ae1f93c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/server/services/agents/agent_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type { Agent } from '../../types';
import { appContextService } from '../app_context';
import { DATA_TIERS } from '../../../common/constants';

const AGGREGATION_MAX_SIZE = 1000;

export async function fetchAndAssignAgentMetrics(esClient: ElasticsearchClient, agents: Agent[]) {
try {
return await _fetchAndAssignAgentMetrics(esClient, agents);
Expand Down Expand Up @@ -112,6 +114,7 @@ const aggregationQueryBuilder = (agentIds: string[]) => ({
agents: {
terms: {
field: 'elastic_agent.id',
size: AGGREGATION_MAX_SIZE,
},
aggs: {
sum_memory_size: {
Expand All @@ -127,6 +130,7 @@ const aggregationQueryBuilder = (agentIds: string[]) => ({
processes: {
terms: {
field: 'elastic_agent.process',
size: AGGREGATION_MAX_SIZE,
order: {
_count: 'desc',
},
Expand Down

0 comments on commit ae1f93c

Please sign in to comment.