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

Prevent migration of system indices that match templates #87933

Merged

Conversation

grcevski
Copy link
Contributor

Legacy and composable templates may apply to system indices. We don't want this behavior during feature migration. The destination index should get its settings, mappings, and aliases from its system index descriptor. A user who gets this warning should modify their templates so that they do not match system indices, at least during the migration.

This PR is an 8.x version of #87262, where we add an additional flag to all SystemIndexDescriptors that allows certain SystemIndexDescriptors to use index templates. At the moment this is only applicable to Kibana (see elastic/kibana#134897).

@grcevski grcevski requested a review from gwbrown June 22, 2022 21:04
@grcevski grcevski added >bug :Core/Infra/Core Core issues without another label Team:Core/Infra Meta label for core/infra team labels Jun 22, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine
Copy link
Collaborator

Hi @grcevski, I've created a changelog YAML for you.

@@ -161,7 +163,8 @@ static List<GetFeatureUpgradeStatusResponse.IndexInfo> getIndexInfos(ClusterStat
indexMetadata -> new GetFeatureUpgradeStatusResponse.IndexInfo(
indexMetadata.getIndex().getName(),
indexMetadata.getCreationVersion(),
indexMetadata.getIndex().getName().equals(failedFeatureName) ? exception : null
(indexMetadata.getIndex().getName().equals(failedFeatureName)
|| indexMetadata.getIndex().getName().equals(failedFeatureUpgradedName)) ? exception : null
Copy link
Contributor Author

@grcevski grcevski Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting, in 8 we weren't properly determining the error status of the upgrade because the index reported in the exception has the upgraded suffix. My tests hit this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, that one's my bad! Good catch.

@grcevski
Copy link
Contributor Author

@rjernst I added the flag as we discussed and I tagged @gwbrown to review as he was reviewing the initial 7.17 version of the PR. I'll backport the flag back to 7.17.x and the migration logic/tests once we merge this here.

Copy link
Contributor

@gwbrown gwbrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some minor notes, otherwise LGTM!

summary: Prevent migration of indices that match templates
area: Infra/Core
type: bug
issues: []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should reference issues #86801 and #87827 here.


ensureGreen();

client().execute(PostFeatureUpgradeAction.INSTANCE, new PostFeatureUpgradeRequest()).get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check that the upgrade is actually started (minimally, that accepted is true) here, otherwise I think testBailOnMigrateWithTemplatesV1 could pass if we get into a situation where we don't think the index needs to be migrated.


ensureGreen();

client().execute(PostFeatureUpgradeAction.INSTANCE, new PostFeatureUpgradeRequest()).get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing about checking the response.

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. My only question is whether we could be a little more strict. Does Kibana use v1 or v2 templates? Could we completely block the other one (ie not allow that unused template type completely)?

@grcevski
Copy link
Contributor Author

LGTM. My only question is whether we could be a little more strict. Does Kibana use v1 or v2 templates? Could we completely block the other one (ie not allow that unused template type completely)?

Good idea, let me see what they use. They mentioned they are using the new type, but I'd have to confirm.

@grcevski
Copy link
Contributor Author

OK, I don't think I can restrict it further. At some point they had a legacy index template, which they explicitly remove now and replace it with the new version. However a customer upgrading from an old version can potentially have the legacy one at the time of Elasticsearch upgrade because they haven't upgraded Kibana yet. From their code:

    const sessionIndexTemplateName = `${this.options.kibanaIndexName}_security_session_index_template_${SESSION_INDEX_TEMPLATE_VERSION}`;
    return (this.indexInitialization = new Promise<void>(async (resolve, reject) => {
      try {
        // Check if legacy index template exists, and remove it if it does.
        let legacyIndexTemplateExists = false;
        try {
          legacyIndexTemplateExists = await this.options.elasticsearchClient.indices.existsTemplate(
            {
              name: sessionIndexTemplateName,
            }
          );
        } catch (err) {
          this.options.logger.error(
            `Failed to check if session legacy index template exists: ${err.message}`
          );
          return reject(err);
        }

        if (legacyIndexTemplateExists) {
          try {
            await this.options.elasticsearchClient.indices.deleteTemplate({
              name: sessionIndexTemplateName,
            });
            this.options.logger.debug('Successfully deleted session legacy index template.');
          } catch (err) {
            this.options.logger.error(
              `Failed to delete session legacy index template: ${err.message}`
            );
            return reject(err);
          }
        }

        // Check if required index template exists.
        let indexTemplateExists = false;
        try {
          indexTemplateExists = await this.options.elasticsearchClient.indices.existsIndexTemplate({
            name: sessionIndexTemplateName,
          });
        } catch (err) {
          this.options.logger.error(
            `Failed to check if session index template exists: ${err.message}`
          );
          return reject(err);
        }

@grcevski grcevski merged commit 0ddb590 into elastic:master Jun 23, 2022
@grcevski grcevski changed the title Prevent migration of indices that match templates Prevent migration of system indices that match templates Jun 23, 2022
grcevski pushed a commit to grcevski/elasticsearch that referenced this pull request Jun 23, 2022
grcevski added a commit that referenced this pull request Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/Core Core issues without another label Team:Core/Infra Meta label for core/infra team v7.17.5 v8.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants