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] adding upgrade details UPG_FAILED check to stuck in updating #173628

Merged
merged 8 commits into from
Dec 21, 2023
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
15 changes: 10 additions & 5 deletions x-pack/plugins/fleet/common/services/agent_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ export const AGENT_UPDATING_TIMEOUT_HOURS = 2;

export function isStuckInUpdating(agent: Agent): boolean {
return (
agent.status === 'updating' &&
!!agent.upgrade_started_at &&
!agent.upgraded_at &&
Date.now() - Date.parse(agent.upgrade_started_at) >
AGENT_UPDATING_TIMEOUT_HOURS * 60 * 60 * 1000
(agent.status !== 'offline' && agent.active && isAgentInFailedUpgradeState(agent)) ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after the latest discussion here changed the logic to consider stuck in updating if upgrade failed, even though agent is back to online

(agent.status === 'updating' &&
!!agent.upgrade_started_at &&
!agent.upgraded_at &&
Date.now() - Date.parse(agent.upgrade_started_at) >
AGENT_UPDATING_TIMEOUT_HOURS * 60 * 60 * 1000)
);
}

export function isAgentInFailedUpgradeState(agent: Agent): boolean {
return agent.upgrade_details?.state === 'UPG_FAILED';
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,65 @@ describe('AgentHealth', () => {
true
);

utils.getByText('Agent may be stuck updating.');

act(() => {
fireEvent.click(utils.getByTestId('restartUpgradeBtn'));
});

utils.findByText('Upgrade Modal');
});

it('should render agent health with callout when agent has upgrade state failed', () => {
const { utils } = renderAgentHealth(
{
active: true,
status: 'online',
upgrade_started_at: '2022-11-21T12:27:24Z',
upgrade_details: {
state: 'UPG_FAILED',
},
} as any,
true
);

utils.getByText('Agent upgrade is stuck in failed state.');

utils.getByTestId('restartUpgradeBtn');
});

it('should not render agent health with callout when agent has upgrade state failed but offline', () => {
const { utils } = renderAgentHealth(
{
active: true,
status: 'offline',
upgrade_started_at: '2022-11-21T12:27:24Z',
upgrade_details: {
state: 'UPG_FAILED',
},
} as any,
true
);

expect(utils.queryByTestId('restartUpgradeBtn')).not.toBeInTheDocument();
});

it('should not render agent health with callout when agent has upgrade state failed but inactive', () => {
const { utils } = renderAgentHealth(
{
active: false,
status: 'unenrolled',
upgrade_started_at: '2022-11-21T12:27:24Z',
upgrade_details: {
state: 'UPG_FAILED',
},
} as any,
true
);

expect(utils.queryByTestId('restartUpgradeBtn')).not.toBeInTheDocument();
});

it('should not render agent health with callout when agent not stuck updating', () => {
const { utils } = renderAgentHealth(
{
Expand All @@ -58,6 +110,7 @@ describe('AgentHealth', () => {
);

expect(utils.queryByTestId('restartUpgradeBtn')).not.toBeInTheDocument();
expect(utils.queryByText('Agent may be stuck updating.')).not.toBeInTheDocument();
});

it('should not render agent health with callout when not from details', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { euiLightVars as euiVars } from '@kbn/ui-theme';

import {
getPreviousAgentStatusForOfflineAgents,
isAgentInFailedUpgradeState,
isStuckInUpdating,
} from '../../../../../../common/services/agent_status';

Expand Down Expand Up @@ -152,12 +153,19 @@ export const AgentHealth: React.FunctionComponent<Props> = ({ agent, fromDetails
<p>{lastCheckinText}</p>
<p>{lastCheckInMessageText}</p>
{isStuckInUpdating(agent) ? (
<p>
isAgentInFailedUpgradeState(agent) ? (
<FormattedMessage
id="xpack.fleet.agentHealth.restartUpgradeTooltipText"
defaultMessage="Agent may be stuck updating. Consider restarting the upgrade."
id="xpack.fleet.agentHealth.failedUpgradeTooltipText"
defaultMessage="Agent upgrade failed. Consider restarting the upgrade."
/>
</p>
) : (
<p>
<FormattedMessage
id="xpack.fleet.agentHealth.restartUpgradeTooltipText"
defaultMessage="Agent may be stuck updating. Consider restarting the upgrade."
/>
</p>
)
) : null}
</>
}
Expand All @@ -183,17 +191,27 @@ export const AgentHealth: React.FunctionComponent<Props> = ({ agent, fromDetails
size="m"
color="warning"
title={
<FormattedMessage
id="xpack.fleet.agentHealth.stuckUpdatingTitle"
defaultMessage="Agent may be stuck updating."
/>
isAgentInFailedUpgradeState(agent) ? (
<FormattedMessage
id="xpack.fleet.agentHealth.failedUpgradeTitle"
defaultMessage="Agent upgrade is stuck in failed state."
/>
) : (
<FormattedMessage
id="xpack.fleet.agentHealth.stuckUpdatingTitle"
defaultMessage="Agent may be stuck updating."
/>
)
}
>
<p>
<FormattedMessage
id="xpack.fleet.agentHealth.stuckUpdatingText"
defaultMessage="Agent has been updating for a while, and may be stuck. Consider restarting the upgrade. {learnMore}"
defaultMessage="{stuckMessage} Consider restarting the upgrade. {learnMore}"
values={{
stuckMessage: isAgentInFailedUpgradeState(agent)
? 'Agent upgrade failed.'
: 'Agent has been updating for a while, and may be stuck.',
learnMore: (
<div>
<EuiLink href={docLinks.links.fleet.upgradeElasticAgent} target="_blank">
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -16577,7 +16577,6 @@
"xpack.fleet.agentFlyout.standaloneRadioOption": "{standaloneMessage} – Exécutez un agent Elastic Agent de façon autonome pour le configurer et le mettre à jour manuellement sur l'hôte sur lequel il est installé.",
"xpack.fleet.agentHealth.checkinMessageText": "Dernier message de vérification : {lastCheckinMessage}",
"xpack.fleet.agentHealth.checkInTooltipText": "Dernier archivage le {lastCheckIn}",
"xpack.fleet.agentHealth.stuckUpdatingText": "L'agent effectue la mise à jour depuis un certain temps ; il est peut-être bloqué. Envisagez de redémarrer la mise à niveau. {learnMore}",
"xpack.fleet.agentList.noFilteredAgentsPrompt": "Aucun agent trouvé. {clearFiltersLink}",
"xpack.fleet.agentLogs.logDisabledCallOutDescription": "Mettez à jour la politique de l'agent {settingsLink} pour activer la collecte de logs.",
"xpack.fleet.agentLogs.oldAgentWarningTitle": "La vue Logs requiert Elastic Agent 7.11 ou une version ultérieure. Pour mettre à niveau un agent, accédez au menu Actions ou {downloadLink} une version plus récente.",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -16590,7 +16590,6 @@
"xpack.fleet.agentFlyout.standaloneRadioOption": "{standaloneMessage} – Elasticエージェントをスタンドアロンで実行して、エージェントがインストールされているホストで、手動でエージェントを構成および更新します。",
"xpack.fleet.agentHealth.checkinMessageText": "前回のチェックインメッセージ:{lastCheckinMessage}",
"xpack.fleet.agentHealth.checkInTooltipText": "前回確認日時:{lastCheckIn}",
"xpack.fleet.agentHealth.stuckUpdatingText": "エージェントはしばらく更新が止まっている可能性があります。アップグレードの再開を検討してください。{learnMore}",
"xpack.fleet.agentList.noFilteredAgentsPrompt": "エージェントが見つかりません。{clearFiltersLink}",
"xpack.fleet.agentLogs.logDisabledCallOutDescription": "エージェントのポリシー{settingsLink}を更新して、ログ収集を有効にします。",
"xpack.fleet.agentLogs.oldAgentWarningTitle": "ログの表示には、Elastic Agent 7.11以降が必要です。エージェントをアップグレードするには、[アクション]メニューに移動するか、新しいバージョンを{downloadLink}。",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -16590,7 +16590,6 @@
"xpack.fleet.agentFlyout.standaloneRadioOption": "{standaloneMessage} – 独立运行 Elastic 代理,以在安装代理的主机上手动配置和更新代理。",
"xpack.fleet.agentHealth.checkinMessageText": "上次签入消息:{lastCheckinMessage}",
"xpack.fleet.agentHealth.checkInTooltipText": "上次签入时间 {lastCheckIn}",
"xpack.fleet.agentHealth.stuckUpdatingText": "代理已更新一段时间,并可能陷入停滞。请考虑重新开始升级。{learnMore}",
"xpack.fleet.agentList.noFilteredAgentsPrompt": "找不到代理。{clearFiltersLink}",
"xpack.fleet.agentLogs.logDisabledCallOutDescription": "更新代理的策略 {settingsLink} 以启用日志收集。",
"xpack.fleet.agentLogs.oldAgentWarningTitle": "“日志”视图需要 Elastic Agent 7.11 或更高版本。要升级代理,请前往“操作”菜单或{downloadLink}更新的版本。",
Expand Down