Skip to content

Commit

Permalink
[8.0] [UA] - Add warning to accept for reindex (#122249)
Browse files Browse the repository at this point in the history
* [UA] Inform user about changes to reindexed data

* commit using @elastic.co

* Fix linter issues

* Fix integration test

Co-authored-by: Sébastien Loix <sabee77@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 11, 2022
1 parent 2ba281b commit d0cf489
Show file tree
Hide file tree
Showing 28 changed files with 578 additions and 119 deletions.
6 changes: 0 additions & 6 deletions x-pack/plugins/translations/translations/ja-JP.json
Expand Up @@ -26220,18 +26220,12 @@
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexButton.runReindexLabel": "再インデックスの開始",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexButton.tryAgainLabel": "再試行",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexDescription": "再インデックス中はインデックスが読み取り専用です。再インデックスが完了するまでは、ドキュメントの追加、更新、削除ができません。新しいクラスターを再インデックスする必要がある場合は、再インデックスAPIを使用します。{docsLink}",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.aliasSwapStepTitle": "元のインデックスをエイリアスと交換します。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.cancelButton.cancelLabel": "キャンセル",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.cancelButton.cancelledLabel": "キャンセル済み",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.cancelButton.cancellingLabel": "キャンセル中…",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.cancelButton.errorLabel": "キャンセルできませんでした",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.cancelledTitle": "再インデックスはキャンセルされました。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.createIndexStepTitle": "新しいインデックスを作成します。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.inProgress.aliasSwapStepTitle": "元のインデックスをエイリアスと交換しています。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.inProgress.createIndexStepTitle": "新しいインデックスを作成しています。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.inProgress.readonlyStepTitle": "元のインデックスを読み取り専用に設定しています。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.inProgress.reindexingDocumentsStepTitle": "ドキュメントを再インデックスしています。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.readonlyStepTitle": "元のインデックスを読み取り専用に設定します。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.reindexingDocumentsStepTitle": "ドキュメントのインデックスを作成します。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklistTitle": "プロセスを再インデックス中",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingFailedCalloutTitle": "再インデックスエラー",
Expand Down
6 changes: 0 additions & 6 deletions x-pack/plugins/translations/translations/zh-CN.json
Expand Up @@ -26673,18 +26673,12 @@
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexButton.runReindexLabel": "启动重新索引",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexButton.tryAgainLabel": "重试",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexDescription": "重新索引期间,索引将处于只读状态。在重新索引完成之前,您无法添加、更新或删除文档。如果需要重新索引到新集群,请使用重新索引 API。{docsLink}",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.aliasSwapStepTitle": "交换具有别名的原始索引。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.cancelButton.cancelLabel": "取消",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.cancelButton.cancelledLabel": "已取消",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.cancelButton.cancellingLabel": "正在取消……",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.cancelButton.errorLabel": "无法取消",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.cancelledTitle": "重新索引已取消。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.createIndexStepTitle": "创建新索引。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.inProgress.aliasSwapStepTitle": "正在交换具有别名的原始索引。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.inProgress.createIndexStepTitle": "正在创建新索引。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.inProgress.readonlyStepTitle": "正在将原始索引设置为只读。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.inProgress.reindexingDocumentsStepTitle": "正在重新索引文档。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.readonlyStepTitle": "将原始索引设置为只读。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.reindexingDocumentsStepTitle": "索引文档。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklistTitle": "重新索引过程",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingFailedCalloutTitle": "重新索引错误",
Expand Down
Expand Up @@ -27,6 +27,16 @@ describe('Default deprecation flyout', () => {
jobId: MOCK_JOB_ID,
status: 'idle',
});
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: null,
warnings: [],
hasRequiredPrivileges: true,
meta: {
indexName: 'foo',
reindexName: 'reindexed-foo',
aliases: [],
},
});

await act(async () => {
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
Expand Down
Expand Up @@ -34,6 +34,16 @@ describe('ES deprecations table', () => {
jobId: MOCK_JOB_ID,
status: 'idle',
});
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: null,
warnings: [],
hasRequiredPrivileges: true,
meta: {
indexName: 'foo',
reindexName: 'reindexed-foo',
aliases: [],
},
});

await act(async () => {
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
Expand Down
Expand Up @@ -28,6 +28,16 @@ describe('Index settings deprecation flyout', () => {
jobId: MOCK_JOB_ID,
status: 'idle',
});
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: null,
warnings: [],
hasRequiredPrivileges: true,
meta: {
indexName: 'foo',
reindexName: 'reindexed-foo',
aliases: [],
},
});

await act(async () => {
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
Expand Down
Expand Up @@ -30,6 +30,16 @@ describe('Machine learning deprecation flyout', () => {
jobId: MOCK_JOB_ID,
status: 'idle',
});
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: null,
warnings: [],
hasRequiredPrivileges: true,
meta: {
indexName: 'foo',
reindexName: 'reindexed-foo',
aliases: [],
},
});

await act(async () => {
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
Expand Down
Expand Up @@ -7,17 +7,28 @@

import { act } from 'react-dom/test-utils';

import { ReindexStatus, ReindexStep, ReindexStatusResponse } from '../../../common/types';
import { setupEnvironment } from '../helpers';
import { ElasticsearchTestBed, setupElasticsearchPage } from './es_deprecations.helpers';
import { esDeprecationsMockResponse, MOCK_SNAPSHOT_ID, MOCK_JOB_ID } from './mocked_responses';
import { ReindexStatus, ReindexStep } from '../../../common/types';

const defaultReindexStatusMeta: ReindexStatusResponse['meta'] = {
indexName: 'foo',
reindexName: 'reindexed-foo',
aliases: [],
};

// Note: The reindexing flyout UX is subject to change; more tests should be added here once functionality is built out
describe('Reindex deprecation flyout', () => {
let testBed: ElasticsearchTestBed;
const { server, httpRequestsMockHelpers } = setupEnvironment();

beforeAll(() => {
jest.useFakeTimers();
});

afterAll(() => {
jest.useRealTimers();
server.restore();
});

Expand All @@ -29,6 +40,16 @@ describe('Reindex deprecation flyout', () => {
jobId: MOCK_JOB_ID,
status: 'idle',
});
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: null,
warnings: [],
hasRequiredPrivileges: true,
meta: {
indexName: 'foo',
reindexName: 'reindexed-foo',
aliases: [],
},
});

await act(async () => {
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
Expand All @@ -54,6 +75,7 @@ describe('Reindex deprecation flyout', () => {
reindexOp: null,
warnings: [],
hasRequiredPrivileges: true,
meta: defaultReindexStatusMeta,
});

await act(async () => {
Expand Down Expand Up @@ -113,6 +135,7 @@ describe('Reindex deprecation flyout', () => {
},
warnings: [],
hasRequiredPrivileges: true,
meta: defaultReindexStatusMeta,
});

await act(async () => {
Expand All @@ -137,6 +160,7 @@ describe('Reindex deprecation flyout', () => {
},
warnings: [],
hasRequiredPrivileges: true,
meta: defaultReindexStatusMeta,
});

await act(async () => {
Expand All @@ -148,7 +172,7 @@ describe('Reindex deprecation flyout', () => {

await actions.table.clickDeprecationRowAt('reindex', 0);

expect(find('reindexChecklistTitle').text()).toEqual('Reindexing in progress… 31%');
expect(find('reindexChecklistTitle').text()).toEqual('Reindexing in progress… 30%');
expect(exists('cancelReindexingDocumentsButton')).toBe(true);
});

Expand All @@ -161,6 +185,7 @@ describe('Reindex deprecation flyout', () => {
},
warnings: [],
hasRequiredPrivileges: true,
meta: defaultReindexStatusMeta,
});

await act(async () => {
Expand All @@ -172,7 +197,7 @@ describe('Reindex deprecation flyout', () => {

await actions.table.clickDeprecationRowAt('reindex', 0);

expect(find('reindexChecklistTitle').text()).toEqual('Reindexing in progress… 95%');
expect(find('reindexChecklistTitle').text()).toEqual('Reindexing in progress… 90%');
expect(exists('cancelReindexingDocumentsButton')).toBe(false);
});

Expand All @@ -185,19 +210,30 @@ describe('Reindex deprecation flyout', () => {
},
warnings: [],
hasRequiredPrivileges: true,
meta: defaultReindexStatusMeta,
});

await act(async () => {
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});

testBed.component.update();
const { actions, find, exists } = testBed;
const { actions, find, exists, component } = testBed;
component.update();

await actions.table.clickDeprecationRowAt('reindex', 0);

expect(find('reindexChecklistTitle').text()).toEqual('Reindexing process');
expect(find('reindexChecklistTitle').text()).toEqual('Reindexing in progress… 95%');
expect(exists('cancelReindexingDocumentsButton')).toBe(false);

// We have put in place a "fake" fifth step to delete the original index
// In reality that was done in the last step (when the alias was created),
// but for the user we will display it as a separate reindex step
await act(async () => {
jest.advanceTimersByTime(1000);
});
component.update();

expect(find('reindexChecklistTitle').text()).toEqual('Reindexing process');
});
});
});
18 changes: 17 additions & 1 deletion x-pack/plugins/upgrade_assistant/common/types.ts
Expand Up @@ -28,6 +28,8 @@ export enum ReindexStep {
reindexStarted = 40,
reindexCompleted = 50,
aliasCreated = 60,
originalIndexDeleted = 70,
existingAliasesUpdated = 80,
}

export enum ReindexStatus {
Expand All @@ -41,7 +43,20 @@ export enum ReindexStatus {
fetchFailed,
}

export interface ReindexStatusResponse {
meta: {
indexName: string;
reindexName: string;
// Array of aliases pointing to the index being reindexed
aliases: string[];
};
warnings?: ReindexWarning[];
reindexOp?: ReindexOperation;
hasRequiredPrivileges?: boolean;
}

export const REINDEX_OP_TYPE = 'upgrade-assistant-reindex-operation';

export interface QueueSettings extends SavedObjectAttributes {
/**
* A Unix timestamp of when the reindex operation was enqueued.
Expand Down Expand Up @@ -106,7 +121,8 @@ export interface ReindexOperation extends SavedObjectAttributes {
export type ReindexSavedObject = SavedObject<ReindexOperation>;

// 7.0 -> 8.0 warnings
export type ReindexWarningTypes = 'customTypeName' | 'indexSetting';
export type ReindexWarningTypes = 'customTypeName' | 'indexSetting' | 'replaceIndexWithAlias';

export interface ReindexWarning {
warningType: ReindexWarningTypes;
/**
Expand Down
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useEffect, createContext, useContext } from 'react';
import React, { createContext, useContext } from 'react';

import { ApiService } from '../../../../lib/api';
import { useReindexStatus, ReindexState } from './use_reindex_state';
Expand Down Expand Up @@ -37,16 +37,11 @@ export const ReindexStatusProvider: React.FunctionComponent<Props> = ({
indexName,
children,
}) => {
const { reindexState, startReindex, cancelReindex, updateStatus } = useReindexStatus({
const { reindexState, startReindex, cancelReindex } = useReindexStatus({
indexName,
api,
});

useEffect(() => {
updateStatus();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<ReindexContext.Provider
value={{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -54,6 +54,11 @@ describe('ChecklistFlyout', () => {
errorMessage: null,
reindexWarnings: [],
hasRequiredPrivileges: true,
meta: {
indexName: 'myIndex',
reindexName: 'reindexed-myIndex',
aliases: [],
},
} as ReindexState,
};

Expand Down
Expand Up @@ -64,6 +64,7 @@ export const ReindexFlyout: React.FunctionComponent<ReindexFlyoutProps> = ({
const flyoutContents = showWarningsStep ? (
<WarningsFlyoutStep
warnings={reindexState.reindexWarnings ?? []}
meta={reindexState.meta}
hideWarningsStep={() => setShowWarningsStep(false)}
continueReindex={() => {
setShowWarningsStep(false);
Expand Down

0 comments on commit d0cf489

Please sign in to comment.