Skip to content

Commit

Permalink
allow agent to report error and degraded status
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Jul 7, 2020
1 parent 357d203 commit 668988f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ export function getAgentStatus(agent: Agent, now: number = Date.now()): AgentSta
if (agent.unenrollment_started_at && !agent.unenrolled_at) {
return 'unenrolling';
}
if (agent.current_error_events.length > 0) {
if (agent.last_checkin_status === 'error') {
return 'error';
}
if (agent.last_checkin_status === 'degraded') {
return 'degraded';
}
if (intervalsSinceLastCheckIn >= 4) {
return 'offline';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ const Status = {
/>
</EuiHealth>
),
Degraded: (
<EuiHealth color="danger">
<FormattedMessage
id="xpack.ingestManager.agentHealth.degradedStatusText"
defaultMessage="Degraded"
/>
</EuiHealth>
),
Enrolling: (
<EuiHealth color="warning">
<FormattedMessage
Expand All @@ -75,6 +83,8 @@ function getStatusComponent(agent: Agent): React.ReactElement {
switch (agent.status) {
case 'error':
return Status.Error;
case 'degraded':
return Status.Degraded;
case 'inactive':
return Status.Inactive;
case 'offline':
Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/ingest_manager/server/routes/agent/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,11 @@ export const postAgentCheckinHandler: RequestHandler<
const { actions } = await AgentService.agentCheckin(
soClient,
agent,
request.body.events || [],
request.body.local_metadata,
{
events: request.body.events || [],
localMetadata: request.body.local_metadata,
status: request.body.status,
},
{ signal }
);
const body: PostAgentCheckinResponse = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
AgentEvent,
AgentSOAttributes,
AgentEventSOAttributes,
AgentMetadata,
} from '../../../types';

import { AGENT_SAVED_OBJECT_TYPE, AGENT_EVENT_SAVED_OBJECT_TYPE } from '../../../constants';
Expand All @@ -21,20 +20,24 @@ import { getAgentActionsForCheckin } from '../actions';
export async function agentCheckin(
soClient: SavedObjectsClientContract,
agent: Agent,
events: NewAgentEvent[],
localMetadata?: any,
data: {
events: NewAgentEvent[];
localMetadata?: any;
status?: 'online' | 'error' | 'degraded';
},
options?: { signal: AbortSignal }
) {
const updateData: {
local_metadata?: AgentMetadata;
current_error_events?: string;
} = {};
const { updatedErrorEvents } = await processEventsForCheckin(soClient, agent, events);
const updateData: Partial<AgentSOAttributes> = {};
const { updatedErrorEvents } = await processEventsForCheckin(soClient, agent, data.events);
if (updatedErrorEvents) {
updateData.current_error_events = JSON.stringify(updatedErrorEvents);
}
if (localMetadata) {
updateData.local_metadata = localMetadata;
if (data.localMetadata) {
updateData.local_metadata = data.localMetadata;
}

if (data.status !== agent.last_checkin_status) {
updateData.last_checkin_status = data.status;
}
if (Object.keys(updateData).length > 0) {
await soClient.update<AgentSOAttributes>(AGENT_SAVED_OBJECT_TYPE, agent.id, updateData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function agentCheckinStateConnectedAgentsFactory() {
const internalSOClient = getInternalUserSOClient();
const now = new Date().toISOString();
const updates: Array<SavedObjectsBulkUpdateObject<AgentSOAttributes>> = [
...connectedAgentsIds.values(),
...agentToUpdate.values(),
].map((agentId) => ({
type: AGENT_SAVED_OBJECT_TYPE,
id: agentId,
Expand Down

0 comments on commit 668988f

Please sign in to comment.