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

Some template alias settings are not persisted on PUT template #63162

Merged
merged 3 commits into from
Oct 13, 2020

Conversation

davidkyle
Copy link
Member

Templates that use aliases do not persist all of the alias options. The fix is to copy over those settings to the alias metadata

The bug is easy to recreate

PUT _template/with_alias
{
  "index_patterns": [
    "my-prefix-*"
  ],
  "mappings": {
    "properties": {
      "timestamp": {
        "type": "date"
      }
    }
  },
  "aliases": {
    "my-read": {
      "is_hidden" : true
    }
  }
}

Then when the template is read back the is_hidden field has mysteriously disappeared.

GET _template/with_alias



{
  "with_alias" : {
    "order" : 0,
    "index_patterns" : [
      "my-prefix-*"
    ],
    "settings" : { },
    "mappings" : {
      "properties" : {
        "timestamp" : {
          "type" : "date"
        }
      }
    },
    "aliases" : {
      "my-read" : { }.  <-- somethings changed here
    }
  }
}

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features (:Core/Features/Features)

@davidkyle
Copy link
Member Author

run elasticsearch-ci/packaging-sample-windows

@davidkyle
Copy link
Member Author

pinging @elastic/es-core-features I've got a small change here for review

@andreidan andreidan added v7.11.0 and removed v7.10.0 labels Oct 7, 2020
Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

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

Thanks for opening this @davidkyle, I left a comment about a change I think we should do in this PR, but otherwise this looks good.

.filter(alias.filter())
.indexRouting(alias.indexRouting())
.searchRouting(alias.searchRouting())
.writeIndex(alias.writeIndex())
Copy link
Member

Choose a reason for hiding this comment

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

I actually don't think we should persist this one. Putting a template in place with is_write_index: true will be confusing because only a single index can be marked as the write index. I think we should instead throw an exception if alias.writeIndex() is set to true here (fail early rather than fail late)

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes perfect sense. I added a validation against the alias having is_write_index: true and updated the tests

@davidkyle
Copy link
Member Author

The build failures are all a result of the new validation that the template alias cannot be a write alias.

is_write_index: true is used in the tests but those tests cannot have been testing the behaviour of that setting because, as we now know, the field was never persisted.

@dakrone I will defer to you on how to proceed with this change. Not persisting the is_hidden setting is the bug I was having trouble with.

[2020-10-08T16:10:20,774][INFO ][o.e.t.r.ClientYamlTestSuiteIT] [test] [p0=indices.put_index_template/15_composition/Component and index template composition] before test	
[2020-10-08T16:10:20,806][INFO ][o.e.t.r.ClientYamlTestSuiteIT] [test] Stash dump on test failure [{	
  "stash" : {	
    "body" : {	
      "error" : {	
        "root_cause" : [	
          {	
            "type" : "illegal_argument_exception",	
            "reason" : "alias [aliasname] cannot be a write alias",

https://gradle-enterprise.elastic.co/s/kwfgkm34j7avy/tests/failed

@dakrone
Copy link
Member

dakrone commented Oct 8, 2020

Okay, I looked into what it would take to fix the tests, I think that gets a little bit more out of scope for this PR.

I think it's reasonable to persist all the settings for this PR, and then I can open a follow-up issue where we disallow the write index alias setting (fixing the tests in a separate PR).

Do you want to revert/undo the change that adds the exception throwing and we can merge this? (I'll open up the follow-up issue and make sure our team discusses the repercussions)

@davidkyle
Copy link
Member Author

Thanks @dakrone I reverted the validate write alias change.

Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for iterating on this!

@davidkyle davidkyle merged commit d5f60b5 into elastic:master Oct 13, 2020
@davidkyle davidkyle deleted the copy-alias-settings branch October 13, 2020 07:33
davidkyle added a commit to davidkyle/elasticsearch that referenced this pull request Oct 13, 2020
If the templates contains an alias the fields is_write_index and
is_hidden are now copied to the metadata object and persisted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants