fix serialization of rollover (#85582)

This commit is contained in:
Jean-Louis Leysens 2020-12-10 17:53:01 +01:00 committed by GitHub
parent 051bbf073e
commit b24ee4b3ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View file

@ -300,4 +300,16 @@ describe('deserializer and serializer', () => {
expect(result.phases.hot!.actions.shrink).toBeUndefined();
expect(result.phases.warm!.actions.shrink).toBeUndefined();
});
it('removes rollover action fields', () => {
formInternal.phases.hot!.actions.rollover!.max_size = '';
formInternal.phases.hot!.actions.rollover!.max_age = '';
formInternal.phases.hot!.actions.rollover!.max_docs = '' as any;
const result = serializer(formInternal);
expect(result.phases.hot!.actions.rollover!.max_age).toBeUndefined();
expect(result.phases.hot!.actions.rollover!.max_docs).toBeUndefined();
expect(result.phases.hot!.actions.rollover!.max_size).toBeUndefined();
});
});

View file

@ -43,12 +43,20 @@ export const createSerializer = (originalPolicy?: SerializedPolicy) => (
if (draft.phases.hot?.actions) {
const hotPhaseActions = draft.phases.hot.actions;
if (hotPhaseActions.rollover && _meta.hot.useRollover) {
if (hotPhaseActions.rollover.max_age) {
if (updatedPolicy.phases.hot!.actions.rollover?.max_age) {
hotPhaseActions.rollover.max_age = `${hotPhaseActions.rollover.max_age}${_meta.hot.maxAgeUnit}`;
} else {
delete hotPhaseActions.rollover.max_age;
}
if (hotPhaseActions.rollover.max_size) {
if (typeof updatedPolicy.phases.hot!.actions.rollover?.max_docs !== 'number') {
delete hotPhaseActions.rollover.max_docs;
}
if (updatedPolicy.phases.hot!.actions.rollover?.max_size) {
hotPhaseActions.rollover.max_size = `${hotPhaseActions.rollover.max_size}${_meta.hot.maxStorageSizeUnit}`;
} else {
delete hotPhaseActions.rollover.max_size;
}
if (!updatedPolicy.phases.hot!.actions?.forcemerge) {