Skip to content

Commit

Permalink
Added default index pattern creation to stream-based installation
Browse files Browse the repository at this point in the history
  • Loading branch information
xcrzx committed Nov 6, 2024
1 parent 4869b8f commit e96f27b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
23 changes: 14 additions & 9 deletions x-pack/plugins/fleet/server/services/epm/kibana/assets/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,7 +30,6 @@ interface InstallKibanaAssetsWithStreamingArgs {
packageInstallContext: PackageInstallContext;
spaceId: string;
savedObjectsClient: SavedObjectsClientContract;
installedPkg?: SavedObject<Installation> | undefined;
}

const MAX_ASSETS_TO_INSTALL_IN_PARALLEL = 100;
Expand All @@ -37,11 +39,14 @@ export async function installKibanaAssetsWithStreaming({
packageInstallContext,
savedObjectsClient,
pkgName,
installedPkg,
}: InstallKibanaAssetsWithStreamingArgs): Promise<KibanaAssetReference[]> {
const { archiveIterator } = packageInstallContext;

const { savedObjectClientWithSpace } = getSpaceAwareSaveobjectsClients(spaceId);
const { savedObjectClientWithSpace, savedObjectsImporter } =
getSpaceAwareSaveobjectsClients(spaceId);

await createDefaultIndexPatterns(savedObjectsImporter);
await makeManagedIndexPatternsGlobal(savedObjectsClient);

const assetRefs: KibanaAssetReference[] = [];
let batch: ArchiveAsset[] = [];
Expand Down

0 comments on commit e96f27b

Please sign in to comment.