From e4680f9fb8ac44858e251f9f5c53c4d4f02b7e72 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Wed, 15 Jul 2020 14:24:27 -0400 Subject: [PATCH 1/4] [Ingest Manager] Do not show enrolling and unenrolling agents as online in agents counter --- .../common/services/agent_status.ts | 20 +++++++++++-------- .../common/types/rest_spec/agent.ts | 1 + .../sections/fleet/components/donut_chart.tsx | 2 +- .../sections/fleet/components/list_layout.tsx | 1 + .../server/services/agents/status.ts | 6 ++++-- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/ingest_manager/common/services/agent_status.ts b/x-pack/plugins/ingest_manager/common/services/agent_status.ts index 6489c30308771..d9e54d1159caf 100644 --- a/x-pack/plugins/ingest_manager/common/services/agent_status.ts +++ b/x-pack/plugins/ingest_manager/common/services/agent_status.ts @@ -4,11 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - AGENT_POLLING_THRESHOLD_MS, - AGENT_TYPE_PERMANENT, - AGENT_SAVED_OBJECT_TYPE, -} from '../constants'; +import { AGENT_POLLING_THRESHOLD_MS, AGENT_SAVED_OBJECT_TYPE } from '../constants'; import { Agent, AgentStatus } from '../types'; export function getAgentStatus(agent: Agent, now: number = Date.now()): AgentStatus { @@ -41,8 +37,16 @@ export function getAgentStatus(agent: Agent, now: number = Date.now()): AgentSta return 'online'; } +export function buildKueryForEnrolingAgents() { + return `not ${AGENT_SAVED_OBJECT_TYPE}.last_checkin:*`; +} + +export function buildKueryForUnenrolingAgents() { + return `${AGENT_SAVED_OBJECT_TYPE}.unenrollment_started_at:*`; +} + export function buildKueryForOnlineAgents() { - return `not (${buildKueryForOfflineAgents()}) AND not (${buildKueryForErrorAgents()})`; + return `not (${buildKueryForOfflineAgents()}) AND not (${buildKueryForErrorAgents()}) AND not (${buildKueryForEnrolingAgents()}) AND not (${buildKueryForUnenrolingAgents()})`; } export function buildKueryForErrorAgents() { @@ -50,7 +54,7 @@ export function buildKueryForErrorAgents() { } export function buildKueryForOfflineAgents() { - return `((${AGENT_SAVED_OBJECT_TYPE}.type:${AGENT_TYPE_PERMANENT} AND ${AGENT_SAVED_OBJECT_TYPE}.last_checkin < now-${ + return `${AGENT_SAVED_OBJECT_TYPE}.last_checkin < now-${ (4 * AGENT_POLLING_THRESHOLD_MS) / 1000 - }s) AND not ( ${buildKueryForErrorAgents()} ))`; + }s AND not (${buildKueryForErrorAgents()})`; } diff --git a/x-pack/plugins/ingest_manager/common/types/rest_spec/agent.ts b/x-pack/plugins/ingest_manager/common/types/rest_spec/agent.ts index ed7d73ab0b719..7ec5a8d68311f 100644 --- a/x-pack/plugins/ingest_manager/common/types/rest_spec/agent.ts +++ b/x-pack/plugins/ingest_manager/common/types/rest_spec/agent.ts @@ -173,5 +173,6 @@ export interface GetAgentStatusResponse { online: number; error: number; offline: number; + other: number; }; } diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/donut_chart.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/donut_chart.tsx index bfa9c80f12851..57ef70e8f2739 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/donut_chart.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/donut_chart.tsx @@ -31,7 +31,7 @@ export const DonutChart = ({ height, width, data }: DonutChartProps) => { .ordinal() // @ts-ignore .domain(data) - .range(['#017D73', '#98A2B3', '#BD271E']); + .range(['#017D73', '#98A2B3', '#BD271E', '#9b6900']); const pieGenerator = d3.layout .pie() .value(({ value }: any) => value) diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/list_layout.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/list_layout.tsx index 46190033d4d6b..16acda9dc4afd 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/list_layout.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/list_layout.tsx @@ -66,6 +66,7 @@ export const ListLayout: React.FunctionComponent<{}> = ({ children }) => { online: agentStatus?.online || 0, offline: agentStatus?.offline || 0, error: agentStatus?.error || 0, + other: agentStatus?.other || 0, }} /> diff --git a/x-pack/plugins/ingest_manager/server/services/agents/status.ts b/x-pack/plugins/ingest_manager/server/services/agents/status.ts index 016a2344cf532..86336714a511e 100644 --- a/x-pack/plugins/ingest_manager/server/services/agents/status.ts +++ b/x-pack/plugins/ingest_manager/server/services/agents/status.ts @@ -25,9 +25,10 @@ export async function getAgentStatusForConfig( soClient: SavedObjectsClientContract, configId?: string ) { - const [all, error, offline] = await Promise.all( + const [all, online, error, offline] = await Promise.all( [ undefined, + AgentStatusKueryHelper.buildKueryForOnlineAgents(), AgentStatusKueryHelper.buildKueryForErrorAgents(), AgentStatusKueryHelper.buildKueryForOfflineAgents(), ].map((kuery) => @@ -47,9 +48,10 @@ export async function getAgentStatusForConfig( return { events: await getEventsCount(soClient, configId), total: all.total, - online: all.total - error.total - offline.total, + online: online.total, error: error.total, offline: offline.total, + other: all.total - online.total - error.total - offline.total, }; } From 7ee7fec9a19aca0dc751aaa6d3b7f86c3b97bc67 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Wed, 15 Jul 2020 15:39:00 -0400 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: Jen Huang --- x-pack/plugins/ingest_manager/common/services/agent_status.ts | 4 ++-- .../ingest_manager/sections/fleet/components/donut_chart.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/ingest_manager/common/services/agent_status.ts b/x-pack/plugins/ingest_manager/common/services/agent_status.ts index d9e54d1159caf..51b1a09767a32 100644 --- a/x-pack/plugins/ingest_manager/common/services/agent_status.ts +++ b/x-pack/plugins/ingest_manager/common/services/agent_status.ts @@ -37,11 +37,11 @@ export function getAgentStatus(agent: Agent, now: number = Date.now()): AgentSta return 'online'; } -export function buildKueryForEnrolingAgents() { +export function buildKueryForEnrollingAgents() { return `not ${AGENT_SAVED_OBJECT_TYPE}.last_checkin:*`; } -export function buildKueryForUnenrolingAgents() { +export function buildKueryForUnenrollingAgents() { return `${AGENT_SAVED_OBJECT_TYPE}.unenrollment_started_at:*`; } diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/donut_chart.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/donut_chart.tsx index 57ef70e8f2739..99a4f27b428fe 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/donut_chart.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/donut_chart.tsx @@ -31,7 +31,7 @@ export const DonutChart = ({ height, width, data }: DonutChartProps) => { .ordinal() // @ts-ignore .domain(data) - .range(['#017D73', '#98A2B3', '#BD271E', '#9b6900']); + .range(['#017D73', '#98A2B3', '#BD271E', '#F5A700']); const pieGenerator = d3.layout .pie() .value(({ value }: any) => value) From b2b34dd5474f90dbef34feea591143441355d2fd Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Thu, 16 Jul 2020 08:24:36 -0400 Subject: [PATCH 3/4] Fix types --- x-pack/plugins/ingest_manager/common/services/agent_status.ts | 2 +- .../management/pages/policy/store/policy_details/reducer.ts | 1 + .../public/management/pages/policy/store/policy_list/reducer.ts | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/ingest_manager/common/services/agent_status.ts b/x-pack/plugins/ingest_manager/common/services/agent_status.ts index 51b1a09767a32..536003b0f743d 100644 --- a/x-pack/plugins/ingest_manager/common/services/agent_status.ts +++ b/x-pack/plugins/ingest_manager/common/services/agent_status.ts @@ -46,7 +46,7 @@ export function buildKueryForUnenrollingAgents() { } export function buildKueryForOnlineAgents() { - return `not (${buildKueryForOfflineAgents()}) AND not (${buildKueryForErrorAgents()}) AND not (${buildKueryForEnrolingAgents()}) AND not (${buildKueryForUnenrolingAgents()})`; + return `not (${buildKueryForOfflineAgents()}) AND not (${buildKueryForErrorAgents()}) AND not (${buildKueryForEnrollingAgents()}) AND not (${buildKueryForUnenrollingAgents()})`; } export function buildKueryForErrorAgents() { diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/reducer.ts b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/reducer.ts index b3b74c2ca9dae..e7aa2c8893f8e 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/reducer.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/reducer.ts @@ -21,6 +21,7 @@ export const initialPolicyDetailsState: () => Immutable = () offline: 0, online: 0, total: 0, + other: 0, }, }); diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_list/reducer.ts b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_list/reducer.ts index 52bed8d850ef4..53954449ab9c3 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_list/reducer.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_list/reducer.ts @@ -31,6 +31,7 @@ export const initialPolicyListState: () => Immutable = () => ({ offline: 0, online: 0, total: 0, + other: 0, }, }); From 1973c9f815440e88a4c0fb7904b8f7fe7e2dea25 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Thu, 16 Jul 2020 13:48:20 -0400 Subject: [PATCH 4/4] Fix tests --- .../management/pages/policy/store/policy_list/index.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_list/index.test.ts b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_list/index.test.ts index 0a24c9eea71eb..8203aae244f24 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_list/index.test.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_list/index.test.ts @@ -152,6 +152,7 @@ describe('policy list store concerns', () => { offline: 0, online: 0, total: 0, + other: 0, }, }); });