Skip to content

Commit

Permalink
[ILM] Rollover field redesign (#85579)
Browse files Browse the repository at this point in the history
* implement form-level support for using default rollover action

* slight update to copy

* added use default rollover switch and tooltips for detailed copy

* fix legacy integration tests and do not unmount rollover field!!

* remove unused import

* fix client integration tests

* updated form to use new isUsingRollover check

* fix serialization of rollover

* Update x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/hot_phase/hot_phase.tsx

Co-authored-by: Adam Locke <adam.locke@elastic.co>

* Update x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/hot_phase/hot_phase.tsx

Co-authored-by: Adam Locke <adam.locke@elastic.co>

* Update x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/hot_phase/hot_phase.tsx

Co-authored-by: Adam Locke <adam.locke@elastic.co>

Co-authored-by: Yulia Čech <6585477+yuliacech@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Adam Locke <adam.locke@elastic.co>
  • Loading branch information
4 people committed Dec 14, 2020
1 parent 1f21fe7 commit 286f464
Show file tree
Hide file tree
Showing 19 changed files with 300 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export const setup = async (arg?: { appServicesContext: Partial<AppServicesConte
component.update();
};

const toggleDefaultRollover = createFormToggleAction('useDefaultRolloverSwitch');

const toggleRollover = createFormToggleAction('rolloverSwitch');

const setMaxSize = async (value: string, units?: string) => {
Expand Down Expand Up @@ -239,6 +241,7 @@ export const setup = async (arg?: { appServicesContext: Partial<AppServicesConte
setMaxDocs,
setMaxAge,
toggleRollover,
toggleDefaultRollover,
...createForceMergeActions('hot'),
setIndexPriority: setIndexPriority('hot'),
setShrink: setShrink('hot'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ describe('<EditPolicy />', () => {
test('setting all values', async () => {
const { actions } = testBed;

await actions.hot.toggleDefaultRollover(false);
await actions.hot.setMaxSize('123', 'mb');
await actions.hot.setMaxDocs('123');
await actions.hot.setMaxAge('123', 'h');
Expand Down Expand Up @@ -177,7 +178,8 @@ describe('<EditPolicy />', () => {

test('disabling rollover', async () => {
const { actions } = testBed;
await actions.hot.toggleRollover(true);
await actions.hot.toggleDefaultRollover(false);
await actions.hot.toggleRollover(false);
await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
const policy = JSON.parse(JSON.parse(latestRequest.requestBody).body);
Expand Down Expand Up @@ -212,6 +214,17 @@ describe('<EditPolicy />', () => {
expect(actions.cold.searchableSnapshotsExists()).toBeTruthy();
expect(actions.cold.freezeExists()).toBeFalsy();
});

test('disabling rollover toggle, but enabling default rollover', async () => {
const { actions } = testBed;
await actions.hot.toggleDefaultRollover(false);
await actions.hot.toggleRollover(false);
await actions.hot.toggleDefaultRollover(true);

expect(actions.hot.forceMergeFieldExists()).toBeTruthy();
expect(actions.hot.shrinkExists()).toBeTruthy();
expect(actions.hot.searchableSnapshotsExists()).toBeTruthy();
});
});
});

Expand Down Expand Up @@ -766,7 +779,7 @@ describe('<EditPolicy />', () => {
await act(async () => {
testBed = await setup({
appServicesContext: {
license: licensingMock.createLicense({ license: { type: 'basic' } }),
license: licensingMock.createLicense({ license: { type: 'enterprise' } }),
},
});
});
Expand All @@ -776,11 +789,12 @@ describe('<EditPolicy />', () => {
});
test('hiding and disabling searchable snapshot field', async () => {
const { actions } = testBed;
await actions.hot.toggleDefaultRollover(false);
await actions.hot.toggleRollover(false);
await actions.cold.enable(true);

expect(actions.hot.searchableSnapshotsExists()).toBeFalsy();
expect(actions.cold.searchableSnapshotDisabledDueToLicense()).toBeTruthy();
expect(actions.cold.searchableSnapshotDisabledDueToRollover()).toBeTruthy();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ const expectedErrorMessages = (rendered: ReactWrapper, expectedMessages: string[
expect(foundErrorMessage).toBe(true);
});
};
const noDefaultRollover = async (rendered: ReactWrapper) => {
await act(async () => {
findTestSubject(rendered, 'useDefaultRolloverSwitch').simulate('click');
});
rendered.update();
};
const noRollover = async (rendered: ReactWrapper) => {
await noDefaultRollover(rendered);
await act(async () => {
findTestSubject(rendered, 'rolloverSwitch').simulate('click');
});
Expand Down Expand Up @@ -326,6 +333,7 @@ describe('edit policy', () => {
describe('hot phase', () => {
test('should show errors when trying to save with no max size, no max age and no max docs', async () => {
const rendered = mountWithIntl(component);
await noDefaultRollover(rendered);
expect(findTestSubject(rendered, 'rolloverSettingsRequired').exists()).toBeFalsy();
await setPolicyName(rendered, 'mypolicy');
const maxSizeInput = findTestSubject(rendered, 'hot-selectedMaxSizeStored');
Expand All @@ -349,6 +357,7 @@ describe('edit policy', () => {
test('should show number above 0 required error when trying to save with -1 for max size', async () => {
const rendered = mountWithIntl(component);
await setPolicyName(rendered, 'mypolicy');
await noDefaultRollover(rendered);
const maxSizeInput = findTestSubject(rendered, 'hot-selectedMaxSizeStored');
await act(async () => {
maxSizeInput.simulate('change', { target: { value: '-1' } });
Expand All @@ -360,6 +369,7 @@ describe('edit policy', () => {
test('should show number above 0 required error when trying to save with 0 for max size', async () => {
const rendered = mountWithIntl(component);
await setPolicyName(rendered, 'mypolicy');
await noDefaultRollover(rendered);
const maxSizeInput = findTestSubject(rendered, 'hot-selectedMaxSizeStored');
await act(async () => {
maxSizeInput.simulate('change', { target: { value: '-1' } });
Expand All @@ -370,6 +380,7 @@ describe('edit policy', () => {
test('should show number above 0 required error when trying to save with -1 for max age', async () => {
const rendered = mountWithIntl(component);
await setPolicyName(rendered, 'mypolicy');
await noDefaultRollover(rendered);
const maxAgeInput = findTestSubject(rendered, 'hot-selectedMaxAge');
await act(async () => {
maxAgeInput.simulate('change', { target: { value: '-1' } });
Expand All @@ -380,6 +391,7 @@ describe('edit policy', () => {
test('should show number above 0 required error when trying to save with 0 for max age', async () => {
const rendered = mountWithIntl(component);
await setPolicyName(rendered, 'mypolicy');
await noDefaultRollover(rendered);
const maxAgeInput = findTestSubject(rendered, 'hot-selectedMaxAge');
await act(async () => {
maxAgeInput.simulate('change', { target: { value: '0' } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ export interface SearchableSnapshotAction {
force_merge_index?: boolean;
}

export interface RolloverAction {
max_size?: string;
max_age?: string;
max_docs?: number;
}

export interface SerializedHotPhase extends SerializedPhase {
actions: {
rollover?: {
max_size?: string;
max_age?: string;
max_docs?: number;
};
rollover?: RolloverAction;
forcemerge?: ForcemergeAction;
readonly?: {};
shrink?: ShrinkAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SerializedPhase, DeletePhase, SerializedPolicy } from '../../../common/types';
import {
SerializedPhase,
DeletePhase,
SerializedPolicy,
RolloverAction,
} from '../../../common/types';

export const defaultSetPriority: string = '100';

export const defaultPhaseIndexPriority: string = '50';

export const defaultRolloverAction: RolloverAction = {
max_age: '30d',
max_size: '50gb',
};

export const defaultPolicy: SerializedPolicy = {
name: '',
phases: {
hot: {
actions: {
rollover: {
max_age: '30d',
max_size: '50gb',
},
rollover: defaultRolloverAction,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
*/

export * from './data_tiers';

export * from './rollover';
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 { SerializedPolicy } from '../../../common/types';
import { defaultRolloverAction } from '../constants';

export const isUsingDefaultRollover = (policy: SerializedPolicy): boolean => {
const rollover = policy?.phases?.hot?.actions?.rollover;
return Boolean(
rollover &&
rollover.max_age === defaultRolloverAction.max_age &&
rollover.max_docs === defaultRolloverAction.max_docs &&
rollover.max_size === defaultRolloverAction.max_size
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export const DescribedFormRow: FunctionComponent<Props> = ({
const [uncontrolledIsContentVisible, setUncontrolledIsContentVisible] = useState<boolean>(
() => switchProps?.initialValue ?? false
);
const isContentVisible = Boolean(switchProps?.checked ?? uncontrolledIsContentVisible);
const isContentVisible = Boolean(
switchProps === undefined || (switchProps?.checked ?? uncontrolledIsContentVisible)
);

const renderToggle = () => {
if (!switchProps) {
Expand Down
Loading

0 comments on commit 286f464

Please sign in to comment.