forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Upgrade Assistant] Better handling of closed indices (elastic#58890)
* Exclude disallowed, private setting at index creation * Remove intl from tabs component * Added logic for checking the current index status * Added ES contract integration test Using _cluster/state is considered internal. This adds an integration test for checking the contract in CI. * Add the client side notification for closed indices * First version of end-to-end functionality working * Clean up unused, incorrect type information * Fix type issues and added a comment about the new reindex options * Fixed server side tests, added comments and logic updates Updated the handling of reindexOptions to make it more backwards compatible (treat it as if it could be undefined). Also update the logic for checking for open or closed indices. No optional chaining! It should break if the response does not exactly match. * Clean up unused code * Improved idempotency of test and check explicitly for "close". Rather check for the specific value we want, as this is what is also gauranteed by the tests. In this way, the information we send back to the client is also more accurate regarding the index status. If, in future, more index states are introduced this will need to be revisited if it affects the ability for an index to be re-indexed. * Update client-side tests * Fix types * Handle a case where the index name provided may be an alias * Fix types * merge-conflict: finish merge conflict resolution * Update x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/reindex/closed_warning_icon.tsx Co-Authored-By: Alison Goryachev <alisonmllr20@gmail.com> * merge-conflict: Remove duplicate import VSCode does not auto-save as expected :sigh: * ui: Revisit the UI Moved the warning icon to inside of the button and tooltip to on the button. Added a callout to the reindex flyout for when an index is closed. * logic: slight update to when the index closed callout is shown We only show the index closed callout in the flyout when the reindex operation is not considered "completed" * tests: fix jest tests * refactor: remove "openAndClose" from reindex endpoints "openAndClose" should just happen automatically. The user should not have to pass the flag in, that would be a weird API. We just need to warn the user about that reindexing a closed index will take more resources * test: update upgrade assistant integration test * fix: types * copy: use sentence case * refactor: use the in scope declaration of reindex op * test: Clean up tests Reindexing test was generating index name, could just get it from server response. Also removed openAndClose from all integration tests Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Alison Goryachev <alisonmllr20@gmail.com> # Conflicts: # x-pack/plugins/upgrade_assistant/common/types.ts # x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/cell.tsx # x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/index_table.tsx # x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/list.test.tsx # x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/list.tsx # x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/reindex/button.tsx # x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/reindex/flyout/checklist_step.test.tsx # x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/reindex/flyout/checklist_step.tsx # x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/reindex/flyout/container.tsx # x-pack/plugins/upgrade_assistant/server/lib/__snapshots__/es_migration_apis.test.ts.snap # x-pack/plugins/upgrade_assistant/server/lib/reindexing/reindex_service.ts
- Loading branch information
1 parent
5f06b79
commit d62e400
Showing
32 changed files
with
597 additions
and
126 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
x-pack/plugins/upgrade_assistant/common/get_index_state_from_cluster_state.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { getIndexStateFromClusterState } from './get_index_state_from_cluster_state'; | ||
import { ClusterStateAPIResponse } from './types'; | ||
|
||
describe('getIndexStateFromClusterState', () => { | ||
const indexName = 'indexName'; | ||
const clusterState: ClusterStateAPIResponse = { | ||
metadata: { | ||
indices: {}, | ||
cluster_coordination: {} as any, | ||
cluster_uuid: 'test', | ||
templates: {} as any, | ||
}, | ||
cluster_name: 'test', | ||
cluster_uuid: 'test', | ||
}; | ||
|
||
afterEach(() => { | ||
clusterState.metadata.indices = {}; | ||
}); | ||
|
||
it('correctly extracts state from cluster state', () => { | ||
clusterState.metadata.indices[indexName] = { state: 'open' } as any; | ||
clusterState.metadata.indices.aTotallyDifferentIndex = { state: 'close' } as any; | ||
expect(getIndexStateFromClusterState(indexName, clusterState)).toBe('open'); | ||
}); | ||
|
||
it('correctly extracts state from aliased index in cluster state', () => { | ||
clusterState.metadata.indices.aTotallyDifferentName = { | ||
state: 'close', | ||
aliases: [indexName, 'test'], | ||
} as any; | ||
clusterState.metadata.indices.aTotallyDifferentName1 = { | ||
state: 'open', | ||
aliases: ['another', 'test'], | ||
} as any; | ||
|
||
expect(getIndexStateFromClusterState(indexName, clusterState)).toBe('close'); | ||
}); | ||
|
||
it('throws if the index name cannot be found in the cluster state', () => { | ||
expect(() => getIndexStateFromClusterState(indexName, clusterState)).toThrow('not found'); | ||
clusterState.metadata.indices.aTotallyDifferentName1 = { | ||
state: 'open', | ||
aliases: ['another', 'test'], | ||
} as any; | ||
expect(() => getIndexStateFromClusterState(indexName, clusterState)).toThrow('not found'); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/upgrade_assistant/common/get_index_state_from_cluster_state.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { ClusterStateAPIResponse } from './types'; | ||
|
||
const checkAllAliases = ( | ||
indexName: string, | ||
clusterState: ClusterStateAPIResponse | ||
): 'open' | 'close' => { | ||
for (const index of Object.values(clusterState.metadata.indices)) { | ||
if (index.aliases?.some(alias => alias === indexName)) { | ||
return index.state; | ||
} | ||
} | ||
|
||
throw new Error(`${indexName} not found in cluster state!`); | ||
}; | ||
|
||
export const getIndexStateFromClusterState = ( | ||
indexName: string, | ||
clusterState: ClusterStateAPIResponse | ||
): 'open' | 'close' => | ||
clusterState.metadata.indices[indexName] | ||
? clusterState.metadata.indices[indexName].state | ||
: checkAllAliases(indexName, clusterState); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.