Skip to content

Commit

Permalink
[8.x] [Fleet] Added default index pattern creation to stream-based in…
Browse files Browse the repository at this point in the history
…stallation (#199122) (#199453)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Fleet] Added default index pattern creation to stream-based
installation (#199122)](#199122)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Dmitrii
Shevchenko","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-07T09:04:56Z","message":"[Fleet]
Added default index pattern creation to stream-based installation
(#199122)\n\n**Related to:
https://github.com/elastic/kibana/pull/195888**\r\n\r\n##
Summary\r\n\r\nAdd default index pattern creation to the new
stream-based package\r\ninstallation method to match the behavior of
standard package\r\ninstallation.\r\n\r\nSwitching to stream-based
package installation resulted in the default\r\nindex patterns not being
created, even after installing the rules\r\npackage. While this likely
doesn’t affect production, as multiple\r\nintegrations are usually
installed in Kibana (creating the default index\r\npattern in any case),
this change has impacted some
tests:\r\nhttps://github.com//pull/199030. So restoring
the
original\r\nbehaviour","sha":"22d3e628931706dee4c0d8eec068575d264bb13e","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","backport:version","v8.17.0"],"number":199122,"url":"https://github.com/elastic/kibana/pull/199122","mergeCommit":{"message":"[Fleet]
Added default index pattern creation to stream-based installation
(#199122)\n\n**Related to:
https://github.com/elastic/kibana/pull/195888**\r\n\r\n##
Summary\r\n\r\nAdd default index pattern creation to the new
stream-based package\r\ninstallation method to match the behavior of
standard package\r\ninstallation.\r\n\r\nSwitching to stream-based
package installation resulted in the default\r\nindex patterns not being
created, even after installing the rules\r\npackage. While this likely
doesn’t affect production, as multiple\r\nintegrations are usually
installed in Kibana (creating the default index\r\npattern in any case),
this change has impacted some
tests:\r\nhttps://github.com//pull/199030. So restoring
the
original\r\nbehaviour","sha":"22d3e628931706dee4c0d8eec068575d264bb13e"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199122","number":199122,"mergeCommit":{"message":"[Fleet]
Added default index pattern creation to stream-based installation
(#199122)\n\n**Related to:
https://github.com/elastic/kibana/pull/195888**\r\n\r\n##
Summary\r\n\r\nAdd default index pattern creation to the new
stream-based package\r\ninstallation method to match the behavior of
standard package\r\ninstallation.\r\n\r\nSwitching to stream-based
package installation resulted in the default\r\nindex patterns not being
created, even after installing the rules\r\npackage. While this likely
doesn’t affect production, as multiple\r\nintegrations are usually
installed in Kibana (creating the default index\r\npattern in any case),
this change has impacted some
tests:\r\nhttps://github.com//pull/199030. So restoring
the
original\r\nbehaviour","sha":"22d3e628931706dee4c0d8eec068575d264bb13e"}},{"branch":"8.x","label":"v8.17.0","labelRegex":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
  • Loading branch information
xcrzx authored Nov 8, 2024
1 parent 31eb316 commit b8d6a5c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -51,7 +51,6 @@ export async function stepInstallKibanaAssetsWithStreaming(context: InstallConte
savedObjectsClient,
pkgName,
packageInstallContext,
installedPkg,
spaceId,
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit b8d6a5c

Please sign in to comment.