Skip to content

Commit

Permalink
[8.18] [UA] Implement read-only and unfreeze flows for indices (elast…
Browse files Browse the repository at this point in the history
…ic#210199) (elastic#211361)

# Backport

This will backport the following commits from `8.x` to `8.18`:
- [[UA] Implement read-only and unfreeze flows for indices
(elastic#210199)](elastic#210199)

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

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

<!--BACKPORT [{"author":{"name":"Gerard
Soldevila","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-02-14T16:09:38Z","message":"[UA]
Implement read-only and unfreeze flows for indices (elastic#210199)\n\n##
Summary\r\n\r\nAddress
https://github.com/elastic/kibana-team/issues/1418,\r\nhttps://github.com/elastic/kibana/issues/205945\r\n\r\n*
Implement the \"make readonly\" flow for _old index_ deprecations.\r\n*
Implement the \"unfreeze\" flow for _old indices_ that are frozen
and\r\n`verified_read_only: true` (making them read-only is no longer an
option\r\nfor those).\r\n* Refactor the code so that the \"reindex\"
flyout steps are generalised\r\nto support the new flows.\r\n* Rename
vars with misleading names
(see\r\nhttps://github.com/elastic/pull/209522).\r\n\r\n---------\r\n\r\nCo-authored-by:
Rudolf Meijering
<[email protected]>","sha":"3768c353b4ba0420e7d4e55100312d88b727cb3c","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","v9.0.0","backport:version","v8.18.0"],"title":"[UA]
Implement read-only and unfreeze flows for
indices","number":210199,"url":"https://github.com/elastic/kibana/pull/210199","mergeCommit":{"message":"[UA]
Implement read-only and unfreeze flows for indices (elastic#210199)\n\n##
Summary\r\n\r\nAddress
https://github.com/elastic/kibana-team/issues/1418,\r\nhttps://github.com/elastic/kibana/issues/205945\r\n\r\n*
Implement the \"make readonly\" flow for _old index_ deprecations.\r\n*
Implement the \"unfreeze\" flow for _old indices_ that are frozen
and\r\n`verified_read_only: true` (making them read-only is no longer an
option\r\nfor those).\r\n* Refactor the code so that the \"reindex\"
flyout steps are generalised\r\nto support the new flows.\r\n* Rename
vars with misleading names
(see\r\nhttps://github.com/elastic/pull/209522).\r\n\r\n---------\r\n\r\nCo-authored-by:
Rudolf Meijering
<[email protected]>","sha":"3768c353b4ba0420e7d4e55100312d88b727cb3c"}},"sourceBranch":"8.x","suggestedTargetBranches":["9.0","8.18"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
  • Loading branch information
gsoldevila authored Feb 16, 2025
1 parent f11680d commit 8b1f5f1
Show file tree
Hide file tree
Showing 62 changed files with 2,828 additions and 830 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ export const getDocLinks = ({ kibanaBranch, buildFlavor }: GetDocLinkOptions): D
upgradeAssistant: {
overview: `${KIBANA_DOCS}upgrade-assistant.html`,
batchReindex: `${KIBANA_DOCS}batch-start-resume-reindex.html`,
indexBlocks: `${ELASTICSEARCH_DOCS}index-modules-blocks.html#index-block-settings`,
remoteReindex: `${ELASTICSEARCH_DOCS}docs-reindex.html#reindex-from-remote`,
unfreezeApi: `${ELASTICSEARCH_DOCS}unfreeze-index-api.html`,
reindexWithPipeline: `${ELASTICSEARCH_DOCS}docs-reindex.html#reindex-with-an-ingest-pipeline`,
Expand Down
1 change: 1 addition & 0 deletions src/platform/packages/shared/kbn-doc-links/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ export interface DocLinks {
readonly upgradeAssistant: {
readonly overview: string;
readonly batchReindex: string;
readonly indexBlocks: string;
readonly remoteReindex: string;
readonly unfreezeApi: string;
readonly reindexWithPipeline: string;
Expand Down
112 changes: 56 additions & 56 deletions x-pack/platform/plugins/private/translations/translations/fr-FR.json

Large diffs are not rendered by default.

112 changes: 56 additions & 56 deletions x-pack/platform/plugins/private/translations/translations/ja-JP.json

Large diffs are not rendered by default.

112 changes: 56 additions & 56 deletions x-pack/platform/plugins/private/translations/translations/zh-CN.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const defaultReindexStatusMeta: ReindexStatusResponse['meta'] = {
indexName: 'foo',
reindexName: 'reindexed-foo',
aliases: [],
isFrozen: false,
isReadonly: false,
};

describe('Reindex deprecation flyout', () => {
Expand Down Expand Up @@ -75,28 +77,22 @@ describe('Reindex deprecation flyout', () => {

expect(exists('reindexDetails')).toBe(true);
expect(find('reindexDetails.flyoutTitle').text()).toContain(
`Reindex ${reindexDeprecation.index}`
`Update ${reindexDeprecation.index}`
);
});

it('renders error callout when reindex fails', async () => {
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup);
});

testBed.component.update();

const { actions, exists } = testBed;

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

httpRequestsMockHelpers.setStartReindexingResponse(MOCK_REINDEX_DEPRECATION.index!, undefined, {
statusCode: 404,
message: 'no such index [test]',
});

await actions.reindexDeprecationFlyout.clickReindexButton();
const { actions, exists } = testBed;

await actions.table.clickDeprecationRowAt('reindex', 0);
await actions.reindexDeprecationFlyout.clickReindexButton(); // details step
await actions.reindexDeprecationFlyout.clickReindexButton(); // warning step
expect(exists('reindexDetails')).toBe(true);
expect(exists('reindexDetails.reindexingFailedCallout')).toBe(true);
});

Expand All @@ -106,28 +102,16 @@ describe('Reindex deprecation flyout', () => {
message: 'no such index [test]',
});

await act(async () => {
testBed = await setupElasticsearchPage(httpSetup);
});

testBed.component.update();

const { actions, exists } = testBed;

await actions.table.clickDeprecationRowAt('reindex', 0);
await actions.reindexDeprecationFlyout.clickReindexButton(); // details step
await actions.reindexDeprecationFlyout.clickReindexButton(); // warning step

expect(exists('reindexDetails.fetchFailedCallout')).toBe(true);
});

describe('reindexing progress', () => {
it('has not started yet', async () => {
const { actions, find, exists } = testBed;

await actions.table.clickDeprecationRowAt('reindex', 0);
expect(find('reindexChecklistTitle').text()).toEqual('Reindexing process');
expect(exists('cancelReindexingDocumentsButton')).toBe(false);
});

it('has started but not yet reindexing documents', async () => {
httpRequestsMockHelpers.setReindexStatusResponse(MOCK_REINDEX_DEPRECATION.index!, {
reindexOp: {
Expand All @@ -140,14 +124,11 @@ describe('Reindex deprecation flyout', () => {
meta: defaultReindexStatusMeta,
});

await act(async () => {
testBed = await setupElasticsearchPage(httpSetup);
});

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

await actions.table.clickDeprecationRowAt('reindex', 0);
await actions.reindexDeprecationFlyout.clickReindexButton(); // details step
await actions.reindexDeprecationFlyout.clickReindexButton(); // warning step

expect(find('reindexChecklistTitle').text()).toEqual('Reindexing in progress… 5%');
expect(exists('cancelReindexingDocumentsButton')).toBe(false);
Expand All @@ -165,14 +146,11 @@ describe('Reindex deprecation flyout', () => {
meta: defaultReindexStatusMeta,
});

await act(async () => {
testBed = await setupElasticsearchPage(httpSetup);
});

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

await actions.table.clickDeprecationRowAt('reindex', 0);
await actions.reindexDeprecationFlyout.clickReindexButton(); // details step
await actions.reindexDeprecationFlyout.clickReindexButton(); // warning step

expect(find('reindexChecklistTitle').text()).toEqual('Reindexing in progress… 30%');
expect(exists('cancelReindexingDocumentsButton')).toBe(true);
Expand All @@ -190,14 +168,11 @@ describe('Reindex deprecation flyout', () => {
meta: defaultReindexStatusMeta,
});

await act(async () => {
testBed = await setupElasticsearchPage(httpSetup);
});

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

await actions.table.clickDeprecationRowAt('reindex', 0);
await actions.reindexDeprecationFlyout.clickReindexButton(); // details step
await actions.reindexDeprecationFlyout.clickReindexButton(); // warning step

expect(find('reindexChecklistTitle').text()).toEqual('Reindexing in progress… 90%');
expect(exists('cancelReindexingDocumentsButton')).toBe(false);
Expand All @@ -215,14 +190,11 @@ describe('Reindex deprecation flyout', () => {
meta: defaultReindexStatusMeta,
});

await act(async () => {
testBed = await setupElasticsearchPage(httpSetup);
});

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

await actions.table.clickDeprecationRowAt('reindex', 0);
await actions.reindexDeprecationFlyout.clickReindexButton(); // details step
await actions.reindexDeprecationFlyout.clickReindexButton(); // warning step

expect(find('reindexChecklistTitle').text()).toEqual('Reindexing in progress… 95%');
expect(exists('cancelReindexingDocumentsButton')).toBe(false);
Expand Down Expand Up @@ -250,14 +222,11 @@ describe('Reindex deprecation flyout', () => {
},
]);

await act(async () => {
testBed = await setupElasticsearchPage(httpSetup);
});

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

await actions.table.clickDeprecationRowAt('reindex', 0);
await actions.reindexDeprecationFlyout.clickReindexButton(); // details step
await actions.reindexDeprecationFlyout.clickReindexButton(); // warning step

expect(find('lowDiskSpaceCallout').text()).toContain('Nodes with low disk space');
expect(find('impactedNodeListItem').length).toEqual(1);
Expand Down
19 changes: 13 additions & 6 deletions x-pack/platform/plugins/private/upgrade_assistant/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ export interface ReindexStatusResponse {
reindexName: string;
// Array of aliases pointing to the index being reindexed
aliases: string[];
isReadonly: boolean;
isFrozen: boolean;
};
warnings?: ReindexWarning[];
warnings?: IndexWarning[];
reindexOp?: ReindexOperation;
hasRequiredPrivileges?: boolean;
}
Expand Down Expand Up @@ -136,18 +138,19 @@ export interface ReindexOperation {
export type ReindexSavedObject = SavedObject<ReindexOperation>;

// 8.0 -> 9.0 warnings
export type ReindexWarningTypes = 'indexSetting' | 'replaceIndexWithAlias';
export type IndexWarningType = 'indexSetting' | 'replaceIndexWithAlias' | 'makeIndexReadonly';

export interface ReindexWarning {
warningType: ReindexWarningTypes;
export interface IndexWarning {
warningType: IndexWarningType;
flow: 'reindex' | 'readonly' | 'all';
/**
* Optional metadata for deprecations
*
* @remark
* For "indexSetting" we want to surface the deprecated settings.
*/
meta?: {
[key: string]: string | string[];
[key: string]: string | string[] | boolean;
};
}

Expand Down Expand Up @@ -202,6 +205,10 @@ export interface ReindexAction {
blockerForReindexing?: 'index-closed'; // 'index-closed' can be handled automatically, but requires more resources, user should be warned
}

export interface UnfreezeAction {
type: 'unfreeze';
}

export interface MlAction {
type: 'mlSnapshot';
snapshotId: string;
Expand Down Expand Up @@ -237,11 +244,11 @@ export interface EnrichedDeprecationInfo
| 'ilm_policies'
| 'templates';
isCritical: boolean;
frozen?: boolean;
status?: estypes.HealthReportIndicatorHealthStatus;
index?: string;
correctiveAction?:
| ReindexAction
| UnfreezeAction
| MlAction
| IndexSettingAction
| ClusterSettingAction
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export type UpdateIndexOperation = 'blockWrite' | 'unfreeze';
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { i18n } from '@kbn/i18n';
import moment from 'moment';
import { DataStreamMigrationStatus } from '../../../../../../../../../common/types';
import type { MigrationState } from '../../../use_migration_state';
import { StepProgress, StepProgressStep } from '../../../../reindex/flyout/step_progress';
import { getDataStreamReindexProgress } from '../../../../../../../lib/utils';
import { MigrateDocumentsStepTitle } from './progress_title';
import { CancelLoadingState } from '../../../../../../types';
import { StepProgress, type StepProgressStep } from '../../../../../common/step_progress';

interface Props {
migrationState: MigrationState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const ReindexWarningCallout: React.FunctionComponent<{}> = () => {
<EuiCallOut
title={
<FormattedMessage
id="xpack.upgradeAssistant.dataStream.migration.flyout.warningsStep.destructiveCallout.calloutTitle"
id="xpack.upgradeAssistant.dataStream.migration.flyout.warningsStep.reindex.calloutTitle"
defaultMessage="This operation requires destructive changes that cannot be reversed"
/>
}
Expand All @@ -23,7 +23,7 @@ export const ReindexWarningCallout: React.FunctionComponent<{}> = () => {
>
<p>
<FormattedMessage
id="xpack.upgradeAssistant.dataStream.migration.flyout.warningsStep.destructiveCallout.calloutDetail"
id="xpack.upgradeAssistant.dataStream.migration.flyout.warningsStep.reindex.calloutDetail"
defaultMessage="Ensure data has been backed up before continuing. To proceed with reindexing this data, confirm below."
/>
</p>
Expand All @@ -36,7 +36,7 @@ export const ReadonlyWarningCallout: React.FunctionComponent<{}> = () => {
<EuiCallOut
title={
<FormattedMessage
id="xpack.upgradeAssistant.dataStream.migration.flyout.warningsStep.destructiveCallout.calloutTitle"
id="xpack.upgradeAssistant.dataStream.migration.flyout.warningsStep.readonly.calloutTitle"
defaultMessage="Marking this data read only could affect some of the existing setups"
/>
}
Expand All @@ -45,7 +45,7 @@ export const ReadonlyWarningCallout: React.FunctionComponent<{}> = () => {
>
<p>
<FormattedMessage
id="xpack.upgradeAssistant.dataStream.migration.flyout.warningsStep.destructiveCallout.calloutDetail"
id="xpack.upgradeAssistant.dataStream.migration.flyout.warningsStep.readonly.calloutDetail"
defaultMessage="Make sure you have backed up your data, etc. You can always re-index this data later to make it editable."
/>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
export { MlSnapshotsTableRow } from './ml_snapshots';
export { IndexSettingsTableRow } from './index_settings';
export { DefaultTableRow } from './default';
export { ReindexTableRow } from './reindex';
export { IndexTableRow } from './indices';
export { DataStreamTableRow } from './data_streams';
export { ClusterSettingsTableRow } from './cluster_settings';
export { HealthIndicatorTableRow } from './health_indicator';
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

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

import { ApiService } from '../../../../lib/api';
import { useReindex, ReindexState } from './use_reindex';
import { UpdateIndexState, useUpdateIndex } from './use_update_index';
import { EnrichedDeprecationInfo } from '../../../../../../common/types';

export interface IndexStateContext {
deprecation: EnrichedDeprecationInfo;
reindexState: ReindexState;
startReindex: () => Promise<void>;
cancelReindex: () => Promise<void>;
updateIndexState: UpdateIndexState;
updateIndex: () => Promise<void>;
}

const IndexContext = createContext<IndexStateContext | undefined>(undefined);

export const useIndexContext = () => {
const context = useContext(IndexContext);
if (context === undefined) {
throw new Error('useIndexContext must be used within a <IndexStatusProvider />');
}
return context;
};

interface Props {
api: ApiService;
children: React.ReactNode;
deprecation: EnrichedDeprecationInfo;
}

export const IndexStatusProvider: React.FunctionComponent<Props> = ({
api,
deprecation,
children,
}) => {
const indexName = deprecation.index!;
const { reindexState, startReindex, cancelReindex } = useReindex({
indexName,
api,
});

const { updateIndexState, updateIndex } = useUpdateIndex({
indexName,
api,
correctiveAction: deprecation.correctiveAction,
});

return (
<IndexContext.Provider
value={{
deprecation,
reindexState,
startReindex,
cancelReindex,
updateIndexState,
updateIndex,
}}
>
{children}
</IndexContext.Provider>
);
};
Loading

0 comments on commit 8b1f5f1

Please sign in to comment.