From f7caf44876d3ff604fe7270cdbad82211c3816b4 Mon Sep 17 00:00:00 2001 From: Zacqary Adam Xeper Date: Wed, 31 Mar 2021 14:10:46 -0500 Subject: [PATCH] [Fleet] Match telemetry key names to UI agent states (#95567) --- .../server/collectors/agent_collectors.ts | 28 ++- .../fleet/server/collectors/register.ts | 34 ++- .../fleet/server/services/agents/status.ts | 12 +- .../schema/xpack_plugins.json | 232 +++++++++++------- .../apis/agents/status.ts | 1 + 5 files changed, 196 insertions(+), 111 deletions(-) diff --git a/x-pack/plugins/fleet/server/collectors/agent_collectors.ts b/x-pack/plugins/fleet/server/collectors/agent_collectors.ts index de16f6555d4b..0eb392e78433 100644 --- a/x-pack/plugins/fleet/server/collectors/agent_collectors.ts +++ b/x-pack/plugins/fleet/server/collectors/agent_collectors.ts @@ -13,10 +13,11 @@ import * as AgentService from '../services/agents'; import { isFleetServerSetup } from '../services/fleet_server'; export interface AgentUsage { - total: number; - online: number; - error: number; + total_enrolled: number; + healthy: number; + unhealthy: number; offline: number; + total_all_statuses: number; } export const getAgentUsage = async ( @@ -27,21 +28,26 @@ export const getAgentUsage = async ( // TODO: unsure if this case is possible at all. if (!soClient || !esClient || !(await isFleetServerSetup())) { return { - total: 0, - online: 0, - error: 0, + total_enrolled: 0, + healthy: 0, + unhealthy: 0, offline: 0, + total_all_statuses: 0, }; } - const { total, online, error, offline } = await AgentService.getAgentStatusForAgentPolicy( - soClient, - esClient - ); - return { + const { total, + inactive, online, error, offline, + } = await AgentService.getAgentStatusForAgentPolicy(soClient, esClient); + return { + total_enrolled: total, + healthy: online, + unhealthy: error, + offline, + total_all_statuses: total + inactive, }; }; diff --git a/x-pack/plugins/fleet/server/collectors/register.ts b/x-pack/plugins/fleet/server/collectors/register.ts index 7992d54d1dfa..842bb95fe813 100644 --- a/x-pack/plugins/fleet/server/collectors/register.ts +++ b/x-pack/plugins/fleet/server/collectors/register.ts @@ -49,10 +49,36 @@ export function registerFleetUsageCollector( schema: { agents_enabled: { type: 'boolean' }, agents: { - total: { type: 'long' }, - online: { type: 'long' }, - error: { type: 'long' }, - offline: { type: 'long' }, + total_enrolled: { + type: 'long', + _meta: { + description: 'The total number of enrolled agents, in any state', + }, + }, + healthy: { + type: 'long', + _meta: { + description: 'The total number of enrolled agents in a healthy state', + }, + }, + unhealthy: { + type: 'long', + _meta: { + description: 'The total number of enrolled agents in an unhealthy state', + }, + }, + offline: { + type: 'long', + _meta: { + description: 'The total number of enrolled agents currently offline', + }, + }, + total_all_statuses: { + type: 'long', + _meta: { + description: 'The total number of agents in any state, both enrolled and inactive', + }, + }, }, packages: { type: 'array', diff --git a/x-pack/plugins/fleet/server/services/agents/status.ts b/x-pack/plugins/fleet/server/services/agents/status.ts index f3fb01655974..737b6874a813 100644 --- a/x-pack/plugins/fleet/server/services/agents/status.ts +++ b/x-pack/plugins/fleet/server/services/agents/status.ts @@ -55,17 +55,18 @@ export async function getAgentStatusForAgentPolicy( agentPolicyId?: string, filterKuery?: string ) { - const [all, online, error, offline, updating] = await pMap( + const [all, allActive, online, error, offline, updating] = await pMap( [ - undefined, + undefined, // All agents, including inactive + undefined, // All active agents AgentStatusKueryHelper.buildKueryForOnlineAgents(), AgentStatusKueryHelper.buildKueryForErrorAgents(), AgentStatusKueryHelper.buildKueryForOfflineAgents(), AgentStatusKueryHelper.buildKueryForUpdatingAgents(), ], - (kuery) => + (kuery, index) => getAgentsByKuery(esClient, { - showInactive: false, + showInactive: index === 0, perPage: 0, page: 1, kuery: joinKuerys( @@ -84,7 +85,8 @@ export async function getAgentStatusForAgentPolicy( return { events: await getEventsCount(soClient, agentPolicyId), - total: all.total, + total: allActive.total, + inactive: all.total - allActive.total, online: online.total, error: error.total, offline: offline.total, diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json index ef09937da3fb..e1e0711c2bb2 100644 --- a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json +++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @@ -1837,17 +1837,35 @@ }, "agents": { "properties": { - "total": { - "type": "long" + "total_enrolled": { + "type": "long", + "_meta": { + "description": "The total number of enrolled agents, in any state" + } }, - "online": { - "type": "long" + "healthy": { + "type": "long", + "_meta": { + "description": "The total number of enrolled agents in a healthy state" + } }, - "error": { - "type": "long" + "unhealthy": { + "type": "long", + "_meta": { + "description": "The total number of enrolled agents in an unhealthy state" + } }, "offline": { - "type": "long" + "type": "long", + "_meta": { + "description": "The total number of enrolled agents currently offline" + } + }, + "total_all_statuses": { + "type": "long", + "_meta": { + "description": "The total number of agents in any state, both enrolled and inactive" + } } } }, @@ -1978,6 +1996,42 @@ "xy_layer_added": { "type": "long" }, + "open_field_editor_edit": { + "type": "long", + "_meta": { + "description": "Number of times the user opened the editor flyout to edit a field from within Lens." + } + }, + "open_field_editor_add": { + "type": "long", + "_meta": { + "description": "Number of times the user opened the editor flyout to add a field from within Lens." + } + }, + "save_field_edit": { + "type": "long", + "_meta": { + "description": "Number of times the user edited a field from within Lens." + } + }, + "save_field_add": { + "type": "long", + "_meta": { + "description": "Number of times the user added a field from within Lens." + } + }, + "open_field_delete_modal": { + "type": "long", + "_meta": { + "description": "Number of times the user opened the field delete modal from within Lens." + } + }, + "delete_field": { + "type": "long", + "_meta": { + "description": "Number of times the user deleted a field from within Lens." + } + }, "indexpattern_dimension_operation_terms": { "type": "long", "_meta": { @@ -2034,70 +2088,50 @@ }, "indexpattern_dimension_operation_range": { "type": "long", - "_meta": { "description": "Number of times the range function was selected" } + "_meta": { + "description": "Number of times the range function was selected" + } }, "indexpattern_dimension_operation_median": { "type": "long", - "_meta": { "description": "Number of times the median function was selected" } + "_meta": { + "description": "Number of times the median function was selected" + } }, "indexpattern_dimension_operation_percentile": { "type": "long", - "_meta": { "description": "Number of times the percentile function was selected" } + "_meta": { + "description": "Number of times the percentile function was selected" + } }, "indexpattern_dimension_operation_last_value": { "type": "long", - "_meta": { "description": "Number of times the last value function was selected" } + "_meta": { + "description": "Number of times the last value function was selected" + } }, "indexpattern_dimension_operation_cumulative_sum": { "type": "long", - "_meta": { "description": "Number of times the cumulative sum function was selected" } + "_meta": { + "description": "Number of times the cumulative sum function was selected" + } }, "indexpattern_dimension_operation_counter_rate": { "type": "long", - "_meta": { "description": "Number of times the counter rate function was selected" } + "_meta": { + "description": "Number of times the counter rate function was selected" + } }, "indexpattern_dimension_operation_derivative": { "type": "long", - "_meta": { "description": "Number of times the derivative function was selected" } + "_meta": { + "description": "Number of times the derivative function was selected" + } }, "indexpattern_dimension_operation_moving_average": { - "type": "long", - "_meta": { "description": "Number of times the moving average function was selected" } - }, - "open_field_editor_edit": { "type": "long", "_meta": { - "description": "Number of times the user opened the editor flyout to edit a field from within Lens." - } - }, - "open_field_editor_add": { - "type": "long", - "_meta": { - "description": "Number of times the user opened the editor flyout to add a field from within Lens." - } - }, - "save_field_edit": { - "type": "long", - "_meta": { - "description": "Number of times the user edited a field from within Lens." - } - }, - "save_field_add": { - "type": "long", - "_meta": { - "description": "Number of times the user added a field from within Lens." - } - }, - "open_field_delete_modal": { - "type": "long", - "_meta": { - "description": "Number of times the user opened the field delete modal from within Lens." - } - }, - "delete_field": { - "type": "long", - "_meta": { - "description": "Number of times the user deleted a field from within Lens." + "description": "Number of times the moving average function was selected" } } } @@ -2185,6 +2219,42 @@ "xy_layer_added": { "type": "long" }, + "open_field_editor_edit": { + "type": "long", + "_meta": { + "description": "Number of times the user opened the editor flyout to edit a field from within Lens." + } + }, + "open_field_editor_add": { + "type": "long", + "_meta": { + "description": "Number of times the user opened the editor flyout to add a field from within Lens." + } + }, + "save_field_edit": { + "type": "long", + "_meta": { + "description": "Number of times the user edited a field from within Lens." + } + }, + "save_field_add": { + "type": "long", + "_meta": { + "description": "Number of times the user added a field from within Lens." + } + }, + "open_field_delete_modal": { + "type": "long", + "_meta": { + "description": "Number of times the user opened the field delete modal from within Lens." + } + }, + "delete_field": { + "type": "long", + "_meta": { + "description": "Number of times the user deleted a field from within Lens." + } + }, "indexpattern_dimension_operation_terms": { "type": "long", "_meta": { @@ -2241,70 +2311,50 @@ }, "indexpattern_dimension_operation_range": { "type": "long", - "_meta": { "description": "Number of times the range function was selected" } + "_meta": { + "description": "Number of times the range function was selected" + } }, "indexpattern_dimension_operation_median": { "type": "long", - "_meta": { "description": "Number of times the median function was selected" } + "_meta": { + "description": "Number of times the median function was selected" + } }, "indexpattern_dimension_operation_percentile": { "type": "long", - "_meta": { "description": "Number of times the percentile function was selected" } + "_meta": { + "description": "Number of times the percentile function was selected" + } }, "indexpattern_dimension_operation_last_value": { "type": "long", - "_meta": { "description": "Number of times the last value function was selected" } + "_meta": { + "description": "Number of times the last value function was selected" + } }, "indexpattern_dimension_operation_cumulative_sum": { "type": "long", - "_meta": { "description": "Number of times the cumulative sum function was selected" } + "_meta": { + "description": "Number of times the cumulative sum function was selected" + } }, "indexpattern_dimension_operation_counter_rate": { "type": "long", - "_meta": { "description": "Number of times the counter rate function was selected" } + "_meta": { + "description": "Number of times the counter rate function was selected" + } }, "indexpattern_dimension_operation_derivative": { "type": "long", - "_meta": { "description": "Number of times the derivative function was selected" } + "_meta": { + "description": "Number of times the derivative function was selected" + } }, "indexpattern_dimension_operation_moving_average": { - "type": "long", - "_meta": { "description": "Number of times the moving average function was selected" } - }, - "open_field_editor_edit": { "type": "long", "_meta": { - "description": "Number of times the user opened the editor flyout to edit a field from within Lens." - } - }, - "open_field_editor_add": { - "type": "long", - "_meta": { - "description": "Number of times the user opened the editor flyout to add a field from within Lens." - } - }, - "save_field_edit": { - "type": "long", - "_meta": { - "description": "Number of times the user edited a field from within Lens." - } - }, - "save_field_add": { - "type": "long", - "_meta": { - "description": "Number of times the user added a field from within Lens." - } - }, - "open_field_delete_modal": { - "type": "long", - "_meta": { - "description": "Number of times the user opened the field delete modal from within Lens." - } - }, - "delete_field": { - "type": "long", - "_meta": { - "description": "Number of times the user deleted a field from within Lens." + "description": "Number of times the moving average function was selected" } } } diff --git a/x-pack/test/fleet_api_integration/apis/agents/status.ts b/x-pack/test/fleet_api_integration/apis/agents/status.ts index 3245b9a459fb..f79ff15b64d3 100644 --- a/x-pack/test/fleet_api_integration/apis/agents/status.ts +++ b/x-pack/test/fleet_api_integration/apis/agents/status.ts @@ -79,6 +79,7 @@ export default function ({ getService }: FtrProviderContext) { offline: 1, updating: 1, other: 1, + inactive: 0, }, }); });