Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Move agent status server side and API to get aggregated statu… #51673

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion x-pack/legacy/plugins/fleet/common/types/domain_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ export interface ConfigurationBlock
id: string;
}

export type Agent = t.TypeOf<typeof RuntimeAgent>;
export type AgentStatus = 'offline' | 'error' | 'online' | 'inactive' | 'warning';

export type Agent = t.TypeOf<typeof RuntimeAgent> & {
status: AgentStatus;
};
export type AgentAction = t.TypeOf<typeof RuntimeAgentAction>;
export type AgentEvent = t.TypeOf<typeof RuntimeAgentEvent>;

Expand Down
53 changes: 18 additions & 35 deletions x-pack/legacy/plugins/fleet/public/components/agent_health.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
import React from 'react';
import { FormattedMessage, FormattedRelative } from '@kbn/i18n/react';
import { EuiHealth, EuiToolTip } from '@elastic/eui';
import {
AGENT_TYPE_PERMANENT,
AGENT_TYPE_TEMPORARY,
AGENT_POLLING_THRESHOLD_MS,
} from '../../common/constants';
import { Agent } from '../../common/types/domain_data';

interface Props {
Expand Down Expand Up @@ -40,41 +35,29 @@ const Status = {
),
Error: (
<EuiHealth color="danger">
<FormattedMessage id="xpack.fleet.agentHealth.errorStatusText" defaultMessage="Offline" />
<FormattedMessage id="xpack.fleet.agentHealth.errorStatusText" defaultMessage="Error" />
</EuiHealth>
),
};

function getStatusComponent(agent: Agent): React.ReactElement {
switch (agent.status) {
case 'error':
return Status.Error;
case 'inactive':
return Status.Inactive;
case 'offline':
return Status.Offline;
case 'warning':
return Status.Warning;
default:
return Status.Online;
}
}

export const AgentHealth: React.SFC<Props> = ({ agent }) => {
// TODO: Use agent events as part of health calculation once we have them;
// until then, we just use last check in time
const { type, last_checkin: lastCheckIn } = agent;
const { last_checkin: lastCheckIn } = agent;
const msLastCheckIn = new Date(lastCheckIn || 0).getTime();
const msSinceLastCheckIn = new Date().getTime() - msLastCheckIn;
const intervalsSinceLastCheckIn = Math.floor(msSinceLastCheckIn / AGENT_POLLING_THRESHOLD_MS);

let status: React.ReactElement = Status.Online;

if (!agent.active) {
status = Status.Inactive;
} else {
switch (type) {
case AGENT_TYPE_PERMANENT:
if (intervalsSinceLastCheckIn >= 4) {
status = Status.Error;
break;
}
if (intervalsSinceLastCheckIn >= 2) {
status = Status.Warning;
break;
}
case AGENT_TYPE_TEMPORARY:
if (intervalsSinceLastCheckIn >= 3) {
status = Status.Offline;
break;
}
}
}

return (
<EuiToolTip
Expand All @@ -96,7 +79,7 @@ export const AgentHealth: React.SFC<Props> = ({ agent }) => {
)
}
>
{status}
{getStatusComponent(agent)}
</EuiToolTip>
);
};
Loading