Skip to content

Migrate watcher to system indices infrastructure #67588

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

Merged
merged 21 commits into from
Feb 22, 2021

Conversation

pugnascotia
Copy link
Contributor

@pugnascotia pugnascotia commented Jan 15, 2021

Part of #61656.

Migrate the .watches and .triggered_watches system indices to use the auto-create infrastructure. The watcher history indices are left alone.

As part of this work, a SystemIndexDescriptor now inspects its mappings to determine whether it has any dynamic mappings. This influences how strict Elasticsearch is with enforcing the descriptor's mappings, since ES cannot know in advanced what all the mappings will be.

This PR also fixes the SystemIndexManager so that it doesn't fall over when attempting to inspect the state of an index that hasn't been created yet.

@pugnascotia pugnascotia marked this pull request as ready for review January 19, 2021 14:29
@elasticmachine elasticmachine added Team:Data Management Meta label for data/management team Team:Core/Infra Meta label for core/infra team labels Jan 19, 2021
@elasticmachine
Copy link
Collaborator

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

@elasticmachine
Copy link
Collaborator

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

@pugnascotia pugnascotia requested a review from jaymode January 19, 2021 14:29
Copy link
Member

@jaymode jaymode left a comment

Choose a reason for hiding this comment

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

LGTM

@mark-vieira
Copy link
Contributor

@elasticmachine update branch

@pugnascotia
Copy link
Contributor Author

pugnascotia commented Feb 9, 2021

There's something very peculiar going on here. As far as I can tell:

  1. The Watcher asciidoc tests create a new watch. In the request payload, the new watch populates a metadata key with { color: red }, which is legitimate.
  2. Watcher submits an index request for the new watch
  3. This request gets turned into a bulk request.
  4. The bulk request notices that the .watches index doesn't exist, and submits an AutoCreateAction to create it.
  5. The index is created, as far as I can tell with the correct mappings from the system index descriptor
  6. But then a TransportAutoPutMappingAction fails because it tries to apply some incorrect mappings to the .watches system index - and it so happens that these new mappings match the metadata from the create watch payload. There's no reason that I can see why this metadata from the watcher payload should have any bearing on the mappings of the .watches index (but I could be wrong)
  7. As far as I can see, this action is raised as part of the replication code, at which point I'm lost.

@jaymode
Copy link
Member

jaymode commented Feb 9, 2021

But then a TransportAutoPutMappingAction fails because it tries to apply some incorrect mappings to the .watches system index - and it so happens that these new mappings match the metadata from the create watch payload. There's no reason that I can see why this metadata from the watcher payload should have any bearing on the mappings of the .watches index (but I could be wrong)

I think the issue is that watches have dynamic objects within the mapping including metadata among others. So when the watch is stored with metadata then the mappings need to be updated to account for the metadata.color field. I think Security will have the same issue for dynamic fields.

In order to resolve this, I think a change is needed to how mappings are validated. If a mapping contains dynamic fields then any fields contained within that object should be allowed. Make sense?

@pugnascotia
Copy link
Contributor Author

@elasticmachine update branch

@martijnvg martijnvg self-requested a review February 18, 2021 07:31
Copy link
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

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

From Watcher side LGTM. I did left a question for my own understanding.

@@ -597,57 +595,6 @@ public void onIndexModule(IndexModule module) {
module.addIndexOperationListener(listener);
}

static void validAutoCreateIndex(Settings settings, Logger logger) {
Copy link
Member

Choose a reason for hiding this comment

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

👍 (never liked this logic here)

builder.field("dynamic", "strict");
{
builder.startObject("_meta");
builder.field("version", Version.CURRENT);
Copy link
Member

Choose a reason for hiding this comment

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

The current template doesn't have a version field under they _meta object.
If I read the code correctly in SystemIndexManager this means that irregardless of that, a mapping update will be triggered?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@martijnvg it turns out that the SystemIndexManager would never have updated the mappings, because without a value for _metadata.version, the manager would always think that the version was the latest (because Version.fromString(null) returns Version.CURRENT). I've pushed a fix for that case.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for fixing that!

`SystemIndexManager.readMappingVersion` didn't take into account that
calling `Version.readString(null)` would return `Version.CURRENT`, which
would mean that an index with version metadata would never have its
mappings updated. Change the logic to return `Version.EMPTY` in this
case, so that the mappings will be updated.
@pugnascotia pugnascotia force-pushed the 61656-auto-create-watcher branch from 086ebdf to ce2d550 Compare February 19, 2021 20:46
@pugnascotia pugnascotia merged commit ae94701 into elastic:master Feb 22, 2021
@pugnascotia pugnascotia deleted the 61656-auto-create-watcher branch February 22, 2021 10:28
pugnascotia added a commit to pugnascotia/elasticsearch that referenced this pull request Feb 22, 2021
Part of elastic#61656.

Migrate the `.watches` and `.triggered_watches` system indices to use
the auto-create infrastructure. The watcher history indices are left
alone.

As part of this work, a `SystemIndexDescriptor` now inspects its
mappings to determine whether it has any dynamic mappings. This
influences how strict Elasticsearch is with enforcing the descriptor's
mappings, since ES cannot know in advanced what all the mappings will
be.

This PR also fixes the `SystemIndexManager` so that (1) it doesn't fall
over when attempting to inspect the state of an index that hasn't been
created yet, and (2) does update mappings if there's no version field in
the mapping metadata.
pugnascotia added a commit that referenced this pull request Feb 23, 2021
Backport of #67588. Part of #61656.

Migrate the `.watches` and `.triggered_watches` system indices to use
the auto-create infrastructure. The watcher history indices are left
alone.

As part of this work, a `SystemIndexDescriptor` now inspects its
mappings to determine whether it has any dynamic mappings. This
influences how strict Elasticsearch is with enforcing the descriptor's
mappings, since ES cannot know in advanced what all the mappings will
be.

This PR also fixes the `SystemIndexManager` so that (1) it doesn't fall
over when attempting to inspect the state of an index that hasn't been
created yet, and (2) does update mappings if there's no version field in
the mapping metadata.
ywangd added a commit that referenced this pull request Feb 24, 2021
Since #67588, .triggered_watches and .watches indices are no longer created on node startup. This PR removing them from the warnings for comparison.
ywangd added a commit to ywangd/elasticsearch that referenced this pull request Feb 24, 2021
Since elastic#67588, .triggered_watches and .watches indices are no longer created on node startup. This PR removing them from the warnings for comparison.
ywangd added a commit to ywangd/elasticsearch that referenced this pull request Feb 24, 2021
Since elastic#67588, .triggered_watches and .watches indices are no longer created on node startup. This PR removing them from the warnings for comparison.
ywangd added a commit that referenced this pull request Feb 24, 2021
Since #67588, .triggered_watches and .watches indices are no longer created on node startup. This PR removing them from the warnings for comparison.
andreidan added a commit to andreidan/elasticsearch that referenced this pull request Nov 22, 2021
We moved watcher to run on the system indices infrastructure in elastic#67588.
This commit makes sure Watcher cleans up the legacy templates it used
before it was migrated to system indices.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Core Core issues without another label :Data Management/Watcher >enhancement Team:Core/Infra Meta label for core/infra team Team:Data Management Meta label for data/management team v7.13.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants