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

search-backend-module-elasticsearch: ensure all stale indices are deleted #24682

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tcardonne
Copy link
Contributor

Hey, I just made a Pull Request!

We ran into a case where the indexer would fail but leave a half-filled index without deleting it (#24680 should allow us to understand why).
As indices are not deleted, we're exhausting the allowed number of shards on our OpenSearch cluster.

This PR changes the way stale indices are cleaned. Instead of relying on aliases, we simply list indices that match the indexer's pattern (some-type-index__*) and delete them after indexation.

I've marked the change as breaking because someone may use some-type-index__some-index-that-shouldnt-be-deleted as an index name (not managed by Backstage Search).
However the wildcard pattern is already used to remove aliases, so IMHO we can commit to use the pattern to detect and delete stale indices.

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

@tcardonne tcardonne requested a review from a team as a code owner May 7, 2024 22:53
@github-actions github-actions bot added search Things related to Search area:discoverability Related to the Discoverability Project Area labels May 7, 2024
@backstage-goalie
Copy link
Contributor

backstage-goalie bot commented May 7, 2024

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/plugin-search-backend-module-elasticsearch plugins/search-backend-module-elasticsearch minor v1.4.2-next.0

djamaile
djamaile previously approved these changes May 8, 2024
@djamaile djamaile dismissed their stale review May 8, 2024 09:23

Need to mark alias function as deprecated

@tcardonne
Copy link
Contributor Author

Hi @djamaile, thanks for the review!

I've re-added getAliases on ElasticSearchClientWrapper and marked it as deprecated. Not sure about the deprecation message, hope it works this way 🤞

@tcardonne tcardonne force-pushed the fix-search-es-stale-indices-2 branch from c800132 to 2dbc917 Compare May 8, 2024 10:33
.changeset/wild-eyes-grab.md Outdated Show resolved Hide resolved

**BREAKING** The ElasticSearch indexer will now delete stale indices matching the indexer's pattern.

An indexer using the `some-type-index__*` pattern will remove indices matching this pattern after indexation
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there an action that the adopter should take before upgrading to this new version? For example, updating their index patterns 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added an action to verify that the pattern isn't conflicting with other indices not managed by Backstage
(which should already be an "issue" since the indexer removes aliases on these indices)

@tcardonne tcardonne force-pushed the fix-search-es-stale-indices-2 branch from 2dbc917 to ab43b4b Compare May 17, 2024 08:49
@backstage-goalie
Copy link
Contributor

Thanks for the contribution!
All commits need to be DCO signed before they are reviewed. Please refer to the the DCO section in CONTRIBUTING.md or the DCO status for more info.

@tcardonne tcardonne force-pushed the fix-search-es-stale-indices-2 branch from ab43b4b to 4a08cc0 Compare May 17, 2024 08:51
…re deleted

Signed-off-by: Thomas Cardonne <thomas.cardonne@adevinta.com>
Signed-off-by: Thomas Cardonne <thomas.cardonne@adevinta.com>
Signed-off-by: Thomas Cardonne <thomas.cardonne@adevinta.com>
Signed-off-by: Thomas Cardonne <thomas.cardonne@adevinta.com>
@tcardonne tcardonne force-pushed the fix-search-es-stale-indices-2 branch from 4a08cc0 to f5d433a Compare May 23, 2024 12:10
Signed-off-by: Thomas Cardonne <thomas.cardonne@adevinta.com>
@tcardonne tcardonne force-pushed the fix-search-es-stale-indices-2 branch from f5d433a to 5eba6fc Compare May 23, 2024 12:10
@tcardonne
Copy link
Contributor Author

Hi @djamaile,

I've updated the PR to handle deletion in chunks of 50 indices to fix an issue that can occur when having a lot of stale indices to delete.

The indices delete method in ES/OS clients generate a DELETE /index1,index2,index3.. request, and since the size of an URL is limited, it fails to send the delete request for ~200-300 indices (depending on the pattern size).
To mitigate this I'm splitting the removableIndices array in chunks of 50 indices.

Let me know if something's needed to move this forward!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:discoverability Related to the Discoverability Project Area search Things related to Search
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants