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

[Fleet] Update data streams mappings directly instead of against backing indices #89660

Merged
merged 5 commits into from
Feb 1, 2021

Conversation

jen-huang
Copy link
Contributor

@jen-huang jen-huang commented Jan 29, 2021

Summary

Resolves #89436. This fixes the concurrent rollover errors when upgrading a package that 1) has incompatible mappings and 2) already has data streams created with different namespaces.

In the case when we detect incompatible mappings, we trigger a rollover on the data stream instead. When this code was written originally in #69180, Elasticsearch did not support updating mappings on the data stream directly, so we had to workaround it by querying for the backing indices. This caused problems when there are multiple namespaces.

ES added support for updating data stream mappings directly in elastic/elasticsearch#58231 (corresponding docs).

This PR:

  1. Returns the data stream name to work with, instead of the last backing index name (aka the write index): LOC
  2. Sends the mapping update attempt against the data stream with write_index_only parameter to protect data in backing indices: LOC
  3. Removes the subsequent query to solve for the data stream name before calling rollover: LOC
  4. Changes variable and method names to reflect working with a data stream, instead of indices (hence the line changes 😉 )

The corresponding API integration test suite was updated to perform against multiple data streams with multiple namespaces.

… indices, update integration tests to test with multiple namespaces
@jen-huang jen-huang added bug Fixes for quality problems that affect the customer experience v8.0.0 Feature:EPM Fleet team's Elastic Package Manager (aka Integrations) project Team:Fleet Team label for Observability Data Collection Fleet team v7.12.0 v7.11.1 labels Jan 29, 2021
@jen-huang jen-huang requested a review from a team January 29, 2021 01:03
@jen-huang jen-huang self-assigned this Jan 29, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Feature:EPM)

@elasticmachine
Copy link
Contributor

Pinging @elastic/ingest-management (Team:Ingest Management)

@jen-huang jen-huang added release_note:skip Skip the PR/issue when compiling release notes release_note:fix v7.10.3 v7.11.0 and removed release_note:skip Skip the PR/issue when compiling release notes v7.11.1 labels Jan 29, 2021
@neptunian
Copy link
Contributor

neptunian commented Jan 29, 2021

Looks great! This really simplifies things. Though I'd like to make sure, is there any concern about updating all the backing indices of the datastream? The docs say "Changing the mapping of an existing field could invalidate any data that’s already indexed". Is that expected? There is a write_index_only parameter option now so we wouldn't need to query for indices in this case either. CC @ruflin

@jen-huang
Copy link
Contributor Author

@neptunian Thanks for pointing that out! I'm not sure about what the consequences of updating all backing indices mappings are, but it sounds like setting write_index_only would be a good idea to maintain parity with the previous code (where we look for the last backing index to update against). I'd like to hear @ruflin's opinion too, but I'll update the PR with that flag in the meantime.

return updateExistingIndex({ indexName, callCluster, indexTemplate });
});
await Promise.all(updateIndexPromises);
const updatedataStreamPromises = indexNameWithTemplates.map(
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be moved inside the Promise.all. If updateExistingDataStream throws/rejects before the await Promise.all line we'll crash due to UnhandledPromiseRejection

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jfsiii Can you elaborate or provide revised code? updatedataStreamPromises is passed to the Promise.all and updateExistingDataStream is async?

Also, I didn't change the logic here, just renaming. Due to being this a priority fix, I might merge this and follow up on code improvements based on your feedback afterwards.

@ruflin
Copy link
Member

ruflin commented Feb 1, 2021

We should not try to update all backing indices but only the one we currently write to. Otherwise it would update many indices where the new mapping does not matter and in addition it would slow down. Also it would probably trigger a rollover if just a single old index does not match the mapping, so rollover from there forward would always happen. write_index_only sounds like the right flag.

@ruflin
Copy link
Member

ruflin commented Feb 1, 2021

@EricDavisX It would be great if we could add a test case to our e2e using multiple namespaces to uncover this issue here.

@jen-huang
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jen-huang jen-huang merged commit cb16a5c into elastic:master Feb 1, 2021
@jen-huang jen-huang deleted the fix/concurrent-rollovers branch February 1, 2021 17:24
jen-huang added a commit to jen-huang/kibana that referenced this pull request Feb 1, 2021
…ing indices (elastic#89660)

* Update data streams mappings directly instead of querying for backing indices, update integration tests to test with multiple namespaces

* Add flag to only update mappings of the current write index

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
jen-huang added a commit to jen-huang/kibana that referenced this pull request Feb 1, 2021
…ing indices (elastic#89660)

* Update data streams mappings directly instead of querying for backing indices, update integration tests to test with multiple namespaces

* Add flag to only update mappings of the current write index

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts
#	x-pack/test/fleet_api_integration/apis/epm/data_stream.ts
jen-huang added a commit that referenced this pull request Feb 1, 2021
…ing indices (#89660) (#89892)

* Update data streams mappings directly instead of querying for backing indices, update integration tests to test with multiple namespaces

* Add flag to only update mappings of the current write index

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
jen-huang added a commit that referenced this pull request Feb 1, 2021
…ing indices (#89660) (#89891)

* Update data streams mappings directly instead of querying for backing indices, update integration tests to test with multiple namespaces

* Add flag to only update mappings of the current write index

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
jen-huang added a commit that referenced this pull request Feb 1, 2021
…ing indices (#89660) (#89896)

* Update data streams mappings directly instead of querying for backing indices, update integration tests to test with multiple namespaces

* Add flag to only update mappings of the current write index

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts
#	x-pack/test/fleet_api_integration/apis/epm/data_stream.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:EPM Fleet team's Elastic Package Manager (aka Integrations) project release_note:fix Team:Fleet Team label for Observability Data Collection Fleet team v7.10.3 v7.11.0 v7.12.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fleet] Datastream rollovers for an integration do not rollover with the right namespace
7 participants