From 669d749fcae9be546c49e97ed512a78f9e28b3fb Mon Sep 17 00:00:00 2001 From: criamico Date: Wed, 18 May 2022 11:52:17 +0200 Subject: [PATCH 01/10] [Fleet] Changes to agent upgrade modal to allow for rolling upgrades --- .../components/bulk_actions.tsx | 8 +- .../agent_upgrade_modal/constants.tsx | 41 ++++++ .../components/agent_upgrade_modal/index.tsx | 129 ++++++++++++------ 3 files changed, 135 insertions(+), 43 deletions(-) create mode 100644 x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/bulk_actions.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/bulk_actions.tsx index a2515b51814ee..6a9562a958ef8 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/bulk_actions.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/bulk_actions.tsx @@ -24,7 +24,6 @@ import { AgentUnenrollAgentModal, AgentUpgradeAgentModal, } from '../../components'; -import { useKibanaVersion } from '../../../../hooks'; import type { SelectionMode } from './types'; @@ -48,11 +47,10 @@ export const AgentBulkActions: React.FunctionComponent = ({ selectedAgents, refreshAgents, }) => { - const kibanaVersion = useKibanaVersion(); // Bulk actions menu states const [isMenuOpen, setIsMenuOpen] = useState(false); const closeMenu = () => setIsMenuOpen(false); - const openMenu = () => setIsMenuOpen(true); + const onClickMenu = () => setIsMenuOpen(!isMenuOpen); // Actions states const [isReassignFlyoutOpen, setIsReassignFlyoutOpen] = useState(false); @@ -150,7 +148,7 @@ export const AgentBulkActions: React.FunctionComponent = ({ {isUpgradeModalOpen && ( { @@ -172,7 +170,7 @@ export const AgentBulkActions: React.FunctionComponent = ({ fill iconType="arrowDown" iconSide="right" - onClick={openMenu} + onClick={onClickMenu} data-test-subj="agentBulkActionsButton" > void; agents: Agent[] | string; agentCount: number; - version: string; } export const AgentUpgradeAgentModal: React.FunctionComponent = ({ onClose, agents, agentCount, - version, }) => { const { notifications } = useStartServices(); const [isSubmitting, setIsSubmitting] = useState(false); + const fallbackVersions: Array> = FALLBACK_VERSIONS.map((option) => ({ + label: option, + value: option, + })); + const maintainanceOptions: Array> = MAINTAINANCE_WINDOWS.map((option) => ({ + label: option, + value: option, + })); + const [selectedVersion, setSelectedVersion] = useState([fallbackVersions[0]]); + const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([maintainanceOptions[0]]); const isSingleAgent = Array.isArray(agents) && agents.length === 1; const isAllAgents = agents === ''; + + const getVersion = (selectedVersion: EuiComboBoxOptionOption[]) => selectedVersion[0].value as string; + async function onSubmit() { + const version = getVersion(selectedVersion); try { setIsSubmitting(true); const { data, error } = isSingleAgent @@ -114,39 +128,20 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ - - {isSingleAgent ? ( - - ) : ( - - )} - - - - } - tooltipContent={ - - } + <> + {isSingleAgent ? ( + - - + ) : ( + + )} + } onCancel={onClose} onConfirm={onSubmit} @@ -172,24 +167,82 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ ) } > -

+

{isSingleAgent ? ( ) : ( )}

+ + + >) => { + setSelectedVersion(selectedVersion); + }} + /> + + + + + {i18n.translate( + 'xpack.fleet.upgradeAgents.maintainanceAvailableLabel', + { + defaultMessage: 'Maintainance window available', + } + )} + + + + + + + + + } + fullWidth + > + >) => { + setSelectedMantainanceWindow(selectedMantainanceWindow); + }} + /> + +
); }; From f442fa9440cfa735d9ffedf36f423a0c7dc2e3cc Mon Sep 17 00:00:00 2001 From: criamico Date: Wed, 18 May 2022 14:38:45 +0200 Subject: [PATCH 02/10] Update the onSubmit logic and handle case with single agent --- .../fleet/common/types/rest_spec/agent.ts | 1 + .../components/actions_menu.tsx | 1 - .../sections/agents/agent_list_page/index.tsx | 1 - .../agent_upgrade_modal/constants.tsx | 14 ++-- .../components/agent_upgrade_modal/index.tsx | 79 ++++++++++--------- 5 files changed, 50 insertions(+), 46 deletions(-) diff --git a/x-pack/plugins/fleet/common/types/rest_spec/agent.ts b/x-pack/plugins/fleet/common/types/rest_spec/agent.ts index 7a8b7b918c1e3..d0348f87eadf8 100644 --- a/x-pack/plugins/fleet/common/types/rest_spec/agent.ts +++ b/x-pack/plugins/fleet/common/types/rest_spec/agent.ts @@ -89,6 +89,7 @@ export interface PostBulkAgentUpgradeRequest { agents: string[] | string; source_uri?: string; version: string; + rollout_duration_seconds: number }; } diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/actions_menu.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/actions_menu.tsx index 44e87d7fb4e63..239afe6c7e330 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/actions_menu.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/actions_menu.tsx @@ -70,7 +70,6 @@ export const AgentDetailsActionMenu: React.FunctionComponent<{ { setIsUpgradeModalOpen(false); refreshAgent(); diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx index be38f7688c735..d1a959d02a8c6 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx @@ -500,7 +500,6 @@ export const AgentListPage: React.FunctionComponent<{}> = () => { setAgentToUpgrade(undefined); fetchData(); }} - version={kibanaVersion} />
)} diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx index e8e34307e72ee..edebdefe8af0d 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx @@ -31,11 +31,11 @@ export const FALLBACK_VERSIONS = [ ]; export const MAINTAINANCE_WINDOWS = [ - '1 hour', - '2 hours', - '4 hours', - '8 hours', - '12 hours', - '24 hours', - '48 hours', + 1, + 2, + 4, + 8, + 12, + 24, + 48 ]; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx index e2000838d2f23..3c9f35abe05a0 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx @@ -37,8 +37,8 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ value: option, })); const maintainanceOptions: Array> = MAINTAINANCE_WINDOWS.map((option) => ({ - label: option, - value: option, + label: option === 1 ? `${option} hour` : `${option} hours`, + value: `${option * 3600}` })); const [selectedVersion, setSelectedVersion] = useState([fallbackVersions[0]]); const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([maintainanceOptions[0]]); @@ -46,6 +46,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ const isAllAgents = agents === ''; const getVersion = (selectedVersion: EuiComboBoxOptionOption[]) => selectedVersion[0].value as string; + const getRolloutDuration = (selectedMantainanceWindow: EuiComboBoxOptionOption[]) => Number(selectedMantainanceWindow[0].value) async function onSubmit() { const version = getVersion(selectedVersion); @@ -58,6 +59,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ : await sendPostBulkAgentUpgrade({ agents: Array.isArray(agents) ? agents.map((agent) => agent.id) : agents, version, + rollout_duration_seconds: getRolloutDuration(selectedMantainanceWindow) }); if (error) { throw error; @@ -206,42 +208,45 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ /> - - - {i18n.translate( - 'xpack.fleet.upgradeAgents.maintainanceAvailableLabel', - { - defaultMessage: 'Maintainance window available', - } - )} - - - - - - - - - } - fullWidth - > - + + {i18n.translate( + 'xpack.fleet.upgradeAgents.maintainanceAvailableLabel', + { + defaultMessage: 'Maintainance window available', + } + )} + + + + + + + + + } fullWidth - singleSelection={{ asPlainText: true }} - options={maintainanceOptions} - selectedOptions={selectedMantainanceWindow} - onChange={(selectedMantainanceWindow: Array>) => { - setSelectedMantainanceWindow(selectedMantainanceWindow); - }} - /> - + > + >) => { + setSelectedMantainanceWindow(selectedMantainanceWindow); + }} + /> + + : null + } ); From 40c45d02edfad6d0c1791058a7795c3e13b8a9a2 Mon Sep 17 00:00:00 2001 From: criamico Date: Wed, 18 May 2022 14:53:47 +0200 Subject: [PATCH 03/10] Fix check --- .../agents/components/agent_upgrade_modal/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx index 3c9f35abe05a0..73c6eebf57375 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx @@ -202,8 +202,8 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ singleSelection={{ asPlainText: true }} options={fallbackVersions} selectedOptions={selectedVersion} - onChange={(selectedVersion: Array>) => { - setSelectedVersion(selectedVersion); + onChange={(selected: Array>) => { + setSelectedVersion(selected); }} /> @@ -240,8 +240,8 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ singleSelection={{ asPlainText: true }} options={maintainanceOptions} selectedOptions={selectedMantainanceWindow} - onChange={(selectedMantainanceWindow: Array>) => { - setSelectedMantainanceWindow(selectedMantainanceWindow); + onChange={(selected: Array>) => { + setSelectedMantainanceWindow(selected); }} /> From 62086a9d0348ac1e3407e193759e146b5d686819 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 18 May 2022 13:44:10 +0000 Subject: [PATCH 04/10] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../fleet/common/types/rest_spec/agent.ts | 2 +- .../agent_upgrade_modal/constants.tsx | 45 ++++----- .../components/agent_upgrade_modal/index.tsx | 93 +++++++++++-------- 3 files changed, 73 insertions(+), 67 deletions(-) diff --git a/x-pack/plugins/fleet/common/types/rest_spec/agent.ts b/x-pack/plugins/fleet/common/types/rest_spec/agent.ts index d0348f87eadf8..a7cf312e9f929 100644 --- a/x-pack/plugins/fleet/common/types/rest_spec/agent.ts +++ b/x-pack/plugins/fleet/common/types/rest_spec/agent.ts @@ -89,7 +89,7 @@ export interface PostBulkAgentUpgradeRequest { agents: string[] | string; source_uri?: string; version: string; - rollout_duration_seconds: number + rollout_duration_seconds: number; }; } diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx index edebdefe8af0d..7e50b1e7e8151 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx @@ -1,4 +1,3 @@ - /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License @@ -11,31 +10,23 @@ // in the event that the updated versions cannot be retrieved from the endpoint export const FALLBACK_VERSIONS = [ - "7.17.0", - "7.17.1", - "7.17.2", - "7.17.3", - "7.8.0", - "7.8.1", - "7.9.0", - "7.9.1", - "7.9.2", - "7.9.3", - "8.0.0", - "8.0.1", - "8.1.0", - "8.1.1", - "8.1.2", - "8.1.3", - "8.2.0", + '7.17.0', + '7.17.1', + '7.17.2', + '7.17.3', + '7.8.0', + '7.8.1', + '7.9.0', + '7.9.1', + '7.9.2', + '7.9.3', + '8.0.0', + '8.0.1', + '8.1.0', + '8.1.1', + '8.1.2', + '8.1.3', + '8.2.0', ]; -export const MAINTAINANCE_WINDOWS = [ - 1, - 2, - 4, - 8, - 12, - 24, - 48 -]; +export const MAINTAINANCE_WINDOWS = [1, 2, 4, 8, 12, 24, 48]; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx index 73c6eebf57375..6fe07aac78624 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx @@ -7,16 +7,27 @@ import React, { useState } from 'react'; import { i18n } from '@kbn/i18n'; -import { EuiConfirmModal, EuiComboBox, EuiFormRow, EuiSpacer, EuiToolTip, EuiIcon, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; +import { + EuiConfirmModal, + EuiComboBox, + EuiFormRow, + EuiSpacer, + EuiToolTip, + EuiIcon, + EuiFlexGroup, + EuiFlexItem, +} from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; import type { EuiComboBoxOptionOption } from '@elastic/eui'; + import type { Agent } from '../../../../types'; import { sendPostAgentUpgrade, sendPostBulkAgentUpgrade, useStartServices, } from '../../../../hooks'; + import { FALLBACK_VERSIONS, MAINTAINANCE_WINDOWS } from './constants'; interface Props { @@ -32,21 +43,29 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ }) => { const { notifications } = useStartServices(); const [isSubmitting, setIsSubmitting] = useState(false); - const fallbackVersions: Array> = FALLBACK_VERSIONS.map((option) => ({ - label: option, - value: option, - })); - const maintainanceOptions: Array> = MAINTAINANCE_WINDOWS.map((option) => ({ - label: option === 1 ? `${option} hour` : `${option} hours`, - value: `${option * 3600}` - })); + const fallbackVersions: Array> = FALLBACK_VERSIONS.map( + (option) => ({ + label: option, + value: option, + }) + ); + const maintainanceOptions: Array> = MAINTAINANCE_WINDOWS.map( + (option) => ({ + label: option === 1 ? `${option} hour` : `${option} hours`, + value: `${option * 3600}`, + }) + ); const [selectedVersion, setSelectedVersion] = useState([fallbackVersions[0]]); - const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([maintainanceOptions[0]]); + const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([ + maintainanceOptions[0], + ]); const isSingleAgent = Array.isArray(agents) && agents.length === 1; const isAllAgents = agents === ''; - const getVersion = (selectedVersion: EuiComboBoxOptionOption[]) => selectedVersion[0].value as string; - const getRolloutDuration = (selectedMantainanceWindow: EuiComboBoxOptionOption[]) => Number(selectedMantainanceWindow[0].value) + const getVersion = (selectedVersion: Array>) => + selectedVersion[0].value as string; + const getRolloutDuration = (selectedMantainanceWindow: Array>) => + Number(selectedMantainanceWindow[0].value); async function onSubmit() { const version = getVersion(selectedVersion); @@ -59,7 +78,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ : await sendPostBulkAgentUpgrade({ agents: Array.isArray(agents) ? agents.map((agent) => agent.id) : agents, version, - rollout_duration_seconds: getRolloutDuration(selectedMantainanceWindow) + rollout_duration_seconds: getRolloutDuration(selectedMantainanceWindow), }); if (error) { throw error; @@ -169,7 +188,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ ) } > -

+

{isSingleAgent ? ( = ({

= ({ /> - { !isSingleAgent ? + {!isSingleAgent ? ( - {i18n.translate( - 'xpack.fleet.upgradeAgents.maintainanceAvailableLabel', - { - defaultMessage: 'Maintainance window available', - } - )} + {i18n.translate('xpack.fleet.upgradeAgents.maintainanceAvailableLabel', { + defaultMessage: 'Maintainance window available', + })} - + - - } + + } fullWidth > = ({ }} /> - : null - } - + ) : null} ); }; From d03bd38f8727143fd23480e4369baa5ed3e5f4ef Mon Sep 17 00:00:00 2001 From: criamico Date: Wed, 18 May 2022 18:12:00 +0200 Subject: [PATCH 05/10] Add option to upgrade immediately; minor fixes --- .../fleet/common/types/rest_spec/agent.ts | 2 +- .../components/bulk_actions.tsx | 1 - .../agent_upgrade_modal/constants.tsx | 44 +++++++------ .../components/agent_upgrade_modal/index.tsx | 62 +++++++++++-------- 4 files changed, 62 insertions(+), 47 deletions(-) diff --git a/x-pack/plugins/fleet/common/types/rest_spec/agent.ts b/x-pack/plugins/fleet/common/types/rest_spec/agent.ts index a7cf312e9f929..82d5a779c2ed4 100644 --- a/x-pack/plugins/fleet/common/types/rest_spec/agent.ts +++ b/x-pack/plugins/fleet/common/types/rest_spec/agent.ts @@ -89,7 +89,7 @@ export interface PostBulkAgentUpgradeRequest { agents: string[] | string; source_uri?: string; version: string; - rollout_duration_seconds: number; + rollout_duration_seconds?: number }; } diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/bulk_actions.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/bulk_actions.tsx index 6a9562a958ef8..e27c647e25f70 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/bulk_actions.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/bulk_actions.tsx @@ -148,7 +148,6 @@ export const AgentBulkActions: React.FunctionComponent = ({ {isUpgradeModalOpen && ( { diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx index 7e50b1e7e8151..abdd6552742f1 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx @@ -10,23 +10,31 @@ // in the event that the updated versions cannot be retrieved from the endpoint export const FALLBACK_VERSIONS = [ - '7.17.0', - '7.17.1', - '7.17.2', - '7.17.3', - '7.8.0', - '7.8.1', - '7.9.0', - '7.9.1', - '7.9.2', - '7.9.3', - '8.0.0', - '8.0.1', - '8.1.0', - '8.1.1', - '8.1.2', - '8.1.3', - '8.2.0', + '8.2.0', + '8.1.3', + '8.1.2', + '8.1.1', + '8.1.0', + '8.0.1', + '8.0.0', + '7.9.3', + '7.9.2', + '7.9.1', + '7.9.0', + '7.8.1', + '7.8.0', + '7.17.3', + '7.17.2', + '7.17.1', + '7.17.0' ]; -export const MAINTAINANCE_WINDOWS = [1, 2, 4, 8, 12, 24, 48]; +export const MAINTAINANCE_VALUES = [ + 1, + 2, + 4, + 8, + 12, + 24, + 48 +]; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx index 6fe07aac78624..696a2a729d7d0 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx @@ -27,8 +27,7 @@ import { sendPostBulkAgentUpgrade, useStartServices, } from '../../../../hooks'; - -import { FALLBACK_VERSIONS, MAINTAINANCE_WINDOWS } from './constants'; +import { FALLBACK_VERSIONS, MAINTAINANCE_VALUES } from './constants'; interface Props { onClose: () => void; @@ -43,43 +42,51 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ }) => { const { notifications } = useStartServices(); const [isSubmitting, setIsSubmitting] = useState(false); - const fallbackVersions: Array> = FALLBACK_VERSIONS.map( - (option) => ({ - label: option, - value: option, - }) - ); - const maintainanceOptions: Array> = MAINTAINANCE_WINDOWS.map( - (option) => ({ - label: option === 1 ? `${option} hour` : `${option} hours`, - value: `${option * 3600}`, - }) - ); - const [selectedVersion, setSelectedVersion] = useState([fallbackVersions[0]]); - const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([ - maintainanceOptions[0], - ]); const isSingleAgent = Array.isArray(agents) && agents.length === 1; + const isSmallBatch = Array.isArray(agents) && agents.length > 1 && agents.length <= 10; const isAllAgents = agents === ''; - const getVersion = (selectedVersion: Array>) => - selectedVersion[0].value as string; - const getRolloutDuration = (selectedMantainanceWindow: Array>) => - Number(selectedMantainanceWindow[0].value); + const fallbackVersions: Array> = FALLBACK_VERSIONS.map((option) => ({ + label: option, + value: option, + })); + const maintainanceWindows = isSmallBatch ? [0].concat(MAINTAINANCE_VALUES) : MAINTAINANCE_VALUES; + const maintainanceOptions: Array> = maintainanceWindows.map((option) => ({ + label: option === 0 ? i18n.translate( + 'xpack.fleet.upgradeAgents.noMaintainanceWindowOption', + { + defaultMessage: 'Immediately', + } + ) : i18n.translate('xpack.fleet.upgradeAgents.hourLabel', { + defaultMessage: + '{option} {count, plural, one {hour} other {hours}}', + values: { option, count: option === 1 }, + }), + value: option === 0 ? 0 : option * 3600 + })); + const [selectedVersion, setSelectedVersion] = useState([fallbackVersions[0]]); + const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([maintainanceOptions[0]]); + + + const getVersion = (version: EuiComboBoxOptionOption[]) => version[0].value as string; async function onSubmit() { const version = getVersion(selectedVersion); + const rolloutOptions = selectedMantainanceWindow.length > 0 && selectedMantainanceWindow[0]?.value as number > 0 ? { + rollout_duration_seconds: selectedMantainanceWindow[0].value + } : {}; + try { setIsSubmitting(true); const { data, error } = isSingleAgent ? await sendPostAgentUpgrade((agents[0] as Agent).id, { version, }) - : await sendPostBulkAgentUpgrade({ - agents: Array.isArray(agents) ? agents.map((agent) => agent.id) : agents, + : await sendPostBulkAgentUpgrade({ version, - rollout_duration_seconds: getRolloutDuration(selectedMantainanceWindow), - }); + agents: Array.isArray(agents) ? agents.map((agent) => agent.id) : agents, + ...rolloutOptions + }) if (error) { throw error; } @@ -112,6 +119,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ isAllAgents, }, }); + // remove toasts if (counts.success === counts.total) { notifications.toasts.addSuccess(successMessage); } else if (counts.error === counts.total) { @@ -257,7 +265,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ singleSelection={{ asPlainText: true }} options={maintainanceOptions} selectedOptions={selectedMantainanceWindow} - onChange={(selected: Array>) => { + onChange={(selected: Array>) => { setSelectedMantainanceWindow(selected); }} /> From 8d35d719132dfdaee58f4cf22a1217945fbfc3e0 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 18 May 2022 16:17:17 +0000 Subject: [PATCH 06/10] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../fleet/common/types/rest_spec/agent.ts | 2 +- .../agent_upgrade_modal/constants.tsx | 44 ++++++------- .../components/agent_upgrade_modal/index.tsx | 63 +++++++++++-------- 3 files changed, 55 insertions(+), 54 deletions(-) diff --git a/x-pack/plugins/fleet/common/types/rest_spec/agent.ts b/x-pack/plugins/fleet/common/types/rest_spec/agent.ts index 82d5a779c2ed4..886730d38f831 100644 --- a/x-pack/plugins/fleet/common/types/rest_spec/agent.ts +++ b/x-pack/plugins/fleet/common/types/rest_spec/agent.ts @@ -89,7 +89,7 @@ export interface PostBulkAgentUpgradeRequest { agents: string[] | string; source_uri?: string; version: string; - rollout_duration_seconds?: number + rollout_duration_seconds?: number; }; } diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx index abdd6552742f1..b5d8cd8f4d72d 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx @@ -10,31 +10,23 @@ // in the event that the updated versions cannot be retrieved from the endpoint export const FALLBACK_VERSIONS = [ - '8.2.0', - '8.1.3', - '8.1.2', - '8.1.1', - '8.1.0', - '8.0.1', - '8.0.0', - '7.9.3', - '7.9.2', - '7.9.1', - '7.9.0', - '7.8.1', - '7.8.0', - '7.17.3', - '7.17.2', - '7.17.1', - '7.17.0' + '8.2.0', + '8.1.3', + '8.1.2', + '8.1.1', + '8.1.0', + '8.0.1', + '8.0.0', + '7.9.3', + '7.9.2', + '7.9.1', + '7.9.0', + '7.8.1', + '7.8.0', + '7.17.3', + '7.17.2', + '7.17.1', + '7.17.0', ]; -export const MAINTAINANCE_VALUES = [ - 1, - 2, - 4, - 8, - 12, - 24, - 48 -]; +export const MAINTAINANCE_VALUES = [1, 2, 4, 8, 12, 24, 48]; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx index 696a2a729d7d0..34cf9085d78a5 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx @@ -27,6 +27,7 @@ import { sendPostBulkAgentUpgrade, useStartServices, } from '../../../../hooks'; + import { FALLBACK_VERSIONS, MAINTAINANCE_VALUES } from './constants'; interface Props { @@ -43,38 +44,46 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ const { notifications } = useStartServices(); const [isSubmitting, setIsSubmitting] = useState(false); const isSingleAgent = Array.isArray(agents) && agents.length === 1; - const isSmallBatch = Array.isArray(agents) && agents.length > 1 && agents.length <= 10; + const isSmallBatch = Array.isArray(agents) && agents.length > 1 && agents.length <= 10; const isAllAgents = agents === ''; - const fallbackVersions: Array> = FALLBACK_VERSIONS.map((option) => ({ - label: option, - value: option, - })); + const fallbackVersions: Array> = FALLBACK_VERSIONS.map( + (option) => ({ + label: option, + value: option, + }) + ); const maintainanceWindows = isSmallBatch ? [0].concat(MAINTAINANCE_VALUES) : MAINTAINANCE_VALUES; - const maintainanceOptions: Array> = maintainanceWindows.map((option) => ({ - label: option === 0 ? i18n.translate( - 'xpack.fleet.upgradeAgents.noMaintainanceWindowOption', - { - defaultMessage: 'Immediately', - } - ) : i18n.translate('xpack.fleet.upgradeAgents.hourLabel', { - defaultMessage: - '{option} {count, plural, one {hour} other {hours}}', - values: { option, count: option === 1 }, - }), - value: option === 0 ? 0 : option * 3600 - })); + const maintainanceOptions: Array> = maintainanceWindows.map( + (option) => ({ + label: + option === 0 + ? i18n.translate('xpack.fleet.upgradeAgents.noMaintainanceWindowOption', { + defaultMessage: 'Immediately', + }) + : i18n.translate('xpack.fleet.upgradeAgents.hourLabel', { + defaultMessage: '{option} {count, plural, one {hour} other {hours}}', + values: { option, count: option === 1 }, + }), + value: option === 0 ? 0 : option * 3600, + }) + ); const [selectedVersion, setSelectedVersion] = useState([fallbackVersions[0]]); - const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([maintainanceOptions[0]]); + const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([ + maintainanceOptions[0], + ]); - - const getVersion = (version: EuiComboBoxOptionOption[]) => version[0].value as string; + const getVersion = (version: Array>) => + version[0].value as string; async function onSubmit() { const version = getVersion(selectedVersion); - const rolloutOptions = selectedMantainanceWindow.length > 0 && selectedMantainanceWindow[0]?.value as number > 0 ? { - rollout_duration_seconds: selectedMantainanceWindow[0].value - } : {}; + const rolloutOptions = + selectedMantainanceWindow.length > 0 && (selectedMantainanceWindow[0]?.value as number) > 0 + ? { + rollout_duration_seconds: selectedMantainanceWindow[0].value, + } + : {}; try { setIsSubmitting(true); @@ -82,11 +91,11 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ ? await sendPostAgentUpgrade((agents[0] as Agent).id, { version, }) - : await sendPostBulkAgentUpgrade({ + : await sendPostBulkAgentUpgrade({ version, agents: Array.isArray(agents) ? agents.map((agent) => agent.id) : agents, - ...rolloutOptions - }) + ...rolloutOptions, + }); if (error) { throw error; } From 7f36becca5c2cae275ca45ca059cd4accc339d38 Mon Sep 17 00:00:00 2001 From: criamico Date: Thu, 19 May 2022 15:59:52 +0200 Subject: [PATCH 07/10] Add callout in modal for 400 errors --- .../components/agent_upgrade_modal/index.tsx | 28 ++++++++++++++++++- .../translations/translations/fr-FR.json | 2 -- .../translations/translations/ja-JP.json | 2 -- .../translations/translations/zh-CN.json | 2 -- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx index 34cf9085d78a5..888fa4874e1c8 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx @@ -16,6 +16,7 @@ import { EuiIcon, EuiFlexGroup, EuiFlexItem, + EuiCallOut } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; @@ -43,6 +44,8 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ }) => { const { notifications } = useStartServices(); const [isSubmitting, setIsSubmitting] = useState(false); + const [errors, setErrors] = useState(); + const isSingleAgent = Array.isArray(agents) && agents.length === 1; const isSmallBatch = Array.isArray(agents) && agents.length > 1 && agents.length <= 10; const isAllAgents = agents === ''; @@ -97,6 +100,9 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ ...rolloutOptions, }); if (error) { + if (error?.statusCode === 400) { + setErrors(error?.message); + } throw error; } @@ -128,7 +134,6 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ isAllAgents, }, }); - // remove toasts if (counts.success === counts.total) { notifications.toasts.addSuccess(successMessage); } else if (counts.error === counts.total) { @@ -231,6 +236,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ fullWidth > = ({ fullWidth > = ({ /> ) : null} + { errors ? + <> + + + + : null + } ); }; diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json index af4f20d80b563..1cc5d4da738a7 100644 --- a/x-pack/plugins/translations/translations/fr-FR.json +++ b/x-pack/plugins/translations/translations/fr-FR.json @@ -13073,8 +13073,6 @@ "xpack.fleet.upgradeAgents.cancelButtonLabel": "Annuler", "xpack.fleet.upgradeAgents.confirmMultipleButtonLabel": "Mettre à niveau {count, plural, one {l'agent} other {{count} agents} =true {tous les agents sélectionnés}}", "xpack.fleet.upgradeAgents.confirmSingleButtonLabel": "Mettre à niveau l'agent", - "xpack.fleet.upgradeAgents.experimentalLabel": "Expérimental", - "xpack.fleet.upgradeAgents.experimentalLabelTooltip": "Une modification ou une suppression de la mise à niveau de l'agent peut intervenir dans une version ultérieure. La mise à niveau n'est pas soumise à l'accord de niveau de service du support technique.", "xpack.fleet.upgradeAgents.fatalErrorNotificationTitle": "Erreur lors de la mise à niveau de {count, plural, one {l'agent} other {{count} agents} =true {tous les agents sélectionnés}}", "xpack.fleet.upgradeAgents.successMultiNotificationTitle": "{isMixed, select, true {{success} agents sur {total}} other {{isAllAgents, select, true {Tous les agents sélectionnés} other {{success}} }}} mis à niveau", "xpack.fleet.upgradeAgents.successSingleNotificationTitle": "{count} agent mis à niveau", diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 8123876ede978..fa17fbceea882 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -13190,8 +13190,6 @@ "xpack.fleet.upgradeAgents.cancelButtonLabel": "キャンセル", "xpack.fleet.upgradeAgents.confirmMultipleButtonLabel": "{count, plural, other {{count}個のエージェント} =true {すべての選択されたエージェント}}をアップグレード", "xpack.fleet.upgradeAgents.confirmSingleButtonLabel": "エージェントをアップグレード", - "xpack.fleet.upgradeAgents.experimentalLabel": "実験的", - "xpack.fleet.upgradeAgents.experimentalLabelTooltip": "アップグレードエージェントは今後のリリースで変更または削除される可能性があり、SLA のサポート対象になりません。", "xpack.fleet.upgradeAgents.fatalErrorNotificationTitle": "{count, plural, other {{count}個のエージェント} =true {すべての選択されたエージェント}}のアップグレードエラー", "xpack.fleet.upgradeAgents.successMultiNotificationTitle": "{isMixed, select, true {{success}/{total}個の} other {{isAllAgents, select, true {すべての選択された} other {{success}} }}}エージェントをアップグレードしました", "xpack.fleet.upgradeAgents.successSingleNotificationTitle": "{count}個のエージェントをアップグレードしました", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 2b06479908b6e..5e4715a040826 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -13214,8 +13214,6 @@ "xpack.fleet.upgradeAgents.cancelButtonLabel": "取消", "xpack.fleet.upgradeAgents.confirmMultipleButtonLabel": "升级{count, plural, one {代理} other { {count} 个代理} =true {所有选定代理}}", "xpack.fleet.upgradeAgents.confirmSingleButtonLabel": "升级代理", - "xpack.fleet.upgradeAgents.experimentalLabel": "实验性", - "xpack.fleet.upgradeAgents.experimentalLabelTooltip": "在未来的版本中可能会更改或移除升级代理,其不受支持 SLA 的约束。", "xpack.fleet.upgradeAgents.fatalErrorNotificationTitle": "升级{count, plural, one {代理} other { {count} 个代理} =true {所有选定代理}}时出错", "xpack.fleet.upgradeAgents.successMultiNotificationTitle": "已升级{isMixed, select, true { {success} 个(共 {total} 个)} other {{isAllAgents, select, true {所有选定} other { {success} 个} }}}代理", "xpack.fleet.upgradeAgents.successSingleNotificationTitle": "已升级 {count} 个代理", From 40c56d0e9bcbd23440a8b7d18d61ddaaa9b37dde Mon Sep 17 00:00:00 2001 From: criamico Date: Thu, 19 May 2022 16:09:37 +0200 Subject: [PATCH 08/10] Linter fixes --- .../components/agent_upgrade_modal/index.tsx | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx index 888fa4874e1c8..4920e76a9569a 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx @@ -16,7 +16,7 @@ import { EuiIcon, EuiFlexGroup, EuiFlexItem, - EuiCallOut + EuiCallOut, } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; @@ -287,25 +287,23 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ /> ) : null} - { errors ? + {errors ? ( <> - : null - } + + ) : null} ); }; From b8d3991573de622f77e763e23068818da9a46ff6 Mon Sep 17 00:00:00 2001 From: criamico Date: Thu, 19 May 2022 16:52:32 +0200 Subject: [PATCH 09/10] Fix i18n error --- .../agents/components/agent_upgrade_modal/index.tsx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx index 4920e76a9569a..f40ec86f3c986 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx @@ -296,12 +296,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ 'Error upgrading the selected {count, plural, one {agent} other {{count} agents}}', values: { count: isSingleAgent }, })} - > - - + /> ) : null} From 6a30f3ef9296b682bf346e0ca80ab7148ea19f7c Mon Sep 17 00:00:00 2001 From: criamico Date: Fri, 20 May 2022 11:24:09 +0200 Subject: [PATCH 10/10] Address code review comments --- .../components/agent_upgrade_modal/index.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx index f40ec86f3c986..2122abb5e2785 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx @@ -27,6 +27,7 @@ import { sendPostAgentUpgrade, sendPostBulkAgentUpgrade, useStartServices, + useKibanaVersion, } from '../../../../hooks'; import { FALLBACK_VERSIONS, MAINTAINANCE_VALUES } from './constants'; @@ -37,12 +38,15 @@ interface Props { agentCount: number; } +const getVersion = (version: Array>) => version[0].value as string; + export const AgentUpgradeAgentModal: React.FunctionComponent = ({ onClose, agents, agentCount, }) => { const { notifications } = useStartServices(); + const kibanaVersion = useKibanaVersion(); const [isSubmitting, setIsSubmitting] = useState(false); const [errors, setErrors] = useState(); @@ -50,7 +54,8 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ const isSmallBatch = Array.isArray(agents) && agents.length > 1 && agents.length <= 10; const isAllAgents = agents === ''; - const fallbackVersions: Array> = FALLBACK_VERSIONS.map( + const fallbackVersions = [kibanaVersion].concat(FALLBACK_VERSIONS); + const fallbackOptions: Array> = fallbackVersions.map( (option) => ({ label: option, value: option, @@ -71,14 +76,11 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ value: option === 0 ? 0 : option * 3600, }) ); - const [selectedVersion, setSelectedVersion] = useState([fallbackVersions[0]]); + const [selectedVersion, setSelectedVersion] = useState([fallbackOptions[0]]); const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([ maintainanceOptions[0], ]); - const getVersion = (version: Array>) => - version[0].value as string; - async function onSubmit() { const version = getVersion(selectedVersion); const rolloutOptions = @@ -239,7 +241,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ data-test-subj="agentUpgradeModal.VersionCombobox" fullWidth singleSelection={{ asPlainText: true }} - options={fallbackVersions} + options={fallbackOptions} selectedOptions={selectedVersion} onChange={(selected: Array>) => { setSelectedVersion(selected);