From b8d6a5c4186f3a5e92fc60de1f0d6b4cb502736c Mon Sep 17 00:00:00 2001 From: Dmitrii Shevchenko Date: Fri, 8 Nov 2024 15:04:02 +0100 Subject: [PATCH] [8.x] [Fleet] Added default index pattern creation to stream-based installation (#199122) (#199453) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Backport This will backport the following commits from `main` to `8.x`: - [[Fleet] Added default index pattern creation to stream-based installation (#199122)](https://github.com/elastic/kibana/pull/199122) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) --- .../services/epm/kibana/assets/install.ts | 23 +++++++++++-------- .../kibana/assets/install_with_streaming.ts | 15 ++++++++---- .../steps/step_install_kibana_assets.ts | 3 +-- .../sourcerer/sourcerer_timeline.cy.ts | 6 ++--- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/epm/kibana/assets/install.ts b/x-pack/plugins/fleet/server/services/epm/kibana/assets/install.ts index bf5684f29c205..6361aa1bf935b 100644 --- a/x-pack/plugins/fleet/server/services/epm/kibana/assets/install.ts +++ b/x-pack/plugins/fleet/server/services/epm/kibana/assets/install.ts @@ -133,6 +133,20 @@ export async function installKibanaAssets(options: { return []; } + await createDefaultIndexPatterns(savedObjectsImporter); + await makeManagedIndexPatternsGlobal(savedObjectsClient); + + return await installKibanaSavedObjects({ + logger, + savedObjectsImporter, + kibanaAssets: assetsToInstall, + assetsChunkSize: MAX_ASSETS_TO_INSTALL_IN_PARALLEL, + }); +} + +export async function createDefaultIndexPatterns( + savedObjectsImporter: SavedObjectsImporterContract +) { // Create index patterns separately with `overwrite: false` to prevent blowing away users' runtime fields. // These don't get retried on conflict, because we expect that they exist once an integration has been installed. const indexPatternSavedObjects = getIndexPatternSavedObjects() as ArchiveAsset[]; @@ -143,15 +157,6 @@ export async function installKibanaAssets(options: { refresh: false, managed: true, }); - - await makeManagedIndexPatternsGlobal(savedObjectsClient); - - return await installKibanaSavedObjects({ - logger, - savedObjectsImporter, - kibanaAssets: assetsToInstall, - assetsChunkSize: MAX_ASSETS_TO_INSTALL_IN_PARALLEL, - }); } export async function installKibanaAssetsAndReferencesMultispace({ diff --git a/x-pack/plugins/fleet/server/services/epm/kibana/assets/install_with_streaming.ts b/x-pack/plugins/fleet/server/services/epm/kibana/assets/install_with_streaming.ts index fca6cf27a0cd7..45c4aee73b583 100644 --- a/x-pack/plugins/fleet/server/services/epm/kibana/assets/install_with_streaming.ts +++ b/x-pack/plugins/fleet/server/services/epm/kibana/assets/install_with_streaming.ts @@ -5,17 +5,20 @@ * 2.0. */ -import type { SavedObject, SavedObjectsClientContract } from '@kbn/core/server'; +import type { SavedObjectsClientContract } from '@kbn/core/server'; -import type { Installation, PackageInstallContext } from '../../../../../common/types'; +import type { PackageInstallContext } from '../../../../../common/types'; import type { KibanaAssetReference, KibanaAssetType } from '../../../../types'; import { getPathParts } from '../../archive'; import { saveKibanaAssetsRefs } from '../../packages/install'; +import { makeManagedIndexPatternsGlobal } from '../index_pattern/install'; + import type { ArchiveAsset } from './install'; import { KibanaSavedObjectTypeMapping, + createDefaultIndexPatterns, createSavedObjectKibanaAsset, isKibanaAssetType, toAssetReference, @@ -27,7 +30,6 @@ interface InstallKibanaAssetsWithStreamingArgs { packageInstallContext: PackageInstallContext; spaceId: string; savedObjectsClient: SavedObjectsClientContract; - installedPkg?: SavedObject | undefined; } const MAX_ASSETS_TO_INSTALL_IN_PARALLEL = 100; @@ -37,11 +39,14 @@ export async function installKibanaAssetsWithStreaming({ packageInstallContext, savedObjectsClient, pkgName, - installedPkg, }: InstallKibanaAssetsWithStreamingArgs): Promise { const { archiveIterator } = packageInstallContext; - const { savedObjectClientWithSpace } = getSpaceAwareSaveobjectsClients(spaceId); + const { savedObjectClientWithSpace, savedObjectsImporter } = + getSpaceAwareSaveobjectsClients(spaceId); + + await createDefaultIndexPatterns(savedObjectsImporter); + await makeManagedIndexPatternsGlobal(savedObjectsClient); const assetRefs: KibanaAssetReference[] = []; let batch: ArchiveAsset[] = []; diff --git a/x-pack/plugins/fleet/server/services/epm/packages/install_state_machine/steps/step_install_kibana_assets.ts b/x-pack/plugins/fleet/server/services/epm/packages/install_state_machine/steps/step_install_kibana_assets.ts index aabd23f2eb9cc..22c785f568402 100644 --- a/x-pack/plugins/fleet/server/services/epm/packages/install_state_machine/steps/step_install_kibana_assets.ts +++ b/x-pack/plugins/fleet/server/services/epm/packages/install_state_machine/steps/step_install_kibana_assets.ts @@ -40,7 +40,7 @@ export async function stepInstallKibanaAssets(context: InstallContext) { } export async function stepInstallKibanaAssetsWithStreaming(context: InstallContext) { - const { savedObjectsClient, installedPkg, packageInstallContext, spaceId } = context; + const { savedObjectsClient, packageInstallContext, spaceId } = context; const { packageInfo } = packageInstallContext; const { name: pkgName } = packageInfo; @@ -51,7 +51,6 @@ export async function stepInstallKibanaAssetsWithStreaming(context: InstallConte savedObjectsClient, pkgName, packageInstallContext, - installedPkg, spaceId, }) ); diff --git a/x-pack/test/security_solution_cypress/cypress/e2e/investigations/sourcerer/sourcerer_timeline.cy.ts b/x-pack/test/security_solution_cypress/cypress/e2e/investigations/sourcerer/sourcerer_timeline.cy.ts index b89fc7a09ac09..9d2e1ac2e11a5 100644 --- a/x-pack/test/security_solution_cypress/cypress/e2e/investigations/sourcerer/sourcerer_timeline.cy.ts +++ b/x-pack/test/security_solution_cypress/cypress/e2e/investigations/sourcerer/sourcerer_timeline.cy.ts @@ -62,8 +62,7 @@ describe('Timeline scope', { tags: ['@ess', '@serverless', '@skipInServerless'] isNotSourcererOption(`${DEFAULT_ALERTS_INDEX}-default`); }); - // FLAKY: https://github.com/elastic/kibana/issues/173854 - describe.skip('Modified badge', () => { + describe('Modified badge', () => { it('Selecting new data view does not add a modified badge', () => { openTimelineUsingToggle(); cy.get(SOURCERER.badgeModified).should(`not.exist`); @@ -134,8 +133,7 @@ describe('Timeline scope', { tags: ['@ess', '@serverless', '@skipInServerless'] }); const defaultPatterns = [`auditbeat-*`, `${DEFAULT_ALERTS_INDEX}-default`]; - // failing on main multiple times https://github.com/elastic/kibana/issues/198944#issuecomment-2457665138 and https://github.com/elastic/kibana/issues/198943#issuecomment-2457665072 - it.skip('alerts checkbox behaves as expected', () => { + it('alerts checkbox behaves as expected', () => { isDataViewSelection(siemDataViewTitle); defaultPatterns.forEach((pattern) => isSourcererSelection(pattern)); openDataViewSelection();