From b91dfc93e346d503f073a0aa2af1d4c776db1d4a Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 7 Dec 2022 09:34:00 -0500 Subject: [PATCH] [8.6] changed agent versions to agents per version telemetry (#147164) (#147169) # Backport This will backport the following commits from `main` to `8.6`: - [changed agent versions to agents per version telemetry (#147164)](https://github.com/elastic/kibana/pull/147164) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com> Co-authored-by: Julia Bardi --- .../fleet/cypress/e2e/integrations_real.cy.ts | 4 ++-- .../fleet/server/collectors/agent_collectors.ts | 13 ++++++++----- .../integration_tests/fleet_usage_telemetry.test.ts | 5 ++++- .../services/telemetry/fleet_usages_schema.ts | 8 +++++--- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts b/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts index 3b7c29561bc93..d749172a3cbe4 100644 --- a/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts @@ -174,10 +174,10 @@ describe('Add Integration - Real API', () => { setupIntegrations(); cy.getBySel(getIntegrationCategories('aws')).click(); cy.getBySel(INTEGRATIONS_SEARCHBAR.BADGE).contains('AWS').should('exist'); - cy.getBySel(INTEGRATION_LIST).find('.euiCard').should('have.length', 28); + cy.getBySel(INTEGRATION_LIST).find('.euiCard').should('have.length.greaterThan', 28); cy.getBySel(INTEGRATIONS_SEARCHBAR.INPUT).clear().type('Cloud'); - cy.getBySel(INTEGRATION_LIST).find('.euiCard').should('have.length', 3); + cy.getBySel(INTEGRATION_LIST).find('.euiCard').should('have.length.greaterThan', 2); cy.getBySel(INTEGRATIONS_SEARCHBAR.REMOVE_BADGE_BUTTON).click(); cy.getBySel(INTEGRATIONS_SEARCHBAR.BADGE).should('not.exist'); }); diff --git a/x-pack/plugins/fleet/server/collectors/agent_collectors.ts b/x-pack/plugins/fleet/server/collectors/agent_collectors.ts index 7861e7ac606a4..a9bf772602cf8 100644 --- a/x-pack/plugins/fleet/server/collectors/agent_collectors.ts +++ b/x-pack/plugins/fleet/server/collectors/agent_collectors.ts @@ -49,7 +49,10 @@ export const getAgentUsage = async ( }; export interface AgentData { - agent_versions: string[]; + agents_per_version: Array<{ + version: string; + count: number; + }>; agent_checkin_status: { error: number; degraded: number; @@ -58,9 +61,9 @@ export interface AgentData { } const DEFAULT_AGENT_DATA = { - agent_versions: [], agent_checkin_status: { error: 0, degraded: 0 }, agents_per_policy: [], + agents_per_version: [], }; export const getAgentData = async ( @@ -105,8 +108,8 @@ export const getAgentData = async ( }, { signal: abortController.signal } ); - const versions = ((response?.aggregations?.versions as any).buckets ?? []).map( - (bucket: any) => bucket.key + const agentsPerVersion = ((response?.aggregations?.versions as any).buckets ?? []).map( + (bucket: any) => ({ version: bucket.key, count: bucket.doc_count }) ); const statuses = transformLastCheckinStatusBuckets(response); @@ -115,9 +118,9 @@ export const getAgentData = async ( ); return { - agent_versions: versions, agent_checkin_status: statuses, agents_per_policy: agentsPerPolicy, + agents_per_version: agentsPerVersion, }; } catch (error) { if (error.statusCode === 404) { diff --git a/x-pack/plugins/fleet/server/integration_tests/fleet_usage_telemetry.test.ts b/x-pack/plugins/fleet/server/integration_tests/fleet_usage_telemetry.test.ts index 3a53bb30176df..ea091479afa4e 100644 --- a/x-pack/plugins/fleet/server/integration_tests/fleet_usage_telemetry.test.ts +++ b/x-pack/plugins/fleet/server/integration_tests/fleet_usage_telemetry.test.ts @@ -260,7 +260,10 @@ describe('fleet usage telemetry', () => { num_host_urls: 0, }, packages: [], - agent_versions: ['8.5.1', '8.6.0'], + agents_per_version: [ + { version: '8.5.1', count: 1 }, + { version: '8.6.0', count: 1 }, + ], agent_checkin_status: { error: 1, degraded: 1 }, agents_per_policy: [2], fleet_server_config: { diff --git a/x-pack/plugins/fleet/server/services/telemetry/fleet_usages_schema.ts b/x-pack/plugins/fleet/server/services/telemetry/fleet_usages_schema.ts index 3e3bdc9d3b243..a657ff177b68e 100644 --- a/x-pack/plugins/fleet/server/services/telemetry/fleet_usages_schema.ts +++ b/x-pack/plugins/fleet/server/services/telemetry/fleet_usages_schema.ts @@ -106,11 +106,13 @@ export const fleetUsagesSchema: RootSchema = { }, }, }, - agent_versions: { + agents_per_version: { type: 'array', items: { - type: 'keyword', - _meta: { description: 'The agent versions enrolled in this deployment.' }, + properties: { + version: { type: 'keyword' }, + count: { type: 'long' }, + }, }, }, agents_per_policy: {