Skip to content

Commit

Permalink
[Ingest Manager] Do not show enrolling and unenrolling agents as onli…
Browse files Browse the repository at this point in the history
…ne in agent counters (elastic#71921)
  • Loading branch information
nchaulet authored and chrisronline committed Jul 17, 2020
1 parent 67f467c commit ef11c95
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 11 deletions.
20 changes: 12 additions & 8 deletions x-pack/plugins/ingest_manager/common/services/agent_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -41,16 +37,24 @@ export function getAgentStatus(agent: Agent, now: number = Date.now()): AgentSta
return 'online';
}

export function buildKueryForEnrollingAgents() {
return `not ${AGENT_SAVED_OBJECT_TYPE}.last_checkin:*`;
}

export function buildKueryForUnenrollingAgents() {
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 (${buildKueryForEnrollingAgents()}) AND not (${buildKueryForUnenrollingAgents()})`;
}

export function buildKueryForErrorAgents() {
return `( ${AGENT_SAVED_OBJECT_TYPE}.last_checkin_status:error or ${AGENT_SAVED_OBJECT_TYPE}.last_checkin_status:degraded )`;
}

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()})`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,6 @@ export interface GetAgentStatusResponse {
online: number;
error: number;
offline: number;
other: number;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const DonutChart = ({ height, width, data }: DonutChartProps) => {
.ordinal()
// @ts-ignore
.domain(data)
.range(['#017D73', '#98A2B3', '#BD271E']);
.range(['#017D73', '#98A2B3', '#BD271E', '#F5A700']);
const pieGenerator = d3.layout
.pie()
.value(({ value }: any) => value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}}
/>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const initialPolicyDetailsState: () => Immutable<PolicyDetailsState> = ()
offline: 0,
online: 0,
total: 0,
other: 0,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ describe('policy list store concerns', () => {
offline: 0,
online: 0,
total: 0,
other: 0,
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const initialPolicyListState: () => Immutable<PolicyListState> = () => ({
offline: 0,
online: 0,
total: 0,
other: 0,
},
});

Expand Down

0 comments on commit ef11c95

Please sign in to comment.