Skip to content

Commit

Permalink
[main] [UA] Preserve hidden status of original index during reindexing (
Browse files Browse the repository at this point in the history
elastic#209512) (elastic#209540)

Close elastic#209471

# Backport

This will backport the following commits from `8.18` to `main`:
- [[UA] Preserve hidden status of original index during reindexing
(elastic#209512)](elastic#209512)

<!--- Backport version: 9.6.4 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Jean-Louis
Leysens","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-02-04T13:20:51Z","message":"[UA]
Preserve hidden status of original index during reindexing
(elastic#209512)","sha":"ed5b521cb491ccb4e1491190f221209de1c2a90f","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","Feature:Upgrade
Assistant","backport:skip"],"title":"[UA] Preserve hidden status of
original index during
reindexing","number":209512,"url":"https://github.com/elastic/kibana/pull/209512","mergeCommit":{"message":"[UA]
Preserve hidden status of original index during reindexing
(elastic#209512)","sha":"ed5b521cb491ccb4e1491190f221209de1c2a90f"}},"sourceBranch":"8.18","suggestedTargetBranches":[],"targetPullRequestStates":[]}]
BACKPORT-->
  • Loading branch information
jloleysens authored Feb 4, 2025
1 parent 23d926f commit b874212
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -799,18 +799,42 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.aliasCreated);
expect(clusterClient.asCurrentUser.indices.updateAliases).toHaveBeenCalledWith({
actions: [
{ add: { index: 'myIndex-reindex-0', alias: 'myIndex' } },
{ add: { index: 'myIndex-reindex-0', alias: 'myIndex', is_hidden: false } },
{ remove_index: { index: 'myIndex' } },
],
});
});

it.each([true, 'true'])(
'switches aliases, passing on hidden status of index to alias if defined (hidden value: %p)',
async (hidden) => {
clusterClient.asCurrentUser.indices.getAlias.mockResponseOnce({
myIndex: { aliases: {} },
});
clusterClient.asCurrentUser.indices.getSettings.mockResponseOnce({
myIndex: { settings: { index: { hidden } } },
});
clusterClient.asCurrentUser.indices.updateAliases.mockResponseOnce({
acknowledged: true,
});
const updatedOp = await service.processNextStep(reindexOp);
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.aliasCreated);
expect(clusterClient.asCurrentUser.indices.updateAliases).toHaveBeenCalledWith({
actions: [
{ add: { index: 'myIndex-reindex-0', alias: 'myIndex', is_hidden: true } },
{ remove_index: { index: 'myIndex' } },
],
});
}
);

it('moves existing aliases over to new index', async () => {
clusterClient.asCurrentUser.indices.getAlias.mockResponseOnce({
myIndex: {
aliases: {
myAlias: {},
myFilteredAlias: { filter: { term: { https: true } } },
myHiddenAlias: { is_hidden: true },
},
},
});
Expand All @@ -821,7 +845,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.lastCompletedStep).toEqual(ReindexStep.aliasCreated);
expect(clusterClient.asCurrentUser.indices.updateAliases).toHaveBeenCalledWith({
actions: [
{ add: { index: 'myIndex-reindex-0', alias: 'myIndex' } },
{ add: { index: 'myIndex-reindex-0', alias: 'myIndex', is_hidden: false } },
{ remove_index: { index: 'myIndex' } },
{ add: { index: 'myIndex-reindex-0', alias: 'myAlias' } },
{
Expand All @@ -831,6 +855,13 @@ describe('reindexService', () => {
filter: { term: { https: true } },
},
},
{
add: {
index: 'myIndex-reindex-0',
alias: 'myHiddenAlias',
is_hidden: true,
},
},
],
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ export const reindexServiceFactory = (
return response[indexName]?.aliases ?? {};
};

const isIndexHidden = async (indexName: string) => {
const response = await esClient.indices.getSettings({ index: indexName });
const isHidden = response[indexName]?.settings?.index?.hidden;
return isHidden === true || isHidden === 'true';
};

/**
* Restores the original index settings in the new index that had other defaults for reindexing performance reasons
* @param reindexOp
Expand Down Expand Up @@ -391,9 +397,11 @@ export const reindexServiceFactory = (
add: { index: newIndexName, alias: aliasName, ...existingAliases[aliasName] },
}));

const isHidden = await isIndexHidden(indexName);

const aliasResponse = await esClient.indices.updateAliases({
actions: [
{ add: { index: newIndexName, alias: indexName } },
{ add: { index: newIndexName, alias: indexName, is_hidden: isHidden } },
{ remove_index: { index: indexName } },
...extraAliases,
],
Expand Down

0 comments on commit b874212

Please sign in to comment.