Skip to content

Commit 1712f0d

Browse files
[ILM] Migrate Warm phase to Form Lib (#81323)
* migrate all fields on warm phase except, data alloc, replicas and shrink * introduce edit policy context to share original policy and migrate shrink and replicas fields * Refactored biggest field; data allocation Copied the entire field for now duplicating all of the components * remove unused import * complete migration of new serialization * Remove last vestiges of legacy warm phase - also removed policy serialization tests for warm phase * fix existing test coverage and remove use of "none" for node attribute * added policy serialization tests * remove unused translations * Fix use of useFormData after update - also minor refactor to use useCallback in policy flyout now that getFormData changes when the form data changes. * fix import path * simplify serialization snapshot tests * type phases: string -> phases: Phases * Addressed some PR review items - refactor toggle click to take a boolean arg - refactor selection options in data tier component to use a func to get select options. * updated data tier callout logic after new changes * getPolicy -> updatePolicy Also rather deconstruct the validate fn from the form object * fix detection of migrate false and refactor serialization to pure function * fix type issue * fix for correctly detecting policy data tier type - with jest tests see origin here: #81642 Co-authored-by: Kibana Machine <[email protected]>
1 parent 90c78f8 commit 1712f0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2700
-1373
lines changed

x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/constants.ts

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,52 @@ export const DEFAULT_POLICY: PolicyFromES = {
1414
version: 1,
1515
modified_date: Date.now().toString(),
1616
policy: {
17-
name: '',
17+
name: 'my_policy',
18+
phases: {
19+
hot: {
20+
min_age: '0ms',
21+
actions: {
22+
rollover: {
23+
max_age: '30d',
24+
max_size: '50gb',
25+
},
26+
},
27+
},
28+
},
29+
},
30+
name: 'my_policy',
31+
};
32+
33+
export const POLICY_WITH_INCLUDE_EXCLUDE: PolicyFromES = {
34+
version: 1,
35+
modified_date: Date.now().toString(),
36+
policy: {
37+
name: 'my_policy',
1838
phases: {
1939
hot: {
2040
min_age: '123ms',
2141
actions: {
22-
rollover: {},
42+
rollover: {
43+
max_age: '30d',
44+
max_size: '50gb',
45+
},
46+
},
47+
},
48+
warm: {
49+
actions: {
50+
allocate: {
51+
include: {
52+
abc: '123',
53+
},
54+
exclude: {
55+
def: '456',
56+
},
57+
},
2358
},
2459
},
2560
},
2661
},
27-
name: '',
62+
name: 'my_policy',
2863
};
2964

3065
export const DELETE_PHASE_POLICY: PolicyFromES = {
@@ -60,3 +95,58 @@ export const DELETE_PHASE_POLICY: PolicyFromES = {
6095
},
6196
name: POLICY_NAME,
6297
};
98+
99+
export const POLICY_WITH_NODE_ATTR_AND_OFF_ALLOCATION: PolicyFromES = {
100+
version: 1,
101+
modified_date: Date.now().toString(),
102+
policy: {
103+
phases: {
104+
hot: {
105+
min_age: '0ms',
106+
actions: {
107+
rollover: {
108+
max_size: '50gb',
109+
},
110+
},
111+
},
112+
warm: {
113+
actions: {
114+
allocate: {
115+
require: {},
116+
include: { test: '123' },
117+
exclude: {},
118+
},
119+
},
120+
},
121+
cold: {
122+
actions: {
123+
migrate: { enabled: false },
124+
},
125+
},
126+
},
127+
name: POLICY_NAME,
128+
},
129+
name: POLICY_NAME,
130+
};
131+
132+
export const POLICY_WITH_NODE_ROLE_ALLOCATION: PolicyFromES = {
133+
version: 1,
134+
modified_date: Date.now().toString(),
135+
policy: {
136+
phases: {
137+
hot: {
138+
min_age: '0ms',
139+
actions: {
140+
rollover: {
141+
max_size: '50gb',
142+
},
143+
},
144+
},
145+
warm: {
146+
actions: {},
147+
},
148+
},
149+
name: POLICY_NAME,
150+
},
151+
name: POLICY_NAME,
152+
};

x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.helpers.tsx

Lines changed: 81 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ import { act } from 'react-dom/test-utils';
99

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

12+
import { EditPolicy } from '../../../public/application/sections/edit_policy';
13+
import { DataTierAllocationType } from '../../../public/application/sections/edit_policy/types';
14+
15+
import { Phases as PolicyPhases } from '../../../common/types';
16+
17+
type Phases = keyof PolicyPhases;
18+
1219
import { POLICY_NAME } from './constants';
1320
import { TestSubjects } from '../helpers';
1421

15-
import { EditPolicy } from '../../../public/application/sections/edit_policy';
16-
1722
jest.mock('@elastic/eui', () => {
1823
const original = jest.requireActual('@elastic/eui');
1924

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

55-
const { find, component } = testBed;
60+
const { find, component, form } = testBed;
61+
62+
const createFormToggleAction = (dataTestSubject: string) => async (checked: boolean) => {
63+
await act(async () => {
64+
form.toggleEuiSwitch(dataTestSubject, checked);
65+
});
66+
component.update();
67+
};
68+
69+
function createFormSetValueAction<V extends string = string>(dataTestSubject: string) {
70+
return async (value: V) => {
71+
await act(async () => {
72+
form.setInputValue(dataTestSubject, value);
73+
});
74+
component.update();
75+
};
76+
}
5677

5778
const setWaitForSnapshotPolicy = async (snapshotPolicyName: string) => {
5879
act(() => {
@@ -68,12 +89,7 @@ export const setup = async () => {
6889
component.update();
6990
};
7091

71-
const toggleRollover = async (checked: boolean) => {
72-
await act(async () => {
73-
find('rolloverSwitch').simulate('click', { target: { checked } });
74-
});
75-
component.update();
76-
};
92+
const toggleRollover = createFormToggleAction('rolloverSwitch');
7793

7894
const setMaxSize = async (value: string, units?: string) => {
7995
await act(async () => {
@@ -87,12 +103,7 @@ export const setup = async () => {
87103
component.update();
88104
};
89105

90-
const setMaxDocs = async (value: string) => {
91-
await act(async () => {
92-
find('hot-selectedMaxDocuments').simulate('change', { target: { value } });
93-
});
94-
component.update();
95-
};
106+
const setMaxDocs = createFormSetValueAction('hot-selectedMaxDocuments');
96107

97108
const setMaxAge = async (value: string, units?: string) => {
98109
await act(async () => {
@@ -104,32 +115,56 @@ export const setup = async () => {
104115
component.update();
105116
};
106117

107-
const toggleForceMerge = (phase: string) => async (checked: boolean) => {
108-
await act(async () => {
109-
find(`${phase}-forceMergeSwitch`).simulate('click', { target: { checked } });
118+
const toggleForceMerge = (phase: Phases) => createFormToggleAction(`${phase}-forceMergeSwitch`);
119+
120+
const setForcemergeSegmentsCount = (phase: Phases) =>
121+
createFormSetValueAction(`${phase}-selectedForceMergeSegments`);
122+
123+
const setBestCompression = (phase: Phases) => createFormToggleAction(`${phase}-bestCompression`);
124+
125+
const setIndexPriority = (phase: Phases) =>
126+
createFormSetValueAction(`${phase}-phaseIndexPriority`);
127+
128+
const enable = (phase: Phases) => createFormToggleAction(`enablePhaseSwitch-${phase}`);
129+
130+
const warmPhaseOnRollover = createFormToggleAction(`warm-warmPhaseOnRollover`);
131+
132+
const setMinAgeValue = (phase: Phases) => createFormSetValueAction(`${phase}-selectedMinimumAge`);
133+
134+
const setMinAgeUnits = (phase: Phases) =>
135+
createFormSetValueAction(`${phase}-selectedMinimumAgeUnits`);
136+
137+
const setDataAllocation = (phase: Phases) => async (value: DataTierAllocationType) => {
138+
act(() => {
139+
find(`${phase}-dataTierAllocationControls.dataTierSelect`).simulate('click');
110140
});
111141
component.update();
112-
};
113-
114-
const setForcemergeSegmentsCount = (phase: string) => async (value: string) => {
115142
await act(async () => {
116-
find(`${phase}-selectedForceMergeSegments`).simulate('change', { target: { value } });
143+
switch (value) {
144+
case 'node_roles':
145+
find(`${phase}-dataTierAllocationControls.defaultDataAllocationOption`).simulate('click');
146+
break;
147+
case 'node_attrs':
148+
find(`${phase}-dataTierAllocationControls.customDataAllocationOption`).simulate('click');
149+
break;
150+
default:
151+
find(`${phase}-dataTierAllocationControls.noneDataAllocationOption`).simulate('click');
152+
}
117153
});
118154
component.update();
119155
};
120156

121-
const setBestCompression = (phase: string) => async (checked: boolean) => {
122-
await act(async () => {
123-
find(`${phase}-bestCompression`).simulate('click', { target: { checked } });
124-
});
125-
component.update();
157+
const setSelectedNodeAttribute = (phase: string) =>
158+
createFormSetValueAction(`${phase}-selectedNodeAttrs`);
159+
160+
const setReplicas = async (value: string) => {
161+
await createFormToggleAction('warm-setReplicasSwitch')(true);
162+
await createFormSetValueAction('warm-selectedReplicaCount')(value);
126163
};
127164

128-
const setIndexPriority = (phase: string) => async (value: string) => {
129-
await act(async () => {
130-
find(`${phase}-phaseIndexPriority`).simulate('change', { target: { value } });
131-
});
132-
component.update();
165+
const setShrink = async (value: string) => {
166+
await createFormToggleAction('shrinkSwitch')(true);
167+
await createFormSetValueAction('warm-selectedPrimaryShardCount')(value);
133168
};
134169

135170
return {
@@ -147,6 +182,20 @@ export const setup = async () => {
147182
setBestCompression: setBestCompression('hot'),
148183
setIndexPriority: setIndexPriority('hot'),
149184
},
185+
warm: {
186+
enable: enable('warm'),
187+
warmPhaseOnRollover,
188+
setMinAgeValue: setMinAgeValue('warm'),
189+
setMinAgeUnits: setMinAgeUnits('warm'),
190+
setDataAllocation: setDataAllocation('warm'),
191+
setSelectedNodeAttribute: setSelectedNodeAttribute('warm'),
192+
setReplicas,
193+
setShrink,
194+
toggleForceMerge: toggleForceMerge('warm'),
195+
setForcemergeSegments: setForcemergeSegmentsCount('warm'),
196+
setBestCompression: setBestCompression('warm'),
197+
setIndexPriority: setIndexPriority('warm'),
198+
},
150199
},
151200
};
152201
};

0 commit comments

Comments
 (0)