From 6ecf198869458bfc4442c0ba7d73599fe9b6b5d9 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 1 Jan 2025 03:51:01 +1100 Subject: [PATCH] [8.x] [Fleet] Allow to enable global logs and metrics dataview creation with config enableManagedLogsAndMetricsDataviews (#205268) (#205330) # Backport This will backport the following commits from `main` to `8.x`: - [[Fleet] Allow to enable global logs and metrics dataview creation with config enableManagedLogsAndMetricsDataviews (#205268)](https://github.com/elastic/kibana/pull/205268) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Nicolas Chaulet --- docs/settings/fleet-settings.asciidoc | 3 +++ .../shared/fleet/common/types/index.ts | 1 + .../plugins/shared/fleet/server/config.ts | 1 + .../services/epm/kibana/assets/install.ts | 20 +++++++++++++++++-- .../kibana/assets/install_with_streaming.ts | 10 +++++----- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/docs/settings/fleet-settings.asciidoc b/docs/settings/fleet-settings.asciidoc index 084c8c25ad0c7..dfd92f1e9cf99 100644 --- a/docs/settings/fleet-settings.asciidoc +++ b/docs/settings/fleet-settings.asciidoc @@ -318,3 +318,6 @@ The features in this section are experimental and may be changed or removed comp Elastic will make a best effort to fix any issues, but experimental features are not supported to the same level as generally available (GA) features. ==== +`xpack.fleet.enableManagedLogsAndMetricsDataviews`:: +Set to `true` (default), to enable the automatic creation of global `logs-*` and `metrics-*` data views. + diff --git a/x-pack/platform/plugins/shared/fleet/common/types/index.ts b/x-pack/platform/plugins/shared/fleet/common/types/index.ts index f77ea38dc7b5f..69f150a7ca78a 100644 --- a/x-pack/platform/plugins/shared/fleet/common/types/index.ts +++ b/x-pack/platform/plugins/shared/fleet/common/types/index.ts @@ -50,6 +50,7 @@ export interface FleetConfigType { outputs?: PreconfiguredOutput[]; agentIdVerificationEnabled?: boolean; enableExperimental?: string[]; + enableManagedLogsAndMetricsDataviews?: boolean; packageVerification?: { gpgKeyPath?: string; }; diff --git a/x-pack/platform/plugins/shared/fleet/server/config.ts b/x-pack/platform/plugins/shared/fleet/server/config.ts index 8035f389db488..3a78c20c799fe 100644 --- a/x-pack/platform/plugins/shared/fleet/server/config.ts +++ b/x-pack/platform/plugins/shared/fleet/server/config.ts @@ -131,6 +131,7 @@ export const config: PluginConfigDescriptor = { { isAirGapped: schema.maybe(schema.boolean({ defaultValue: false })), enableDeleteUnenrolledAgents: schema.maybe(schema.boolean({ defaultValue: false })), + enableManagedLogsAndMetricsDataviews: schema.boolean({ defaultValue: true }), registryUrl: schema.maybe(schema.uri({ scheme: ['http', 'https'] })), registryProxyUrl: schema.maybe(schema.uri({ scheme: ['http', 'https'] })), agents: schema.object({ diff --git a/x-pack/platform/plugins/shared/fleet/server/services/epm/kibana/assets/install.ts b/x-pack/platform/plugins/shared/fleet/server/services/epm/kibana/assets/install.ts index 6361aa1bf935b..d5594f54300b2 100644 --- a/x-pack/platform/plugins/shared/fleet/server/services/epm/kibana/assets/install.ts +++ b/x-pack/platform/plugins/shared/fleet/server/services/epm/kibana/assets/install.ts @@ -35,6 +35,7 @@ import { withPackageSpan } from '../../packages/utils'; import { tagKibanaAssets } from './tag_assets'; import { getSpaceAwareSaveobjectsClients } from './saved_objects'; +import { appContextService } from '../../..'; const MAX_ASSETS_TO_INSTALL_IN_PARALLEL = 1000; @@ -133,8 +134,10 @@ export async function installKibanaAssets(options: { return []; } - await createDefaultIndexPatterns(savedObjectsImporter); - await makeManagedIndexPatternsGlobal(savedObjectsClient); + await installManagedIndexPattern({ + savedObjectsClient, + savedObjectsImporter, + }); return await installKibanaSavedObjects({ logger, @@ -144,6 +147,19 @@ export async function installKibanaAssets(options: { }); } +export async function installManagedIndexPattern({ + savedObjectsClient, + savedObjectsImporter, +}: { + savedObjectsClient: SavedObjectsClientContract; + savedObjectsImporter: SavedObjectsImporterContract; +}) { + if (appContextService.getConfig()?.enableManagedLogsAndMetricsDataviews === true) { + await createDefaultIndexPatterns(savedObjectsImporter); + await makeManagedIndexPatternsGlobal(savedObjectsClient); + } +} + export async function createDefaultIndexPatterns( savedObjectsImporter: SavedObjectsImporterContract ) { diff --git a/x-pack/platform/plugins/shared/fleet/server/services/epm/kibana/assets/install_with_streaming.ts b/x-pack/platform/plugins/shared/fleet/server/services/epm/kibana/assets/install_with_streaming.ts index 45c4aee73b583..b424d71b00f62 100644 --- a/x-pack/platform/plugins/shared/fleet/server/services/epm/kibana/assets/install_with_streaming.ts +++ b/x-pack/platform/plugins/shared/fleet/server/services/epm/kibana/assets/install_with_streaming.ts @@ -13,13 +13,11 @@ import { getPathParts } from '../../archive'; import { saveKibanaAssetsRefs } from '../../packages/install'; -import { makeManagedIndexPatternsGlobal } from '../index_pattern/install'; - import type { ArchiveAsset } from './install'; import { KibanaSavedObjectTypeMapping, - createDefaultIndexPatterns, createSavedObjectKibanaAsset, + installManagedIndexPattern, isKibanaAssetType, toAssetReference, } from './install'; @@ -45,8 +43,10 @@ export async function installKibanaAssetsWithStreaming({ const { savedObjectClientWithSpace, savedObjectsImporter } = getSpaceAwareSaveobjectsClients(spaceId); - await createDefaultIndexPatterns(savedObjectsImporter); - await makeManagedIndexPatternsGlobal(savedObjectsClient); + await installManagedIndexPattern({ + savedObjectsImporter, + savedObjectsClient, + }); const assetRefs: KibanaAssetReference[] = []; let batch: ArchiveAsset[] = [];