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 Hot phase to Form Lib #80012

Merged
merged 33 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0b59256
wip
jloleysens Oct 6, 2020
ea04a60
added missing shared_imports file to index
jloleysens Oct 6, 2020
5f265af
initial migration of hot phase to form lib
jloleysens Oct 8, 2020
16adb9b
Big refactor
jloleysens Oct 8, 2020
4cd11d6
Merge branch 'master' into ilm/migrate-hotphase-to-formlib
kibanamachine Oct 12, 2020
0eb0610
Integrate form lib serialization with existing serialization
jloleysens Oct 12, 2020
d9f4c5f
wip on fixing jest tests and some other refactors
jloleysens Oct 13, 2020
f030d70
fix jest tests and other refactors
jloleysens Oct 13, 2020
deb67bf
delete existing hot phase serialization and tests
jloleysens Oct 13, 2020
d087b44
beginning of serializer test for hot phase
jloleysens Oct 13, 2020
bed6317
added serialization tests for form lib components
jloleysens Oct 13, 2020
200b6d4
Merge branch 'master' of github.com:elastic/kibana into ilm/migrate-h…
jloleysens Oct 13, 2020
3655f0f
fix some i18n issues
jloleysens Oct 13, 2020
5dc6023
fixed delete phase integration test
jloleysens Oct 13, 2020
d1fdd66
move hot phase serialization test to pre-existing test location
jloleysens Oct 13, 2020
a33ab32
fix another jest test issue
jloleysens Oct 13, 2020
2cbc917
fix ui metric tracking for setting input priority in hot phase
jloleysens Oct 14, 2020
f78b566
Merge branch 'master' into ilm/migrate-hotphase-to-formlib
kibanamachine Oct 14, 2020
b0a8096
refactor use rollover switch to form lib component and update validat…
jloleysens Oct 14, 2020
22017f7
readded missing validation 🤦🏼‍♂️
jloleysens Oct 14, 2020
eab1538
Merge branch 'master' into ilm/migrate-hotphase-to-formlib
kibanamachine Oct 16, 2020
a8ab7b6
fix type check issues and setting of rollover enabled 🙄
jloleysens Oct 16, 2020
b7a7f37
migrate all form lib components to spreading all rest props in EuiFor…
jloleysens Oct 16, 2020
759a0a0
added comment to test helper function
jloleysens Oct 16, 2020
100ad62
refactor test helper setPhaseIndexPriorityFormLib -> setPhaseIndexPri…
jloleysens Oct 16, 2020
9d869c8
refactor to use form schema
jloleysens Oct 16, 2020
844be4b
Removed use of UseMultiFields component
jloleysens Oct 16, 2020
7da30bd
update json flyout behaviour
jloleysens Oct 16, 2020
7f48a65
fix json policy serialization
jloleysens Oct 16, 2020
e5665d0
Fix type and i18n issues
jloleysens Oct 16, 2020
55346ba
Merge branch 'master' into ilm/migrate-hotphase-to-formlib
kibanamachine Oct 19, 2020
b560f21
do not use form.subscribe
jloleysens Oct 19, 2020
371ff40
add missing key value in cells
jloleysens Oct 19, 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 @@ -39,8 +39,8 @@ export const CheckBoxField = ({ field, euiFieldProps = {}, ...rest }: Props) =>
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiCheckbox
label={field.label}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export const ComboBoxField = ({ field, euiFieldProps = {}, ...rest }: Props) =>
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiComboBox
noSuggestions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const MultiSelectField = ({ field, euiFieldProps = {}, ...rest }: Props)
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiSelectable
allowExclusions={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const NumericField = ({ field, euiFieldProps = {}, ...rest }: Props) => {
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
Copy link
Contributor

Choose a reason for hiding this comment

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

Great! 👍 Can we make this change to all the components?

>
<EuiFieldNumber
isInvalid={isInvalid}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const RadioGroupField = ({ field, euiFieldProps = {}, ...rest }: Props) =
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiRadioGroup
idSelected={field.value as string}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export const RangeField = ({ field, euiFieldProps = {}, ...rest }: Props) => {
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiRange
value={field.value as number}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export const SelectField = ({ field, euiFieldProps, ...rest }: Props) => {
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiSelect
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export const SuperSelectField = ({ field, euiFieldProps = { options: [] }, ...re
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiSuperSelect
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const TextAreaField = ({ field, euiFieldProps = {}, ...rest }: Props) =>
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiTextArea
isInvalid={isInvalid}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const TextField = ({ field, euiFieldProps = {}, ...rest }: Props) => {
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiFieldText
isInvalid={isInvalid}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export const ToggleField = ({ field, euiFieldProps = {}, ...rest }: Props) => {
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiSwitch
label={field.label}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ export const POLICY_NAME = 'my_policy';
export const SNAPSHOT_POLICY_NAME = 'my_snapshot_policy';
export const NEW_SNAPSHOT_POLICY_NAME = 'my_new_snapshot_policy';

export const DEFAULT_POLICY: PolicyFromES = {
version: 1,
modified_date: Date.now().toString(),
policy: {
name: '',
phases: {
hot: {
min_age: '123ms',
actions: {
rollover: {},
},
},
},
},
name: '',
};

export const DELETE_PHASE_POLICY: PolicyFromES = {
version: 1,
modified_date: Date.now().toString(),
Expand All @@ -19,8 +36,12 @@ export const DELETE_PHASE_POLICY: PolicyFromES = {
min_age: '0ms',
actions: {
rollover: {
max_age: '30d',
max_size: '50gb',
},
set_priority: {
priority: 100,
},
},
},
delete: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react';
import { act } from 'react-dom/test-utils';

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

import { POLICY_NAME } from './constants';
import { TestSubjects } from '../helpers';
Expand Down Expand Up @@ -43,39 +43,110 @@ const testBedConfig: TestBedConfig = {
},
};

const initTestBed = registerTestBed(EditPolicy, testBedConfig);
const initTestBed = registerTestBed<TestSubjects>(EditPolicy, testBedConfig);

export interface EditPolicyTestBed extends TestBed<TestSubjects> {
actions: {
setWaitForSnapshotPolicy: (snapshotPolicyName: string) => void;
savePolicy: () => void;
};
}
type SetupReturn = ReturnType<typeof setup>;

export type EditPolicyTestBed = SetupReturn extends Promise<infer U> ? U : SetupReturn;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice trick! I guess we'll never hit the right part of the ternary right? But this is a way to extract U? Interesting... 😊


export const setup = async (): Promise<EditPolicyTestBed> => {
export const setup = async () => {
const testBed = await initTestBed();

const { find, component } = testBed;

const setWaitForSnapshotPolicy = async (snapshotPolicyName: string) => {
const { component } = testBed;
act(() => {
testBed.find('snapshotPolicyCombobox').simulate('change', [{ label: snapshotPolicyName }]);
find('snapshotPolicyCombobox').simulate('change', [{ label: snapshotPolicyName }]);
});
component.update();
};

const savePolicy = async () => {
const { component, find } = testBed;
await act(async () => {
find('savePolicyButton').simulate('click');
});
component.update();
};

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

const setMaxSize = async (value: string, units?: string) => {
await act(async () => {
find('hot-selectedMaxSizeStored').simulate('change', { target: { value } });
if (units) {
find('hot-selectedMaxSizeStoredUnits.select').simulate('change', {
target: { value: units },
});
}
});
component.update();
};

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

const setMaxAge = async (value: string, units?: string) => {
await act(async () => {
find('hot-selectedMaxAge').simulate('change', { target: { value } });
if (units) {
find('hot-selectedMaxAgeUnits.select').simulate('change', { target: { value: units } });
}
});
component.update();
};

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

const setForcemergeSegmentsCount = (phase: string) => async (value: string) => {
await act(async () => {
find(`${phase}-selectedForceMergeSegments`).simulate('change', { target: { value } });
});
component.update();
};

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

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

return {
...testBed,
actions: {
setWaitForSnapshotPolicy,
savePolicy,
hot: {
setMaxSize,
setMaxDocs,
setMaxAge,
toggleRollover,
toggleForceMerge: toggleForceMerge('hot'),
setForcemergeSegments: setForcemergeSegmentsCount('hot'),
setBestCompression: setBestCompression('hot'),
setIndexPriority: setIndexPriority('hot'),
},
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import { setupEnvironment } from '../helpers/setup_environment';
import { EditPolicyTestBed, setup } from './edit_policy.helpers';

import { API_BASE_PATH } from '../../../common/constants';
import { DELETE_PHASE_POLICY, NEW_SNAPSHOT_POLICY_NAME, SNAPSHOT_POLICY_NAME } from './constants';
import {
DELETE_PHASE_POLICY,
NEW_SNAPSHOT_POLICY_NAME,
SNAPSHOT_POLICY_NAME,
DEFAULT_POLICY,
} from './constants';

window.scrollTo = jest.fn();

Expand All @@ -21,6 +26,83 @@ describe('<EditPolicy />', () => {
server.restore();
});

describe('hot phase', () => {
describe('serialization', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome to have the serialization test here! 👍

beforeEach(async () => {
httpRequestsMockHelpers.setLoadPolicies([DEFAULT_POLICY]);
httpRequestsMockHelpers.setLoadSnapshotPolicies([]);

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

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

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

await actions.hot.setMaxSize('123', 'mb');
await actions.hot.setMaxDocs('123');
await actions.hot.setMaxAge('123', 'h');
await actions.hot.toggleForceMerge(true);
await actions.hot.setForcemergeSegments('123');
await actions.hot.setBestCompression(true);
await actions.hot.setIndexPriority('123');

await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toMatchInlineSnapshot(`
Object {
"name": "my_policy",
"phases": Object {
"hot": Object {
"actions": Object {
"forcemerge": Object {
"index_codec": "best_compression",
"max_num_segments": 123,
},
"rollover": Object {
"max_age": "123h",
"max_docs": 123,
"max_size": "123mb",
},
"set_priority": Object {
"priority": 123,
},
},
"min_age": "0ms",
},
},
}
`);
});

test('disabling rollover', async () => {
const { actions } = testBed;
await actions.hot.toggleRollover(false);
await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toMatchInlineSnapshot(`
Object {
"name": "my_policy",
"phases": Object {
"hot": Object {
"actions": Object {
"set_priority": Object {
"priority": 100,
},
},
"min_age": "0ms",
},
},
}
`);
});
});
});

describe('delete phase', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadPolicies([DELETE_PHASE_POLICY]);
Expand Down
Loading