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 all 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.
Jump to
Jump to file
Failed to load files.
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 Expand Up @@ -60,3 +95,58 @@ export const DELETE_PHASE_POLICY: PolicyFromES = {
},
name: POLICY_NAME,
};

export const POLICY_WITH_NODE_ATTR_AND_OFF_ALLOCATION: PolicyFromES = {
version: 1,
modified_date: Date.now().toString(),
policy: {
phases: {
hot: {
min_age: '0ms',
actions: {
rollover: {
max_size: '50gb',
},
},
},
warm: {
actions: {
allocate: {
require: {},
include: { test: '123' },
exclude: {},
},
},
},
cold: {
actions: {
migrate: { enabled: false },
},
},
},
name: POLICY_NAME,
},
name: POLICY_NAME,
};

export const POLICY_WITH_NODE_ROLE_ALLOCATION: PolicyFromES = {
version: 1,
modified_date: Date.now().toString(),
policy: {
phases: {
hot: {
min_age: '0ms',
actions: {
rollover: {
max_size: '50gb',
},
},
},
warm: {
actions: {},
},
},
name: POLICY_NAME,
},
name: POLICY_NAME,
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import { act } from 'react-dom/test-utils';

import { registerTestBed, TestBedConfig } from '../../../../../test_utils';

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

import { Phases as PolicyPhases } from '../../../common/types';

type Phases = keyof PolicyPhases;

import { POLICY_NAME } from './constants';
import { TestSubjects } from '../helpers';

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

jest.mock('@elastic/eui', () => {
const original = jest.requireActual('@elastic/eui');

Expand Down Expand Up @@ -52,7 +57,23 @@ export type EditPolicyTestBed = SetupReturn extends Promise<infer U> ? U : Setup
export const setup = async () => {
const testBed = await initTestBed();

const { find, component } = testBed;
const { find, component, form } = testBed;

const createFormToggleAction = (dataTestSubject: string) => async (checked: boolean) => {
await act(async () => {
form.toggleEuiSwitch(dataTestSubject, checked);
});
component.update();
};

function createFormSetValueAction<V extends string = string>(dataTestSubject: string) {
return async (value: V) => {
await act(async () => {
form.setInputValue(dataTestSubject, value);
});
component.update();
};
}

const setWaitForSnapshotPolicy = async (snapshotPolicyName: string) => {
act(() => {
Expand All @@ -68,12 +89,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 = createFormToggleAction('rolloverSwitch');

const setMaxSize = async (value: string, units?: string) => {
await act(async () => {
Expand All @@ -87,12 +103,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 +115,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: Phases) => createFormToggleAction(`${phase}-forceMergeSwitch`);

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

const setBestCompression = (phase: Phases) => createFormToggleAction(`${phase}-bestCompression`);

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

const enable = (phase: Phases) => createFormToggleAction(`enablePhaseSwitch-${phase}`);

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

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

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

const setDataAllocation = (phase: Phases) => 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 createFormToggleAction('warm-setReplicasSwitch')(true);
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 createFormToggleAction('shrinkSwitch')(true);
await createFormSetValueAction('warm-selectedPrimaryShardCount')(value);
};

return {
Expand All @@ -147,6 +182,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'),
},
},
};
};