Skip to content

Commit

Permalink
[ILM] Migrate Cold phase to Form Lib (elastic#81754)
Browse files Browse the repository at this point in the history
* use form lib fields and start updating deserializer

* delete legacy data tier allocation field

* finished deserialization

* delete legacy serialization, validation and deserialization

* fix type issue and remove propertyOf for now

* fix legacy tests and create another number validator

* added serialization test coverage

* fix elastic#81697

* clean up remaining legacy tests and slight update to existing test

* remove legacy unused components

* fix copy to be clearer for more scenarios

* remove remaining coldphase interface use and clean up unused i18n

* update default index priority for cold phase

* updated cold phase index priority to 0

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
jloleysens and kibanamachine committed Oct 28, 2020
1 parent 036622c commit 69234d4
Show file tree
Hide file tree
Showing 43 changed files with 614 additions and 1,823 deletions.
Expand Up @@ -30,6 +30,31 @@ export const DEFAULT_POLICY: PolicyFromES = {
name: 'my_policy',
};

export const POLICY_WITH_MIGRATE_OFF: PolicyFromES = {
version: 1,
modified_date: Date.now().toString(),
policy: {
name: 'my_policy',
phases: {
hot: {
min_age: '0ms',
actions: {
rollover: {
max_age: '30d',
max_size: '50gb',
},
},
},
warm: {
actions: {
migrate: { enabled: false },
},
},
},
},
name: 'my_policy',
};

export const POLICY_WITH_INCLUDE_EXCLUDE: PolicyFromES = {
version: 1,
modified_date: Date.now().toString(),
Expand Down
Expand Up @@ -154,19 +154,21 @@ export const setup = async () => {
component.update();
};

const setSelectedNodeAttribute = (phase: string) =>
const setSelectedNodeAttribute = (phase: Phases) =>
createFormSetValueAction(`${phase}-selectedNodeAttrs`);

const setReplicas = async (value: string) => {
await createFormToggleAction('warm-setReplicasSwitch')(true);
await createFormSetValueAction('warm-selectedReplicaCount')(value);
const setReplicas = (phase: Phases) => async (value: string) => {
await createFormToggleAction(`${phase}-setReplicasSwitch`)(true);
await createFormSetValueAction(`${phase}-selectedReplicaCount`)(value);
};

const setShrink = async (value: string) => {
await createFormToggleAction('shrinkSwitch')(true);
await createFormSetValueAction('warm-selectedPrimaryShardCount')(value);
};

const setFreeze = createFormToggleAction('freezeSwitch');

return {
...testBed,
actions: {
Expand All @@ -189,13 +191,23 @@ export const setup = async () => {
setMinAgeUnits: setMinAgeUnits('warm'),
setDataAllocation: setDataAllocation('warm'),
setSelectedNodeAttribute: setSelectedNodeAttribute('warm'),
setReplicas,
setReplicas: setReplicas('warm'),
setShrink,
toggleForceMerge: toggleForceMerge('warm'),
setForcemergeSegments: setForcemergeSegmentsCount('warm'),
setBestCompression: setBestCompression('warm'),
setIndexPriority: setIndexPriority('warm'),
},
cold: {
enable: enable('cold'),
setMinAgeValue: setMinAgeValue('cold'),
setMinAgeUnits: setMinAgeUnits('cold'),
setDataAllocation: setDataAllocation('cold'),
setSelectedNodeAttribute: setSelectedNodeAttribute('cold'),
setReplicas: setReplicas('cold'),
setFreeze,
setIndexPriority: setIndexPriority('cold'),
},
},
};
};
Expand Up @@ -15,6 +15,7 @@ import {
NEW_SNAPSHOT_POLICY_NAME,
SNAPSHOT_POLICY_NAME,
DEFAULT_POLICY,
POLICY_WITH_MIGRATE_OFF,
POLICY_WITH_INCLUDE_EXCLUDE,
POLICY_WITH_NODE_ATTR_AND_OFF_ALLOCATION,
POLICY_WITH_NODE_ROLE_ALLOCATION,
Expand Down Expand Up @@ -199,26 +200,6 @@ describe('<EditPolicy />', () => {
`);
});

test('default allocation with replicas set', async () => {
const { actions } = testBed;
await actions.warm.enable(true);
await actions.warm.setReplicas('123');
await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
const warmPhaseActions = JSON.parse(JSON.parse(latestRequest.requestBody).body).phases.warm
.actions;
expect(warmPhaseActions).toMatchInlineSnapshot(`
Object {
"allocate": Object {
"number_of_replicas": 123,
},
"set_priority": Object {
"priority": 50,
},
}
`);
});

test('setting warm phase on rollover to "true"', async () => {
const { actions } = testBed;
await actions.warm.enable(true);
Expand Down Expand Up @@ -252,6 +233,7 @@ describe('<EditPolicy />', () => {
test('preserves include, exclude allocation settings', async () => {
const { actions } = testBed;
await actions.warm.setDataAllocation('node_attrs');
await actions.warm.setSelectedNodeAttribute('test:123');
await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
const warmPhaseAllocate = JSON.parse(JSON.parse(latestRequest.requestBody).body).phases.warm
Expand All @@ -264,6 +246,101 @@ describe('<EditPolicy />', () => {
"include": Object {
"abc": "123",
},
"require": Object {
"test": "123",
},
}
`);
});
});
});

describe('cold phase', () => {
describe('serialization', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadPolicies([DEFAULT_POLICY]);
httpRequestsMockHelpers.setListNodes({
nodesByRoles: {},
nodesByAttributes: { test: ['123'] },
isUsingDeprecatedDataRoleConfig: false,
});
httpRequestsMockHelpers.setLoadSnapshotPolicies([]);

await act(async () => {
testBed = await setup();
});

const { component } = testBed;
component.update();
});

test('default values', async () => {
const { actions } = testBed;

await actions.cold.enable(true);
await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
const entirePolicy = JSON.parse(JSON.parse(latestRequest.requestBody).body);
expect(entirePolicy.phases.cold).toMatchInlineSnapshot(`
Object {
"actions": Object {
"set_priority": Object {
"priority": 0,
},
},
"min_age": "0d",
}
`);
});

test('setting all values', async () => {
const { actions } = testBed;

await actions.cold.enable(true);
await actions.cold.setMinAgeValue('123');
await actions.cold.setMinAgeUnits('s');
await actions.cold.setDataAllocation('node_attrs');
await actions.cold.setSelectedNodeAttribute('test:123');
await actions.cold.setReplicas('123');
await actions.cold.setFreeze(true);
await actions.cold.setIndexPriority('123');

await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
const entirePolicy = JSON.parse(JSON.parse(latestRequest.requestBody).body);

expect(entirePolicy).toMatchInlineSnapshot(`
Object {
"name": "my_policy",
"phases": Object {
"cold": Object {
"actions": Object {
"allocate": Object {
"number_of_replicas": 123,
"require": Object {
"test": "123",
},
},
"freeze": Object {},
"set_priority": Object {
"priority": 123,
},
},
"min_age": "123s",
},
"hot": Object {
"actions": Object {
"rollover": Object {
"max_age": "30d",
"max_size": "50gb",
},
"set_priority": Object {
"priority": 100,
},
},
"min_age": "0ms",
},
},
}
`);
});
Expand Down Expand Up @@ -385,6 +462,33 @@ describe('<EditPolicy />', () => {
});

describe('data allocation', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadPolicies([POLICY_WITH_MIGRATE_OFF]);
httpRequestsMockHelpers.setListNodes({
nodesByRoles: {},
nodesByAttributes: { test: ['123'] },
isUsingDeprecatedDataRoleConfig: false,
});
httpRequestsMockHelpers.setLoadSnapshotPolicies([]);

await act(async () => {
testBed = await setup();
});

const { component } = testBed;
component.update();
});

test('setting node_attr based allocation, but not selecting node attribute', async () => {
const { actions } = testBed;
await actions.warm.setDataAllocation('node_attrs');
await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
const warmPhase = JSON.parse(JSON.parse(latestRequest.requestBody).body).phases.warm;

expect(warmPhase.actions.migrate).toEqual({ enabled: false });
});

describe('node roles', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadPolicies([POLICY_WITH_NODE_ROLE_ALLOCATION]);
Expand All @@ -401,15 +505,32 @@ describe('<EditPolicy />', () => {
const { component } = testBed;
component.update();
});
test('showing "default" type', () => {

test('detecting use of the recommended allocation type', () => {
const { find } = testBed;
expect(find('warm-dataTierAllocationControls.dataTierSelect').text()).toContain(
'recommended'
);
expect(find('warm-dataTierAllocationControls.dataTierSelect').text()).not.toContain(
'Custom'
);
expect(find('warm-dataTierAllocationControls.dataTierSelect').text()).not.toContain('Off');
const selectedDataAllocation = find(
'warm-dataTierAllocationControls.dataTierSelect'
).text();
expect(selectedDataAllocation).toBe('Use warm nodes (recommended)');
});

test('setting replicas serialization', async () => {
const { actions } = testBed;
await actions.warm.setReplicas('123');
await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
const warmPhaseActions = JSON.parse(JSON.parse(latestRequest.requestBody).body).phases.warm
.actions;
expect(warmPhaseActions).toMatchInlineSnapshot(`
Object {
"allocate": Object {
"number_of_replicas": 123,
},
"set_priority": Object {
"priority": 50,
},
}
`);
});
});
describe('node attr and none', () => {
Expand All @@ -429,9 +550,12 @@ describe('<EditPolicy />', () => {
component.update();
});

test('showing "custom" and "off" types', () => {
test('detecting use of the custom allocation type', () => {
const { find } = testBed;
expect(find('warm-dataTierAllocationControls.dataTierSelect').text()).toBe('Custom');
});
test('detecting use of the "off" allocation type', () => {
const { find } = testBed;
expect(find('warm-dataTierAllocationControls.dataTierSelect').text()).toContain('Custom');
expect(find('cold-dataTierAllocationControls.dataTierSelect').text()).toContain('Off');
});
});
Expand Down
Expand Up @@ -17,4 +17,5 @@ export type TestSubjects =
| 'hot-selectedMaxDocuments'
| 'hot-selectedMaxAge'
| 'hot-selectedMaxAgeUnits'
| 'freezeSwitch'
| string;

0 comments on commit 69234d4

Please sign in to comment.