Skip to content
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

[Security Solution] Unskip install_large_prebuilt_rules_package #192563

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 65 additions & 30 deletions x-pack/plugins/fleet/server/services/epm/kibana/assets/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,35 +146,12 @@ export async function installKibanaAssets(options: {

await makeManagedIndexPatternsGlobal(savedObjectsClient);

let installedAssets: SavedObjectsImportSuccess[] = [];

if (
assetsToInstall.length > MAX_ASSETS_TO_INSTALL_IN_PARALLEL &&
!hasReferences(assetsToInstall)
) {
// If the package size is too large, we need to install in chunks to avoid
// memory issues as the SO import creates a lot of objects in memory

// NOTE: if there are references, we can't chunk the install because
// referenced objects might end up in different chunks leading to import
// errors.
for (const assetChunk of chunk(assetsToInstall, MAX_ASSETS_TO_INSTALL_IN_PARALLEL)) {
const result = await installKibanaSavedObjects({
logger,
savedObjectsImporter,
kibanaAssets: assetChunk,
});
installedAssets = installedAssets.concat(result);
}
} else {
installedAssets = await installKibanaSavedObjects({
logger,
savedObjectsImporter,
kibanaAssets: assetsToInstall,
});
}

return installedAssets;
return await installKibanaSavedObjects({
logger,
savedObjectsImporter,
kibanaAssets: assetsToInstall,
assetsChunkSize: MAX_ASSETS_TO_INSTALL_IN_PARALLEL,
});
}

export async function installKibanaAssetsAndReferencesMultispace({
Expand Down Expand Up @@ -411,13 +388,71 @@ async function retryImportOnConflictError(

// only exported for testing
export async function installKibanaSavedObjects({
savedObjectsImporter,
kibanaAssets,
assetsChunkSize,
logger,
}: {
kibanaAssets: ArchiveAsset[];
savedObjectsImporter: SavedObjectsImporterContract;
logger: Logger;
assetsChunkSize?: number;
}): Promise<SavedObjectsImportSuccess[]> {
if (!assetsChunkSize || kibanaAssets.length <= assetsChunkSize || hasReferences(kibanaAssets)) {
return await installKibanaSavedObjectsChunk({
logger,
savedObjectsImporter,
kibanaAssets,
refresh: 'wait_for',
});
}

const installedAssets: SavedObjectsImportSuccess[] = [];

// If the package size is too large, we need to install in chunks to avoid
// memory issues as the SO import creates a lot of objects in memory

// NOTE: if there are references, we can't chunk the install because
// referenced objects might end up in different chunks leading to import
// errors.
const assetChunks = chunk(kibanaAssets, assetsChunkSize);
const allAssetChunksButLast = assetChunks.slice(0, -1);
const lastAssetChunk = assetChunks.slice(-1)[0];

for (const assetChunk of allAssetChunksButLast) {
const result = await installKibanaSavedObjectsChunk({
logger,
savedObjectsImporter,
kibanaAssets: assetChunk,
refresh: false,
});

installedAssets.push(...result);
}

const result = await installKibanaSavedObjectsChunk({
logger,
savedObjectsImporter,
kibanaAssets: lastAssetChunk,
refresh: 'wait_for',
});

installedAssets.push(...result);

return installedAssets;
}

// only exported for testing
async function installKibanaSavedObjectsChunk({
savedObjectsImporter,
kibanaAssets,
logger,
refresh,
}: {
kibanaAssets: ArchiveAsset[];
savedObjectsImporter: SavedObjectsImporterContract;
logger: Logger;
refresh?: boolean | 'wait_for';
}) {
if (!kibanaAssets.length) {
return [];
Expand All @@ -437,8 +472,8 @@ export async function installKibanaSavedObjects({
overwrite: true,
readStream,
createNewCopies: false,
refresh: false,
managed: true,
refresh,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const log = getService('log');

// Failing: See https://github.com/elastic/kibana/issues/192479
describe.skip('@ess @serverless @skipInServerlessMKI install_large_prebuilt_rules_package', () => {
describe('@ess @serverless @skipInServerlessMKI install_large_prebuilt_rules_package', () => {
beforeEach(async () => {
await deleteAllRules(supertest, log);
await deleteAllPrebuiltRuleAssets(es, log);
Expand All @@ -36,9 +35,12 @@ export default ({ getService }: FtrProviderContext): void => {
es,
supertest
);
expect(statusBeforePackageInstallation.rules_installed).toBe(0);
expect(statusBeforePackageInstallation.rules_not_installed).toBe(0);
expect(statusBeforePackageInstallation.rules_not_updated).toBe(0);

expect(statusBeforePackageInstallation).toMatchObject({
rules_installed: 0,
rules_not_installed: 0,
rules_not_updated: 0,
});

// Install the package with 15000 prebuilt historical version of rules rules and 750 unique rules
await installPrebuiltRulesAndTimelines(es, supertest);
Expand All @@ -48,9 +50,12 @@ export default ({ getService }: FtrProviderContext): void => {
es,
supertest
);
expect(statusAfterPackageInstallation.rules_installed).toBe(750);
expect(statusAfterPackageInstallation.rules_not_installed).toBe(0);
expect(statusAfterPackageInstallation.rules_not_updated).toBe(0);

expect(statusAfterPackageInstallation).toMatchObject({
rules_installed: 750,
rules_not_installed: 0,
rules_not_updated: 0,
});
});
});
};
Loading