From 192556ef63af3cbc4c4dae72a600b426496bd2d1 Mon Sep 17 00:00:00 2001 From: Georgii Gorbachev Date: Tue, 31 Aug 2021 17:40:06 +0200 Subject: [PATCH] [RAC][Rule Registry] Put index upgrade logic under a feature flag (#110592) **Ticket:** https://github.com/elastic/kibana/issues/110594 ## Summary This PR adds a feature flag around the logic that finds existing Alerts as Data indices and upgrades the mappings or rolls the index if the mappings can't be upgraded in place. **IMPORTANT:** - **The feature flag is switched off by default**. This is intentional, because we need to **disable the upgrade logic in 7.15.0**. - **This is a temporary measure**. We're going to work on fixing the index upgrade logic asap and ship it before the next release that makes any mapping changes, possibly as soon as 7.15.1. - Developers will need to enable it in their local kibana configs this way: ```yaml xpack.ruleRegistry.unsafe.indexUpgrade.enabled: true ``` Please check the ticket for the background of this fix. ### Checklist Delete any items that are not applicable to this PR. - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/master/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) --- x-pack/plugins/rule_registry/server/config.ts | 3 +++ x-pack/plugins/rule_registry/server/plugin.ts | 1 + .../server/rule_data_plugin_service/resource_installer.ts | 8 ++++++-- .../rule_data_plugin_service/rule_data_plugin_service.ts | 2 ++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/rule_registry/server/config.ts b/x-pack/plugins/rule_registry/server/config.ts index 830762c9b3741..8f98ceb2dd8db 100644 --- a/x-pack/plugins/rule_registry/server/config.ts +++ b/x-pack/plugins/rule_registry/server/config.ts @@ -17,6 +17,9 @@ export const config = { legacyMultiTenancy: schema.object({ enabled: schema.boolean({ defaultValue: false }), }), + indexUpgrade: schema.object({ + enabled: schema.boolean({ defaultValue: false }), + }), }), }), }; diff --git a/x-pack/plugins/rule_registry/server/plugin.ts b/x-pack/plugins/rule_registry/server/plugin.ts index a4122e3a1ffc1..2329b90898ca6 100644 --- a/x-pack/plugins/rule_registry/server/plugin.ts +++ b/x-pack/plugins/rule_registry/server/plugin.ts @@ -103,6 +103,7 @@ export class RuleRegistryPlugin logger, kibanaVersion, isWriteEnabled: isWriteEnabled(this.config, this.legacyConfig), + isIndexUpgradeEnabled: this.config.unsafe.indexUpgrade.enabled, getClusterClient: async () => { const deps = await startDependencies; return deps.core.elasticsearch.client.asInternalUser; diff --git a/x-pack/plugins/rule_registry/server/rule_data_plugin_service/resource_installer.ts b/x-pack/plugins/rule_registry/server/rule_data_plugin_service/resource_installer.ts index 73651ec298c36..d683cc95065e3 100644 --- a/x-pack/plugins/rule_registry/server/rule_data_plugin_service/resource_installer.ts +++ b/x-pack/plugins/rule_registry/server/rule_data_plugin_service/resource_installer.ts @@ -29,6 +29,7 @@ interface ConstructorOptions { getClusterClient: () => Promise; logger: Logger; isWriteEnabled: boolean; + isIndexUpgradeEnabled: boolean; } export class ResourceInstaller { @@ -115,6 +116,7 @@ export class ResourceInstaller { public async installIndexLevelResources(indexInfo: IndexInfo): Promise { await this.installWithTimeout(`resources for index ${indexInfo.baseName}`, async () => { const { componentTemplates, ilmPolicy } = indexInfo.indexOptions; + const { isIndexUpgradeEnabled } = this.options; if (ilmPolicy != null) { await this.createOrUpdateLifecyclePolicy({ @@ -138,9 +140,11 @@ export class ResourceInstaller { }) ); - // TODO: Update all existing namespaced index templates matching this index' base name + if (isIndexUpgradeEnabled) { + // TODO: Update all existing namespaced index templates matching this index' base name - await this.updateIndexMappings(indexInfo); + await this.updateIndexMappings(indexInfo); + } }); } diff --git a/x-pack/plugins/rule_registry/server/rule_data_plugin_service/rule_data_plugin_service.ts b/x-pack/plugins/rule_registry/server/rule_data_plugin_service/rule_data_plugin_service.ts index ed3d5340756e8..c69677b091c9c 100644 --- a/x-pack/plugins/rule_registry/server/rule_data_plugin_service/rule_data_plugin_service.ts +++ b/x-pack/plugins/rule_registry/server/rule_data_plugin_service/rule_data_plugin_service.ts @@ -22,6 +22,7 @@ interface ConstructorOptions { logger: Logger; kibanaVersion: string; isWriteEnabled: boolean; + isIndexUpgradeEnabled: boolean; } /** @@ -43,6 +44,7 @@ export class RuleDataPluginService { getClusterClient: options.getClusterClient, logger: options.logger, isWriteEnabled: options.isWriteEnabled, + isIndexUpgradeEnabled: options.isIndexUpgradeEnabled, }); this.installCommonResources = Promise.resolve(right('ok'));