Bug fix: the filter of a data stream alias is not always properly removed.#139679
Conversation
|
Pinging @elastic/es-data-management (Team:Data Management) |
|
Hi @gmarouli, I've created a changelog YAML for you. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where filtered data stream aliases were not properly removed when an alias was deleted and then re-added without a filter. The filter from the original alias would persist incorrectly. Additionally, the PR adds handling for orphaned alias filters (filters that exist for data streams no longer in the alias).
Key Changes:
- Modified
DataStreamAlias.update()andDataStreamAlias.removeDataStream()to properly clean up filters when removing data streams or updating aliases without filters - Added capability flag
fix_filtered_data_stream_alias_removalto track this fix - Added comprehensive test coverage for filtered alias removal and orphaned filter cleanup
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| DataStreamAlias.java | Core logic fix to properly remove filters when updating or removing data streams from aliases |
| DataStreamAliasTests.java | Added unit tests for filtered data stream removal and orphaned filter cleanup |
| RestIndicesAliasesAction.java | Added capability flag to indicate the bug fix is available |
| 140_data_stream_aliases.yml | Added integration test verifying filtered alias removal behavior |
| 139679.yaml | Changelog entry documenting the bug fix |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (filterAsMap != null || dataStreamToFilterMap.containsKey(dataStream)) { | ||
| CompressedXContent previousFilter = dataStreamToFilterMap.get(dataStream); | ||
| if (previousFilter == null) { | ||
| if (previousFilter == null || filterAsMap == null) { |
There was a problem hiding this comment.
The condition previousFilter == null || filterAsMap == null could be clearer. Consider splitting this into separate conditions with explicit comments explaining when each case occurs (adding a new filter vs. removing an existing filter).
lukewhiting
left a comment
There was a problem hiding this comment.
Looks good to me 👍🏻 Thanks for sorting this!
…oved. (elastic#139679) A data stream alias that has more than 1 data stream does not handle correctly the removal of a filtered data stream alias. It currently retains the filter even after the alias is removed. ``` # Create 2 data streams PUT _data_stream/logs-yyy-default PUT _data_stream/logs-xxx-default # Add a filtered alias to one and a simple alias to the other. POST _aliases { "actions": [ { "add": { "index": "logs-yyy-default", "alias": "myalias", "filter": { "term": { "type": "mytype" } } } }, { "add": { "index": "logs-xxx-default", "alias": "myalias" } } ] } # Remove the filtered alias POST _aliases { "actions": [ { "remove": { "index": "logs-yyy-default", "alias": "myalias" } } ] } # Add back the alias but WITHOUT filter POST _aliases { "actions": [ { "add": { "index": "logs-yyy-default", "alias": "myalias" } } ] } ``` The last alias will contain the initial filter while it should not. This PR fixes that. Furthermore, we edit the update and removal of data streams from an alias to be able to handle orphaned aliases.
…oved. (elastic#139679) A data stream alias that has more than 1 data stream does not handle correctly the removal of a filtered data stream alias. It currently retains the filter even after the alias is removed. ``` # Create 2 data streams PUT _data_stream/logs-yyy-default PUT _data_stream/logs-xxx-default # Add a filtered alias to one and a simple alias to the other. POST _aliases { "actions": [ { "add": { "index": "logs-yyy-default", "alias": "myalias", "filter": { "term": { "type": "mytype" } } } }, { "add": { "index": "logs-xxx-default", "alias": "myalias" } } ] } # Remove the filtered alias POST _aliases { "actions": [ { "remove": { "index": "logs-yyy-default", "alias": "myalias" } } ] } # Add back the alias but WITHOUT filter POST _aliases { "actions": [ { "add": { "index": "logs-yyy-default", "alias": "myalias" } } ] } ``` The last alias will contain the initial filter while it should not. This PR fixes that. Furthermore, we edit the update and removal of data streams from an alias to be able to handle orphaned aliases.
…oved. (#139679) (#139688) A data stream alias that has more than 1 data stream does not handle correctly the removal of a filtered data stream alias. It currently retains the filter even after the alias is removed. ``` # Create 2 data streams PUT _data_stream/logs-yyy-default PUT _data_stream/logs-xxx-default # Add a filtered alias to one and a simple alias to the other. POST _aliases { "actions": [ { "add": { "index": "logs-yyy-default", "alias": "myalias", "filter": { "term": { "type": "mytype" } } } }, { "add": { "index": "logs-xxx-default", "alias": "myalias" } } ] } # Remove the filtered alias POST _aliases { "actions": [ { "remove": { "index": "logs-yyy-default", "alias": "myalias" } } ] } # Add back the alias but WITHOUT filter POST _aliases { "actions": [ { "add": { "index": "logs-yyy-default", "alias": "myalias" } } ] } ``` The last alias will contain the initial filter while it should not. This PR fixes that. Furthermore, we edit the update and removal of data streams from an alias to be able to handle orphaned aliases.
…oved. (#139679) (#139689) A data stream alias that has more than 1 data stream does not handle correctly the removal of a filtered data stream alias. It currently retains the filter even after the alias is removed. ``` # Create 2 data streams PUT _data_stream/logs-yyy-default PUT _data_stream/logs-xxx-default # Add a filtered alias to one and a simple alias to the other. POST _aliases { "actions": [ { "add": { "index": "logs-yyy-default", "alias": "myalias", "filter": { "term": { "type": "mytype" } } } }, { "add": { "index": "logs-xxx-default", "alias": "myalias" } } ] } # Remove the filtered alias POST _aliases { "actions": [ { "remove": { "index": "logs-yyy-default", "alias": "myalias" } } ] } # Add back the alias but WITHOUT filter POST _aliases { "actions": [ { "add": { "index": "logs-yyy-default", "alias": "myalias" } } ] } ``` The last alias will contain the initial filter while it should not. This PR fixes that. Furthermore, we edit the update and removal of data streams from an alias to be able to handle orphaned aliases.
…oved. (#139679) (#139691) A data stream alias that has more than 1 data stream does not handle correctly the removal of a filtered data stream alias. It currently retains the filter even after the alias is removed. ``` # Create 2 data streams PUT _data_stream/logs-yyy-default PUT _data_stream/logs-xxx-default # Add a filtered alias to one and a simple alias to the other. POST _aliases { "actions": [ { "add": { "index": "logs-yyy-default", "alias": "myalias", "filter": { "term": { "type": "mytype" } } } }, { "add": { "index": "logs-xxx-default", "alias": "myalias" } } ] } # Remove the filtered alias POST _aliases { "actions": [ { "remove": { "index": "logs-yyy-default", "alias": "myalias" } } ] } # Add back the alias but WITHOUT filter POST _aliases { "actions": [ { "add": { "index": "logs-yyy-default", "alias": "myalias" } } ] } ``` The last alias will contain the initial filter while it should not. This PR fixes that. Furthermore, we edit the update and removal of data streams from an alias to be able to handle orphaned aliases.
A data stream alias that has more than 1 data stream does not handle correctly the removal of a filtered data stream alias. It currently retains the filter even after the alias is removed.
The last alias will contain the initial filter while it should not. This PR fixes that.
Furthermore, we edit the update and removal of data streams from an alias to be able to handle orphaned aliases.