From 4c1bf865d02ce0c1eb20d398db545dc9fcb5dd92 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Tue, 11 May 2021 10:41:29 -0400 Subject: [PATCH 1/4] [Fleet] Improve fleet server upgrade modal --- .../components/fleet_server_upgrade_modal.tsx | 70 ++++++++++++++++++- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_upgrade_modal.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_upgrade_modal.tsx index 4d6ac864ee8b5..5fb0fe693b6cc 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_upgrade_modal.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_upgrade_modal.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import React, { useCallback, useState } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import { EuiButton, EuiCheckbox, @@ -24,7 +24,15 @@ import { import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import { sendPutSettings, useLink, useStartServices } from '../../../hooks'; +import { + sendGetAgents, + sendGetOneAgentPolicy, + sendPutSettings, + useLink, + useStartServices, +} from '../../../hooks'; +import type { PackagePolicy } from '../../../types'; +import { FLEET_SERVER_PACKAGE } from '../../../constants'; interface Props { onClose: () => void; @@ -37,6 +45,58 @@ export const FleetServerUpgradeModal: React.FunctionComponent = ({ onClos const isCloud = !!cloud?.cloudId; const [checked, setChecked] = useState(false); + const [isAgentsAndPoliciesLoaded, setAgentsAndPoliciesLoaded] = useState(false); + + // Check if an other agent than the fleet server is already enrolled + useEffect(() => { + async function check() { + try { + const agentPoliciesAlreadyChecked: { [k: string]: boolean } = {}; + + const res = await sendGetAgents({ + page: 1, + perPage: 10, + showInactive: false, + }); + + if (res.error) { + throw res.error; + } + + for (const agent of res.data?.list ?? []) { + if (agent.policy_id) { + if (!agentPoliciesAlreadyChecked[agent.policy_id]) { + agentPoliciesAlreadyChecked[agent.policy_id] = true; + const policyRes = await sendGetOneAgentPolicy(agent.policy_id); + const hasFleetServer = + (policyRes.data?.item.package_policies as PackagePolicy[]).some( + (p: PackagePolicy) => { + return p.package?.name === FLEET_SERVER_PACKAGE; + } + ) ?? false; + if (!hasFleetServer) { + await sendPutSettings({ + has_seen_fleet_migration_notice: true, + }); + onClose(); + return; + } + } + } + } + setAgentsAndPoliciesLoaded(true); + } catch (err) { + notifications.toasts.addError(err, { + title: i18n.translate('xpack.fleet.fleetServerUpgradeModal.errorLoadingAgents', { + defaultMessage: `Error loading agents`, + }), + }); + } + } + + check(); + }, [setAgentsAndPoliciesLoaded, notifications.toasts, onClose]); + const onChange = useCallback(async () => { try { setChecked(!checked); @@ -52,6 +112,10 @@ export const FleetServerUpgradeModal: React.FunctionComponent = ({ onClos } }, [checked, setChecked, notifications]); + if (!isAgentsAndPoliciesLoaded) { + return null; + } + return ( @@ -74,7 +138,7 @@ export const FleetServerUpgradeModal: React.FunctionComponent = ({ onClos {isCloud ? ( From 752038f8000646d1412379f0ad0347697fe116be Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Tue, 11 May 2021 14:17:33 -0400 Subject: [PATCH 2/4] Update fleet server upgrade copy --- .../components/fleet_server_upgrade_modal.tsx | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_upgrade_modal.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_upgrade_modal.tsx index 5fb0fe693b6cc..87511cc29636c 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_upgrade_modal.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_upgrade_modal.tsx @@ -122,12 +122,13 @@ export const FleetServerUpgradeModal: React.FunctionComponent = ({ onClos = ({ onClos {isCloud ? ( @@ -148,17 +149,6 @@ export const FleetServerUpgradeModal: React.FunctionComponent = ({ onClos /> ), - link: ( - - - - ), }} /> ) : ( From a6a9538dbddc974f3d009aaa382d8001e08f1a49 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Tue, 11 May 2021 14:38:33 -0400 Subject: [PATCH 3/4] Fix i18n --- x-pack/plugins/translations/translations/ja-JP.json | 1 - x-pack/plugins/translations/translations/zh-CN.json | 1 - 2 files changed, 2 deletions(-) diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index a2eb51e929fd4..f1d6d37fcb0cc 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -9513,7 +9513,6 @@ "xpack.fleet.fleetServerUpgradeModal.breakingChangeMessage": "これは大きい変更であるため、ベータリリースにしています。ご不便をおかけしていることをお詫び申し上げます。ご質問がある場合や、サポートが必要な場合は、{link}を共有してください。", "xpack.fleet.fleetServerUpgradeModal.checkboxLabel": "次回以降このメッセージを表示しない", "xpack.fleet.fleetServerUpgradeModal.closeButton": "閉じて開始する", - "xpack.fleet.fleetServerUpgradeModal.cloudDescriptionMessage": "Fleetサーバーを使用できます。スケーラビリティとセキュリティが強化されました。すでにElastic CloudでAPMを使用している場合は、APM & Fleetにアップグレードされました。{existingAgentsMessage} Fleetを使用し続けるには、Fleetサーバーと新しいバージョンのElasticエージェントを各ホストにインストールする必要があります。詳細については、{link}をご覧ください。", "xpack.fleet.fleetServerUpgradeModal.existingAgentText": "既存のElasticエージェントは自動的に登録解除され、データの送信を停止しました。", "xpack.fleet.fleetServerUpgradeModal.failedUpdateTitle": "設定の保存エラー", "xpack.fleet.fleetServerUpgradeModal.fleetFeedbackLink": "フィードバック", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index b07661eaf5e26..7aeaeddc65045 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -9602,7 +9602,6 @@ "xpack.fleet.fleetServerUpgradeModal.breakingChangeMessage": "这是一项重大更改,所以我们在公测版中进行该更改。非常抱歉带来不便。如果您有疑问或需要帮助,请共享 {link}。", "xpack.fleet.fleetServerUpgradeModal.checkboxLabel": "不再显示此消息", "xpack.fleet.fleetServerUpgradeModal.closeButton": "关闭并开始使用", - "xpack.fleet.fleetServerUpgradeModal.cloudDescriptionMessage": "Fleet 服务器现在可用并提供改善的可扩展性和安全性。如果在 Elastic Cloud 上已有 APM,则我们已将其升级到 APM & Fleet。{existingAgentsMessage}要继续使用 Fleet,必须在各个主机上安装 Fleet 服务器和新版 Elastic 代理。详细了解我们的 {link}。", "xpack.fleet.fleetServerUpgradeModal.existingAgentText": "您现有的 Elastic 代理已被自动销注且已停止发送数据。", "xpack.fleet.fleetServerUpgradeModal.failedUpdateTitle": "保存设置时出错", "xpack.fleet.fleetServerUpgradeModal.fleetFeedbackLink": "反馈", From 51107817b9a7872c5563b83bd7579662723426f3 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Thu, 13 May 2021 14:25:12 -0400 Subject: [PATCH 4/4] Fix after review --- .../components/fleet_server_upgrade_modal.tsx | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_upgrade_modal.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_upgrade_modal.tsx index 87511cc29636c..ede997f185c7e 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_upgrade_modal.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_upgrade_modal.tsx @@ -64,24 +64,22 @@ export const FleetServerUpgradeModal: React.FunctionComponent = ({ onClos } for (const agent of res.data?.list ?? []) { - if (agent.policy_id) { - if (!agentPoliciesAlreadyChecked[agent.policy_id]) { - agentPoliciesAlreadyChecked[agent.policy_id] = true; - const policyRes = await sendGetOneAgentPolicy(agent.policy_id); - const hasFleetServer = - (policyRes.data?.item.package_policies as PackagePolicy[]).some( - (p: PackagePolicy) => { - return p.package?.name === FLEET_SERVER_PACKAGE; - } - ) ?? false; - if (!hasFleetServer) { - await sendPutSettings({ - has_seen_fleet_migration_notice: true, - }); - onClose(); - return; - } - } + if (!agent.policy_id || agentPoliciesAlreadyChecked[agent.policy_id]) { + continue; + } + + agentPoliciesAlreadyChecked[agent.policy_id] = true; + const policyRes = await sendGetOneAgentPolicy(agent.policy_id); + const hasFleetServer = + (policyRes.data?.item.package_policies as PackagePolicy[]).some((p: PackagePolicy) => { + return p.package?.name === FLEET_SERVER_PACKAGE; + }) ?? false; + if (!hasFleetServer) { + await sendPutSettings({ + has_seen_fleet_migration_notice: true, + }); + onClose(); + return; } } setAgentsAndPoliciesLoaded(true); @@ -95,7 +93,7 @@ export const FleetServerUpgradeModal: React.FunctionComponent = ({ onClos } check(); - }, [setAgentsAndPoliciesLoaded, notifications.toasts, onClose]); + }, [notifications.toasts, onClose]); const onChange = useCallback(async () => { try {