Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ILM] Migrate Warm phase to Form Lib #81323

Merged
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d844b12
migrate all fields on warm phase except, data alloc, replicas and shrink
jloleysens Oct 20, 2020
e867ffe
introduce edit policy context to share original policy and migrate sh…
jloleysens Oct 20, 2020
d349eee
Refactored biggest field; data allocation
jloleysens Oct 20, 2020
779534e
remove unused import
jloleysens Oct 20, 2020
5bb0be9
complete migration of new serialization
jloleysens Oct 21, 2020
98bf14b
Remove last vestiges of legacy warm phase
jloleysens Oct 21, 2020
0121411
fix existing test coverage and remove use of "none" for node attribute
jloleysens Oct 21, 2020
d7896d7
added policy serialization tests
jloleysens Oct 21, 2020
805a55d
Merge branch 'master' of github.com:elastic/kibana into ilm/migrate-w…
jloleysens Oct 21, 2020
4f2a615
remove unused translations
jloleysens Oct 21, 2020
2ed016f
Fix use of useFormData after update
jloleysens Oct 21, 2020
5aed5cf
fix import path
jloleysens Oct 22, 2020
271351e
Merge branch 'master' into ilm/migrate-warm-phase-to-formlib
kibanamachine Oct 22, 2020
db3894d
Merge branch 'master' into ilm/migrate-warm-phase-to-formlib
kibanamachine Oct 26, 2020
7b2f0ba
Merge branch 'master' of github.com:elastic/kibana into ilm/migrate-w…
jloleysens Oct 26, 2020
1affb8e
simplify serialization snapshot tests
jloleysens Oct 26, 2020
97da20e
type phases: string -> phases: Phases
jloleysens Oct 26, 2020
2befd67
Addressed some PR review items
jloleysens Oct 26, 2020
96e45ae
updated data tier callout logic after new changes
jloleysens Oct 26, 2020
cb03877
getPolicy -> updatePolicy
jloleysens Oct 26, 2020
6109d3a
fix detection of migrate false and refactor serialization to pure fun…
jloleysens Oct 26, 2020
750992e
fix type issue
jloleysens Oct 26, 2020
b85f492
fix for correctly detecting policy data tier type
jloleysens Oct 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,52 @@ export const DEFAULT_POLICY: PolicyFromES = {
version: 1,
modified_date: Date.now().toString(),
policy: {
name: '',
name: 'my_policy',
phases: {
hot: {
min_age: '0ms',
actions: {
rollover: {
max_age: '30d',
max_size: '50gb',
},
},
},
},
},
name: 'my_policy',
};

export const POLICY_WITH_INCLUDE_EXCLUDE: PolicyFromES = {
version: 1,
modified_date: Date.now().toString(),
policy: {
name: 'my_policy',
phases: {
hot: {
min_age: '123ms',
actions: {
rollover: {},
rollover: {
max_age: '30d',
max_size: '50gb',
},
},
},
warm: {
actions: {
allocate: {
include: {
abc: '123',
},
exclude: {
def: '456',
},
},
},
},
},
},
name: '',
name: 'my_policy',
};

export const DELETE_PHASE_POLICY: PolicyFromES = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { POLICY_NAME } from './constants';
import { TestSubjects } from '../helpers';

import { EditPolicy } from '../../../public/application/sections/edit_policy';
import { DataTierAllocationType } from '../../../public/application/sections/edit_policy/types';

jest.mock('@elastic/eui', () => {
const original = jest.requireActual('@elastic/eui');
Expand Down Expand Up @@ -54,6 +55,22 @@ export const setup = async () => {

const { find, component } = testBed;

const createFormClickAction = (dataTestSubject: string) => async () => {
await act(async () => {
find(dataTestSubject).simulate('click');
});
component.update();
};

function createFormSetValueAction<V = string>(dataTestSubject: string) {
return async (value: V) => {
await act(async () => {
find(dataTestSubject).simulate('change', { target: { value } });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you could use the form helper from the testBed object

form.setInputValue(dataTestSubject, value);

});
component.update();
};
}

const setWaitForSnapshotPolicy = async (snapshotPolicyName: string) => {
act(() => {
find('snapshotPolicyCombobox').simulate('change', [{ label: snapshotPolicyName }]);
Expand All @@ -68,12 +85,7 @@ export const setup = async () => {
component.update();
};

const toggleRollover = async (checked: boolean) => {
await act(async () => {
find('rolloverSwitch').simulate('click', { target: { checked } });
});
component.update();
};
const toggleRollover = createFormClickAction('rolloverSwitch');

const setMaxSize = async (value: string, units?: string) => {
await act(async () => {
Expand All @@ -87,12 +99,7 @@ export const setup = async () => {
component.update();
};

const setMaxDocs = async (value: string) => {
await act(async () => {
find('hot-selectedMaxDocuments').simulate('change', { target: { value } });
});
component.update();
};
const setMaxDocs = createFormSetValueAction('hot-selectedMaxDocuments');

const setMaxAge = async (value: string, units?: string) => {
await act(async () => {
Expand All @@ -104,32 +111,56 @@ export const setup = async () => {
component.update();
};

const toggleForceMerge = (phase: string) => async (checked: boolean) => {
await act(async () => {
find(`${phase}-forceMergeSwitch`).simulate('click', { target: { checked } });
const toggleForceMerge = (phase: string) => createFormClickAction(`${phase}-forceMergeSwitch`);

const setForcemergeSegmentsCount = (phase: string) =>
createFormSetValueAction(`${phase}-selectedForceMergeSegments`);

const setBestCompression = (phase: string) => createFormClickAction(`${phase}-bestCompression`);

const setIndexPriority = (phase: string) =>
createFormSetValueAction(`${phase}-phaseIndexPriority`);

const enable = (phase: string) => createFormClickAction(`enablePhaseSwitch-${phase}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we type the phase here and below? 'hot' | 'warm' | 'cold' | 'delete'


const warmPhaseOnRollover = createFormClickAction(`warm-warmPhaseOnRollover`);

const setMinAgeValue = (phase: string) => createFormSetValueAction(`${phase}-selectedMinimumAge`);

const setMinAgeUnits = (phase: string) =>
createFormSetValueAction(`${phase}-selectedMinimumAgeUnits`);

const setDataAllocation = (phase: string) => async (value: DataTierAllocationType) => {
act(() => {
find(`${phase}-dataTierAllocationControls.dataTierSelect`).simulate('click');
});
component.update();
};

const setForcemergeSegmentsCount = (phase: string) => async (value: string) => {
await act(async () => {
find(`${phase}-selectedForceMergeSegments`).simulate('change', { target: { value } });
switch (value) {
case 'node_roles':
find(`${phase}-dataTierAllocationControls.defaultDataAllocationOption`).simulate('click');
break;
case 'node_attrs':
find(`${phase}-dataTierAllocationControls.customDataAllocationOption`).simulate('click');
break;
default:
find(`${phase}-dataTierAllocationControls.noneDataAllocationOption`).simulate('click');
}
});
component.update();
};

const setBestCompression = (phase: string) => async (checked: boolean) => {
await act(async () => {
find(`${phase}-bestCompression`).simulate('click', { target: { checked } });
});
component.update();
const setSelectedNodeAttribute = (phase: string) =>
createFormSetValueAction(`${phase}-selectedNodeAttrs`);

const setReplicas = async (value: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if we call twice this method in a test? It seems that the first time the switch would be "on" and the second time "off" and we would not be able to set thevalue. I think this is why we had the option to pass the checked value originally (to "toggleForceMerge" for e.g.).

I think that for toggles we could use the handler from testBed

form.toggleEuiSwitch('warm-setReplicasSwitch', true);

WDYT?

await createFormClickAction('warm-setReplicasSwitch')();
await createFormSetValueAction('warm-selectedReplicaCount')(value);
};

const setIndexPriority = (phase: string) => async (value: string) => {
await act(async () => {
find(`${phase}-phaseIndexPriority`).simulate('change', { target: { value } });
});
component.update();
const setShrink = async (value: string) => {
await createFormClickAction('shrinkSwitch')();
await createFormSetValueAction('warm-selectedPrimaryShardCount')(value);
};

return {
Expand All @@ -147,6 +178,20 @@ export const setup = async () => {
setBestCompression: setBestCompression('hot'),
setIndexPriority: setIndexPriority('hot'),
},
warm: {
enable: enable('warm'),
warmPhaseOnRollover,
setMinAgeValue: setMinAgeValue('warm'),
setMinAgeUnits: setMinAgeUnits('warm'),
setDataAllocation: setDataAllocation('warm'),
setSelectedNodeAttribute: setSelectedNodeAttribute('warm'),
setReplicas,
setShrink,
toggleForceMerge: toggleForceMerge('warm'),
setForcemergeSegments: setForcemergeSegmentsCount('warm'),
setBestCompression: setBestCompression('warm'),
setIndexPriority: setIndexPriority('warm'),
},
},
};
};
Loading