Skip to content

Commit

Permalink
[RAC][Rule Registry] Put index upgrade logic under a feature flag (#1…
Browse files Browse the repository at this point in the history
…10592) (#110657)

**Ticket:** #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)

Co-authored-by: Georgii Gorbachev <georgii.gorbachev@elastic.co>
  • Loading branch information
kibanamachine and banderror authored Aug 31, 2021
1 parent 80bbb05 commit 7aeaaf7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions x-pack/plugins/rule_registry/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export const config = {
legacyMultiTenancy: schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
indexUpgrade: schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
}),
}),
};
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/rule_registry/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface ConstructorOptions {
getClusterClient: () => Promise<ElasticsearchClient>;
logger: Logger;
isWriteEnabled: boolean;
isIndexUpgradeEnabled: boolean;
}

export class ResourceInstaller {
Expand Down Expand Up @@ -115,6 +116,7 @@ export class ResourceInstaller {
public async installIndexLevelResources(indexInfo: IndexInfo): Promise<void> {
await this.installWithTimeout(`resources for index ${indexInfo.baseName}`, async () => {
const { componentTemplates, ilmPolicy } = indexInfo.indexOptions;
const { isIndexUpgradeEnabled } = this.options;

if (ilmPolicy != null) {
await this.createOrUpdateLifecyclePolicy({
Expand All @@ -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);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface ConstructorOptions {
logger: Logger;
kibanaVersion: string;
isWriteEnabled: boolean;
isIndexUpgradeEnabled: boolean;
}

/**
Expand All @@ -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'));
Expand Down

0 comments on commit 7aeaaf7

Please sign in to comment.