-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] Allow to install Kibana assets in multiple spaces #186620
Merged
nchaulet
merged 19 commits into
elastic:main
from
nchaulet:feature-kibana-install-differents-space
Jun 26, 2024
Merged
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
00d685b
[Fleet] Allow to install Kibana assets in multiple spaces
nchaulet 901424e
Add UI
nchaulet 80320de
UI fixes
nchaulet 7dfbc24
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine 168704c
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine 8ff55eb
fix types
nchaulet 9eb9135
Merge branch 'feature-kibana-install-differents-space' of github.com:…
nchaulet a30de0a
Merge branch 'main' of github.com:elastic/kibana into feature-kibana-…
nchaulet 8223489
Move tests
nchaulet e944f52
add api integration tests
nchaulet b74f13e
add delete API integrations tests
nchaulet 587c9f9
rename additionnal -> additional
nchaulet 3ac768f
fix renaming
nchaulet 2cd5196
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine 09c6abe
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine b7fcb9b
refacto
nchaulet e86f532
Move the install assets button to the assets page
nchaulet 50632d7
Merge branch 'main' of github.com:elastic/kibana into feature-kibana-…
nchaulet a6b5c18
Apply suggestions from code review
nchaulet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,7 @@ | |
|
||
export type ExperimentalFeatures = typeof allowedExperimentalValues; | ||
|
||
/** | ||
* A list of allowed values that can be used in `xpack.fleet.enableExperimental`. | ||
* This object is then used to validate and parse the value entered. | ||
*/ | ||
export const allowedExperimentalValues = Object.freeze<Record<string, boolean>>({ | ||
const _allowedExperimentalValues = { | ||
createPackagePolicyMultiPageLayout: true, | ||
packageVerification: true, | ||
showDevtoolsRequest: true, | ||
|
@@ -32,9 +28,18 @@ export const allowedExperimentalValues = Object.freeze<Record<string, boolean>>( | |
advancedPolicySettings: true, | ||
useSpaceAwareness: false, | ||
enableReusableIntegrationPolicies: false, | ||
}); | ||
}; | ||
|
||
/** | ||
* A list of allowed values that can be used in `xpack.fleet.enableExperimental`. | ||
* This object is then used to validate and parse the value entered. | ||
*/ | ||
export const allowedExperimentalValues = Object.freeze< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really related to that feature, but it allow to add some type safety to |
||
Record<keyof typeof _allowedExperimentalValues, boolean> | ||
>({ ..._allowedExperimentalValues }); | ||
|
||
type ExperimentalConfigKeys = Array<keyof ExperimentalFeatures>; | ||
type ExperimentalConfigKey = keyof ExperimentalFeatures; | ||
type ExperimentalConfigKeys = ExperimentalConfigKey[]; | ||
type Mutable<T> = { -readonly [P in keyof T]: T[P] }; | ||
|
||
const allowedKeys = Object.keys(allowedExperimentalValues) as Readonly<ExperimentalConfigKeys>; | ||
|
@@ -46,7 +51,7 @@ const allowedKeys = Object.keys(allowedExperimentalValues) as Readonly<Experimen | |
* @param configValue | ||
*/ | ||
export const parseExperimentalConfigValue = (configValue: string[]): ExperimentalFeatures => { | ||
const enabledFeatures: Mutable<ExperimentalFeatures> = {}; | ||
const enabledFeatures: Mutable<ExperimentalFeatures> = { ...allowedExperimentalValues }; | ||
|
||
for (const value of configValue) { | ||
if (isValidExperimentalValue(value)) { | ||
|
@@ -60,8 +65,8 @@ export const parseExperimentalConfigValue = (configValue: string[]): Experimenta | |
}; | ||
}; | ||
|
||
export const isValidExperimentalValue = (value: string) => { | ||
return allowedKeys.includes(value); | ||
export const isValidExperimentalValue = (value: string): value is ExperimentalConfigKey => { | ||
return (allowedKeys as string[]).includes(value); | ||
}; | ||
|
||
export const getExperimentalAllowedValues = (): string[] => [...allowedKeys]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...cations/integrations/sections/epm/screens/detail/settings/install_kibana_assets_panel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiTitle } from '@elastic/eui'; | ||
import React, { useCallback } from 'react'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import type { InstallationInfo } from '../../../../../../../../common/types'; | ||
import { | ||
useAuthz, | ||
useFleetStatus, | ||
useInstallKibanaAssetsMutation, | ||
useStartServices, | ||
} from '../../../../../hooks'; | ||
|
||
interface InstallKibanaAssetsPanelProps { | ||
title: string; | ||
installInfo: InstallationInfo; | ||
} | ||
|
||
export function InstallKibanaAssetsPanel({ installInfo, title }: InstallKibanaAssetsPanelProps) { | ||
const { spaceId } = useFleetStatus(); | ||
const { notifications } = useStartServices(); | ||
const { name, version } = installInfo; | ||
const canInstallPackages = useAuthz().integrations.installPackages; | ||
const { mutateAsync, isLoading } = useInstallKibanaAssetsMutation(); | ||
|
||
const assetsInstalledInCurrentSpace = | ||
(!installInfo.installed_kibana_space_id && spaceId === 'default') || | ||
installInfo.installed_kibana_space_id === spaceId || | ||
installInfo.additionnal_spaces_installed_kibana?.[spaceId || 'default']; | ||
|
||
const handleClickInstall = useCallback(async () => { | ||
try { | ||
await mutateAsync({ | ||
pkgName: name, | ||
pkgVersion: version, | ||
}); | ||
} catch (err) { | ||
notifications.toasts.addError(err, { | ||
title: i18n.translate('xpack.fleet.fleetServerSetup.kibanaInstallAssetsErrorTitle', { | ||
defaultMessage: 'Error installing kibana assets', | ||
}), | ||
}); | ||
} | ||
}, [mutateAsync, name, version, notifications.toasts]); | ||
|
||
if (!canInstallPackages) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<EuiFlexGroup direction="column" gutterSize="m"> | ||
<EuiFlexItem> | ||
<EuiTitle> | ||
<h4> | ||
<FormattedMessage | ||
id="xpack.fleet.integrations.settings.kibanaInstallAssetsTitle" | ||
defaultMessage="Kibana assets" | ||
/> | ||
</h4> | ||
</EuiTitle> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<FormattedMessage | ||
id="xpack.fleet.integrations.settings.kibanaInstallAssetsDescription" | ||
defaultMessage="Install or reinstall Kibana assets in that space." | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<div> | ||
<EuiButton iconType="refresh" isLoading={isLoading} onClick={handleClickInstall}> | ||
{isLoading ? ( | ||
assetsInstalledInCurrentSpace ? ( | ||
<FormattedMessage | ||
id="xpack.fleet.integrations.installPackage.kibanaAssetsReinstallingButtonLabel" | ||
defaultMessage="Reinstalling {title} kibana assets" | ||
values={{ | ||
title, | ||
}} | ||
/> | ||
) : ( | ||
<FormattedMessage | ||
id="xpack.fleet.integrations.installPackage.kibanaAssetsInstallingButtonLabel" | ||
defaultMessage="Installing {title} kibana assets" | ||
values={{ | ||
title, | ||
}} | ||
/> | ||
) | ||
) : assetsInstalledInCurrentSpace ? ( | ||
<FormattedMessage | ||
id="xpack.fleet.integrations.installPackage.kibanaAssetsReinstallButtonLabel" | ||
defaultMessage="Reinstall {title} kibana assets" | ||
values={{ | ||
title, | ||
}} | ||
/> | ||
) : ( | ||
<FormattedMessage | ||
id="xpack.fleet.integrations.installPackage.kibanaAssetsInstallButtonLabel" | ||
defaultMessage="Install {title} kibana assets" | ||
values={{ | ||
title, | ||
}} | ||
/> | ||
)} | ||
</EuiButton> | ||
</div> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
additional
has onen
😇