[Index Management] Remove freeze index action and api (#116110)

* Remove freeze index action and api

* Remove unused translations

* Add test for unfreeze action

* Fix tests

* Fix tests
This commit is contained in:
Ignacio Rivas 2021-10-26 16:02:17 +01:00 committed by GitHub
parent d91bd98e97
commit 3920918d3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 33 additions and 218 deletions

View file

@ -59,4 +59,5 @@ export type TestSubjects =
| 'templatesTab'
| 'templateTable'
| 'title'
| 'unfreezeIndexMenuButton'
| 'viewButton';

View file

@ -159,9 +159,15 @@ describe('<IndexManagementHome />', () => {
describe('index actions', () => {
const indexName = 'testIndex';
const indexMock = createNonDataStreamIndex(indexName);
beforeEach(async () => {
httpRequestsMockHelpers.setLoadIndicesResponse([createNonDataStreamIndex(indexName)]);
httpRequestsMockHelpers.setLoadIndicesResponse([
{
...indexMock,
isFrozen: true,
},
]);
httpRequestsMockHelpers.setReloadIndicesResponse({ indexNames: [indexName] });
testBed = await setup();
@ -183,5 +189,27 @@ describe('<IndexManagementHome />', () => {
// a reload server call also.
expect(server.requests[requestsCount - 1].url).toBe(`${API_BASE_PATH}/indices/reload`);
});
test('should be able to unfreeze a frozen index', async () => {
const { actions, exists } = testBed;
httpRequestsMockHelpers.setReloadIndicesResponse([{ ...indexMock, isFrozen: false }]);
// Open context menu
await actions.clickManageContextMenuButton();
// Check that the unfreeze action exists for the current index and unfreeze it
expect(exists('unfreezeIndexMenuButton')).toBe(true);
await actions.clickContextMenuOption('unfreezeIndexMenuButton');
const requestsCount = server.requests.length;
expect(server.requests[requestsCount - 2].url).toBe(`${API_BASE_PATH}/indices/unfreeze`);
// After the index is unfrozen, we imediately do a reload. So we need to expect to see
// a reload server call also.
expect(server.requests[requestsCount - 1].url).toBe(`${API_BASE_PATH}/indices/reload`);
// Open context menu once again, since clicking an action will close it.
await actions.clickManageContextMenuButton();
// The unfreeze action should not be present anymore
expect(exists('unfreezeIndexMenuButton')).toBe(false);
});
});
});

View file

@ -108,7 +108,6 @@ Array [
"Refresh indices",
"Clear indices cache",
"Flush indices",
"Freeze indices",
"Delete indices",
]
`;
@ -134,7 +133,6 @@ Array [
"Refresh index",
"Clear index cache",
"Flush index",
"Freeze index",
"Delete index",
]
`;

View file

@ -24,8 +24,6 @@ export {
UIM_INDEX_FLUSH_MANY,
UIM_INDEX_FORCE_MERGE,
UIM_INDEX_FORCE_MERGE_MANY,
UIM_INDEX_FREEZE,
UIM_INDEX_FREEZE_MANY,
UIM_INDEX_OPEN,
UIM_INDEX_OPEN_MANY,
UIM_INDEX_REFRESH,

View file

@ -19,8 +19,6 @@ export const UIM_INDEX_FLUSH = 'index_flush';
export const UIM_INDEX_FLUSH_MANY = 'index_flush_many';
export const UIM_INDEX_FORCE_MERGE = 'index_force_merge';
export const UIM_INDEX_FORCE_MERGE_MANY = 'index_force_merge_many';
export const UIM_INDEX_FREEZE = 'index_freeze';
export const UIM_INDEX_FREEZE_MANY = 'index_freeze_many';
export const UIM_INDEX_OPEN = 'index_open';
export const UIM_INDEX_OPEN_MANY = 'index_open_many';
export const UIM_INDEX_REFRESH = 'index_refresh';

View file

@ -20,7 +20,6 @@ import {
openDetailPanel,
performExtensionAction,
reloadIndices,
freezeIndices,
unfreezeIndices,
} from '../../../../store/actions';
@ -68,9 +67,6 @@ const mapDispatchToProps = (dispatch, { indexNames }) => {
refreshIndices: () => {
dispatch(refreshIndices({ indexNames }));
},
freezeIndices: () => {
dispatch(freezeIndices({ indexNames }));
},
unfreezeIndices: () => {
dispatch(unfreezeIndices({ indexNames }));
},

View file

@ -70,7 +70,6 @@ export class IndexActionsContextMenu extends Component {
return indexStatusByName[indexName] === INDEX_OPEN;
});
const allFrozen = every(indices, (index) => index.isFrozen);
const allUnfrozen = every(indices, (index) => !index.isFrozen);
const selectedIndexCount = indexNames.length;
const items = [];
if (!detailPanel && selectedIndexCount === 1) {
@ -178,6 +177,7 @@ export class IndexActionsContextMenu extends Component {
});
if (allFrozen) {
items.push({
'data-test-subj': 'unfreezeIndexMenuButton',
name: i18n.translate('xpack.idxMgmt.indexActionsMenu.unfreezeIndexLabel', {
defaultMessage: 'Unfreeze {selectedIndexCount, plural, one {index} other {indices} }',
values: { selectedIndexCount },
@ -186,17 +186,6 @@ export class IndexActionsContextMenu extends Component {
this.closePopoverAndExecute(unfreezeIndices);
},
});
} else if (allUnfrozen) {
items.push({
name: i18n.translate('xpack.idxMgmt.indexActionsMenu.freezeIndexLabel', {
defaultMessage: 'Freeze {selectedIndexCount, plural, one {index} other {indices} }',
values: { selectedIndexCount },
}),
onClick: () => {
this.closePopover();
this.setState({ renderConfirmModal: this.renderConfirmFreezeModal });
},
});
}
} else {
items.push({
@ -619,76 +608,6 @@ export class IndexActionsContextMenu extends Component {
);
};
renderConfirmFreezeModal = () => {
const { freezeIndices, indexNames } = this.props;
return (
<EuiConfirmModal
title={i18n.translate(
'xpack.idxMgmt.indexActionsMenu.freezeEntity.confirmModal.modalTitle',
{
defaultMessage: 'Confirm freeze {count, plural, one {index} other {indices}}',
values: {
count: indexNames.length,
},
}
)}
onCancel={this.closeConfirmModal}
onConfirm={() => this.closePopoverAndExecute(freezeIndices)}
cancelButtonText={i18n.translate(
'xpack.idxMgmt.indexActionsMenu.freezeEntity.confirmModal.cancelButtonText',
{
defaultMessage: 'Cancel',
}
)}
confirmButtonText={i18n.translate(
'xpack.idxMgmt.indexActionsMenu.freezeEntity.confirmModal.confirmButtonText',
{
defaultMessage: 'Freeze {count, plural, one {index} other {indices}}',
values: {
count: indexNames.length,
},
}
)}
>
<p>
<FormattedMessage
id="xpack.idxMgmt.indexActionsMenu.freezeEntity.freezeDescription"
defaultMessage="You are about to freeze {count, plural, one {this index} other {these indices}}:"
values={{ count: indexNames.length }}
/>
</p>
<ul>
{indexNames.map((indexName) => (
<li key={indexName}>{indexName}</li>
))}
</ul>
<EuiCallOut
title={i18n.translate(
'xpack.idxMgmt.indexActionsMenu.freezeEntity.proceedWithCautionCallOutTitle',
{
defaultMessage: 'Proceed with caution',
}
)}
color="warning"
iconType="help"
>
<p>
<FormattedMessage
id="xpack.idxMgmt.indexActionsMenu.freezeEntity.freezeEntityWarningDescription"
defaultMessage="
A frozen index has little overhead on the cluster and is blocked for write operations.
You can search a frozen index, but expect queries to be slower.
"
/>
</p>
</EuiCallOut>
</EuiConfirmModal>
);
};
render() {
return (
<AppContextConsumer>

View file

@ -19,8 +19,6 @@ import {
UIM_INDEX_FLUSH_MANY,
UIM_INDEX_FORCE_MERGE,
UIM_INDEX_FORCE_MERGE_MANY,
UIM_INDEX_FREEZE,
UIM_INDEX_FREEZE_MANY,
UIM_INDEX_OPEN,
UIM_INDEX_OPEN_MANY,
UIM_INDEX_REFRESH,
@ -177,16 +175,6 @@ export async function clearCacheIndices(indices: string[]) {
uiMetricService.trackMetric(METRIC_TYPE.COUNT, eventName);
return response;
}
export async function freezeIndices(indices: string[]) {
const body = JSON.stringify({
indices,
});
const response = await httpService.httpClient.post(`${API_BASE_PATH}/indices/freeze`, { body });
// Only track successful requests.
const eventName = indices.length > 1 ? UIM_INDEX_FREEZE_MANY : UIM_INDEX_FREEZE;
uiMetricService.trackMetric(METRIC_TYPE.COUNT, eventName);
return response;
}
export async function unfreezeIndices(indices: string[]) {
const body = JSON.stringify({
indices,

View file

@ -15,7 +15,6 @@ export {
flushIndices,
forcemergeIndices,
clearCacheIndices,
freezeIndices,
unfreezeIndices,
loadIndexSettings,
updateIndexSettings,

View file

@ -1,33 +0,0 @@
/*
* 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 { createAction } from 'redux-actions';
import { i18n } from '@kbn/i18n';
import { freezeIndices as request } from '../../services';
import { clearRowStatus, reloadIndices } from '../actions';
import { notificationService } from '../../services/notification';
export const freezeIndicesStart = createAction('INDEX_MANAGEMENT_FREEZE_INDICES_START');
export const freezeIndices =
({ indexNames }) =>
async (dispatch) => {
dispatch(freezeIndicesStart({ indexNames }));
try {
await request(indexNames);
} catch (error) {
notificationService.showDangerToast(error.message);
return dispatch(clearRowStatus({ indexNames }));
}
dispatch(reloadIndices(indexNames));
notificationService.showSuccessToast(
i18n.translate('xpack.idxMgmt.freezeIndicesAction.successfullyFrozeIndicesMessage', {
defaultMessage: 'Successfully froze: [{indexNames}]',
values: { indexNames: indexNames.join(', ') },
})
);
};

View file

@ -15,7 +15,6 @@ export * from './load_indices';
export * from './load_index_data';
export * from './open_indices';
export * from './refresh_indices';
export * from './freeze_indices';
export * from './unfreeze_indices';
export * from './reload_indices';
export * from './table_state';

View file

@ -1,34 +0,0 @@
/*
* 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 { schema } from '@kbn/config-schema';
import { RouteDependencies } from '../../../types';
import { addBasePath } from '../index';
const bodySchema = schema.object({
indices: schema.arrayOf(schema.string()),
});
export function registerFreezeRoute({ router, lib: { handleEsError } }: RouteDependencies) {
router.post(
{ path: addBasePath('/indices/freeze'), validate: { body: bodySchema } },
async (context, request, response) => {
const { client } = context.core.elasticsearch;
const { indices = [] } = request.body as typeof bodySchema.type;
try {
await client.asCurrentUser.indices.freeze({
index: indices.join(','),
});
return response.ok();
} catch (error) {
return handleEsError({ error, response });
}
}
);
}

View file

@ -16,7 +16,6 @@ import { registerOpenRoute } from './register_open_route';
import { registerRefreshRoute } from './register_refresh_route';
import { registerReloadRoute } from './register_reload_route';
import { registerDeleteRoute } from './register_delete_route';
import { registerFreezeRoute } from './register_freeze_route';
import { registerUnfreezeRoute } from './register_unfreeze_route';
export function registerIndicesRoutes(dependencies: RouteDependencies) {
@ -29,6 +28,5 @@ export function registerIndicesRoutes(dependencies: RouteDependencies) {
registerRefreshRoute(dependencies);
registerReloadRoute(dependencies);
registerDeleteRoute(dependencies);
registerFreezeRoute(dependencies);
registerUnfreezeRoute(dependencies);
}

View file

@ -11640,7 +11640,6 @@
"xpack.idxMgmt.formWizard.stepSettings.settingsDescription": "インデックスの動作を定義します。",
"xpack.idxMgmt.formWizard.stepSettings.settingsEditorHelpText": "JSONフォーマットを使用{code}",
"xpack.idxMgmt.formWizard.stepSettings.stepTitle": "インデックス設定(任意)",
"xpack.idxMgmt.freezeIndicesAction.successfullyFrozeIndicesMessage": "[{indexNames}] が凍結されました",
"xpack.idxMgmt.frozenBadgeLabel": "凍結",
"xpack.idxMgmt.home.appTitle": "インデックス管理",
"xpack.idxMgmt.home.componentTemplates.checkingPrivilegesDescription": "権限を確認中…",
@ -11690,10 +11689,6 @@
"xpack.idxMgmt.indexActionsMenu.forceMerge.forceMergeWarningDescription": " まだ書き込み中のインデックスや、将来もう一度書き込む予定がある強制・マージしないでください。自動バックグラウンドマージプロセスを活用して、スムーズなインデックス実行に必要なマージを実行できます。強制・マージインデックスに書き込む場合、パフォーマンスが大幅に低下する可能性があります。",
"xpack.idxMgmt.indexActionsMenu.forceMerge.maximumNumberOfSegmentsFormRowLabel": "シャードごとの最大セグメント数",
"xpack.idxMgmt.indexActionsMenu.forceMerge.proceedWithCautionCallOutTitle": "十分ご注意ください!",
"xpack.idxMgmt.indexActionsMenu.freezeEntity.confirmModal.cancelButtonText": "キャンセル",
"xpack.idxMgmt.indexActionsMenu.freezeEntity.freezeDescription": "{count, plural, one {このインデックス} other {これらのインデックス} }を凍結しようとしています。",
"xpack.idxMgmt.indexActionsMenu.freezeEntity.freezeEntityWarningDescription": " 凍結されたインデックスはクラスターにほとんどオーバーヘッドがなく、書き込みオペレーションがブロックされます。凍結されたインデックスは検索できますが、クエリが遅くなります。",
"xpack.idxMgmt.indexActionsMenu.freezeEntity.proceedWithCautionCallOutTitle": "十分ご注意ください",
"xpack.idxMgmt.indexActionsMenu.segmentsNumberErrorMessage": "セグメント数は 0 より大きい値である必要があります。",
"xpack.idxMgmt.indexStatusLabels.clearingCacheStatusLabel": "キャッシュを消去中...",
"xpack.idxMgmt.indexStatusLabels.closedStatusLabel": "クローズ済み",

View file

@ -11772,7 +11772,6 @@
"xpack.idxMgmt.formWizard.stepSettings.settingsDescription": "定义索引的行为。",
"xpack.idxMgmt.formWizard.stepSettings.settingsEditorHelpText": "使用 JSON 格式:{code}",
"xpack.idxMgmt.formWizard.stepSettings.stepTitle": "索引设置(可选)",
"xpack.idxMgmt.freezeIndicesAction.successfullyFrozeIndicesMessage": "成功冻结:[{indexNames}]",
"xpack.idxMgmt.frozenBadgeLabel": "已冻结",
"xpack.idxMgmt.home.appTitle": "索引管理",
"xpack.idxMgmt.home.componentTemplates.checkingPrivilegesDescription": "正在检查权限……",
@ -11835,13 +11834,6 @@
"xpack.idxMgmt.indexActionsMenu.forceMerge.maximumNumberOfSegmentsFormRowLabel": "每分片最大段数",
"xpack.idxMgmt.indexActionsMenu.forceMerge.proceedWithCautionCallOutTitle": "谨慎操作!",
"xpack.idxMgmt.indexActionsMenu.forceMergeIndexLabel": "强制合并{selectedIndexCount, plural, other {索引} }",
"xpack.idxMgmt.indexActionsMenu.freezeEntity.confirmModal.cancelButtonText": "取消",
"xpack.idxMgmt.indexActionsMenu.freezeEntity.confirmModal.confirmButtonText": "隐藏{count, plural, other {索引}}",
"xpack.idxMgmt.indexActionsMenu.freezeEntity.confirmModal.modalTitle": "确认冻结{count, plural, other {索引}}",
"xpack.idxMgmt.indexActionsMenu.freezeEntity.freezeDescription": "您将要冻结{count, plural, other {以下索引}}",
"xpack.idxMgmt.indexActionsMenu.freezeEntity.freezeEntityWarningDescription": " 冻结的索引在集群上有很少的开销,已被阻止进行写操作。您可以搜索冻结的索引,但查询应会较慢。",
"xpack.idxMgmt.indexActionsMenu.freezeEntity.proceedWithCautionCallOutTitle": "谨慎操作",
"xpack.idxMgmt.indexActionsMenu.freezeIndexLabel": "冻结{selectedIndexCount, plural, other {索引} }",
"xpack.idxMgmt.indexActionsMenu.manageButtonAriaLabel": "{selectedIndexCount, plural, other {索引} }选项",
"xpack.idxMgmt.indexActionsMenu.manageButtonLabel": "管理{selectedIndexCount, plural, one {索引} other { {selectedIndexCount} 个索引}}",
"xpack.idxMgmt.indexActionsMenu.openIndexLabel": "打开{selectedIndexCount, plural, other {索引} }",

View file

@ -29,8 +29,6 @@ export const registerHelpers = ({ supertest }) => {
const forceMerge = (index, args) => executeActionOnIndices(index, 'forcemerge', args);
const freeze = (index) => executeActionOnIndices(index, 'freeze');
const unfreeze = (index) => executeActionOnIndices(index, 'unfreeze');
const clearCache = (index) => executeActionOnIndices(index, 'clear_cache');
@ -47,7 +45,6 @@ export const registerHelpers = ({ supertest }) => {
flushIndex,
refreshIndex,
forceMerge,
freeze,
unfreeze,
list,
reload,

View file

@ -27,7 +27,6 @@ export default function ({ getService }) {
flushIndex,
refreshIndex,
forceMerge,
freeze,
unfreeze,
list,
reload,
@ -164,35 +163,12 @@ export default function ({ getService }) {
});
});
describe('freeze', () => {
it('should freeze an index', async () => {
const index = await createIndex();
// "sth" correspond to search throttling. Frozen indices are normal indices
// with search throttling turned on.
const {
body: [cat1],
} = await catIndex(index, 'sth');
expect(cat1.sth).to.be('false');
await freeze(index).expect(200);
const {
body: [cat2],
} = await catIndex(index, 'sth');
expect(cat2.sth).to.be('true');
});
});
describe('unfreeze', () => {
it('should unfreeze an index', async () => {
const index = await createIndex();
await freeze(index).expect(200);
const {
body: [cat1],
} = await catIndex(index, 'sth');
expect(cat1.sth).to.be('true');
// Even if the index is already unfrozen, calling the unfreeze api
// will have no effect on it and will return a 200.
await unfreeze(index).expect(200);
const {
body: [cat2],