Skip to content

Commit cbd52be

Browse files
Merge branch 'master' into grunt/rm-check-plugins
2 parents 0362095 + b8ab3fd commit cbd52be

File tree

24 files changed

+1000
-350
lines changed

24 files changed

+1000
-350
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export const setup = async (arg?: { appServicesContext: Partial<AppServicesConte
111111
component.update();
112112
};
113113

114+
const toggleDefaultRollover = createFormToggleAction('useDefaultRolloverSwitch');
115+
114116
const toggleRollover = createFormToggleAction('rolloverSwitch');
115117

116118
const setMaxSize = async (value: string, units?: string) => {
@@ -239,6 +241,7 @@ export const setup = async (arg?: { appServicesContext: Partial<AppServicesConte
239241
setMaxDocs,
240242
setMaxAge,
241243
toggleRollover,
244+
toggleDefaultRollover,
242245
...createForceMergeActions('hot'),
243246
setIndexPriority: setIndexPriority('hot'),
244247
setShrink: setShrink('hot'),

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ describe('<EditPolicy />', () => {
119119
test('setting all values', async () => {
120120
const { actions } = testBed;
121121

122+
await actions.hot.toggleDefaultRollover(false);
122123
await actions.hot.setMaxSize('123', 'mb');
123124
await actions.hot.setMaxDocs('123');
124125
await actions.hot.setMaxAge('123', 'h');
@@ -177,7 +178,8 @@ describe('<EditPolicy />', () => {
177178

178179
test('disabling rollover', async () => {
179180
const { actions } = testBed;
180-
await actions.hot.toggleRollover(true);
181+
await actions.hot.toggleDefaultRollover(false);
182+
await actions.hot.toggleRollover(false);
181183
await actions.savePolicy();
182184
const latestRequest = server.requests[server.requests.length - 1];
183185
const policy = JSON.parse(JSON.parse(latestRequest.requestBody).body);
@@ -212,6 +214,17 @@ describe('<EditPolicy />', () => {
212214
expect(actions.cold.searchableSnapshotsExists()).toBeTruthy();
213215
expect(actions.cold.freezeExists()).toBeFalsy();
214216
});
217+
218+
test('disabling rollover toggle, but enabling default rollover', async () => {
219+
const { actions } = testBed;
220+
await actions.hot.toggleDefaultRollover(false);
221+
await actions.hot.toggleRollover(false);
222+
await actions.hot.toggleDefaultRollover(true);
223+
224+
expect(actions.hot.forceMergeFieldExists()).toBeTruthy();
225+
expect(actions.hot.shrinkExists()).toBeTruthy();
226+
expect(actions.hot.searchableSnapshotsExists()).toBeTruthy();
227+
});
215228
});
216229
});
217230

@@ -766,7 +779,7 @@ describe('<EditPolicy />', () => {
766779
await act(async () => {
767780
testBed = await setup({
768781
appServicesContext: {
769-
license: licensingMock.createLicense({ license: { type: 'basic' } }),
782+
license: licensingMock.createLicense({ license: { type: 'enterprise' } }),
770783
},
771784
});
772785
});
@@ -776,11 +789,12 @@ describe('<EditPolicy />', () => {
776789
});
777790
test('hiding and disabling searchable snapshot field', async () => {
778791
const { actions } = testBed;
792+
await actions.hot.toggleDefaultRollover(false);
779793
await actions.hot.toggleRollover(false);
780794
await actions.cold.enable(true);
781795

782796
expect(actions.hot.searchableSnapshotsExists()).toBeFalsy();
783-
expect(actions.cold.searchableSnapshotDisabledDueToLicense()).toBeTruthy();
797+
expect(actions.cold.searchableSnapshotDisabledDueToRollover()).toBeTruthy();
784798
});
785799
});
786800
});

x-pack/plugins/index_lifecycle_management/__jest__/components/edit_policy.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,14 @@ const expectedErrorMessages = (rendered: ReactWrapper, expectedMessages: string[
113113
expect(foundErrorMessage).toBe(true);
114114
});
115115
};
116+
const noDefaultRollover = async (rendered: ReactWrapper) => {
117+
await act(async () => {
118+
findTestSubject(rendered, 'useDefaultRolloverSwitch').simulate('click');
119+
});
120+
rendered.update();
121+
};
116122
const noRollover = async (rendered: ReactWrapper) => {
123+
await noDefaultRollover(rendered);
117124
await act(async () => {
118125
findTestSubject(rendered, 'rolloverSwitch').simulate('click');
119126
});
@@ -326,6 +333,7 @@ describe('edit policy', () => {
326333
describe('hot phase', () => {
327334
test('should show errors when trying to save with no max size, no max age and no max docs', async () => {
328335
const rendered = mountWithIntl(component);
336+
await noDefaultRollover(rendered);
329337
expect(findTestSubject(rendered, 'rolloverSettingsRequired').exists()).toBeFalsy();
330338
await setPolicyName(rendered, 'mypolicy');
331339
const maxSizeInput = findTestSubject(rendered, 'hot-selectedMaxSizeStored');
@@ -349,6 +357,7 @@ describe('edit policy', () => {
349357
test('should show number above 0 required error when trying to save with -1 for max size', async () => {
350358
const rendered = mountWithIntl(component);
351359
await setPolicyName(rendered, 'mypolicy');
360+
await noDefaultRollover(rendered);
352361
const maxSizeInput = findTestSubject(rendered, 'hot-selectedMaxSizeStored');
353362
await act(async () => {
354363
maxSizeInput.simulate('change', { target: { value: '-1' } });
@@ -360,6 +369,7 @@ describe('edit policy', () => {
360369
test('should show number above 0 required error when trying to save with 0 for max size', async () => {
361370
const rendered = mountWithIntl(component);
362371
await setPolicyName(rendered, 'mypolicy');
372+
await noDefaultRollover(rendered);
363373
const maxSizeInput = findTestSubject(rendered, 'hot-selectedMaxSizeStored');
364374
await act(async () => {
365375
maxSizeInput.simulate('change', { target: { value: '-1' } });
@@ -370,6 +380,7 @@ describe('edit policy', () => {
370380
test('should show number above 0 required error when trying to save with -1 for max age', async () => {
371381
const rendered = mountWithIntl(component);
372382
await setPolicyName(rendered, 'mypolicy');
383+
await noDefaultRollover(rendered);
373384
const maxAgeInput = findTestSubject(rendered, 'hot-selectedMaxAge');
374385
await act(async () => {
375386
maxAgeInput.simulate('change', { target: { value: '-1' } });
@@ -380,6 +391,7 @@ describe('edit policy', () => {
380391
test('should show number above 0 required error when trying to save with 0 for max age', async () => {
381392
const rendered = mountWithIntl(component);
382393
await setPolicyName(rendered, 'mypolicy');
394+
await noDefaultRollover(rendered);
383395
const maxAgeInput = findTestSubject(rendered, 'hot-selectedMaxAge');
384396
await act(async () => {
385397
maxAgeInput.simulate('change', { target: { value: '0' } });

x-pack/plugins/index_lifecycle_management/common/types/policies.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ export interface SearchableSnapshotAction {
5757
force_merge_index?: boolean;
5858
}
5959

60+
export interface RolloverAction {
61+
max_size?: string;
62+
max_age?: string;
63+
max_docs?: number;
64+
}
65+
6066
export interface SerializedHotPhase extends SerializedPhase {
6167
actions: {
62-
rollover?: {
63-
max_size?: string;
64-
max_age?: string;
65-
max_docs?: number;
66-
};
68+
rollover?: RolloverAction;
6769
forcemerge?: ForcemergeAction;
6870
readonly?: {};
6971
shrink?: ShrinkAction;

x-pack/plugins/index_lifecycle_management/public/application/constants/policy.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,28 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { SerializedPhase, DeletePhase, SerializedPolicy } from '../../../common/types';
7+
import {
8+
SerializedPhase,
9+
DeletePhase,
10+
SerializedPolicy,
11+
RolloverAction,
12+
} from '../../../common/types';
813

914
export const defaultSetPriority: string = '100';
1015

1116
export const defaultPhaseIndexPriority: string = '50';
1217

18+
export const defaultRolloverAction: RolloverAction = {
19+
max_age: '30d',
20+
max_size: '50gb',
21+
};
22+
1323
export const defaultPolicy: SerializedPolicy = {
1424
name: '',
1525
phases: {
1626
hot: {
1727
actions: {
18-
rollover: {
19-
max_age: '30d',
20-
max_size: '50gb',
21-
},
28+
rollover: defaultRolloverAction,
2229
},
2330
},
2431
},

x-pack/plugins/index_lifecycle_management/public/application/lib/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
*/
66

77
export * from './data_tiers';
8+
9+
export * from './rollover';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { SerializedPolicy } from '../../../common/types';
8+
import { defaultRolloverAction } from '../constants';
9+
10+
export const isUsingDefaultRollover = (policy: SerializedPolicy): boolean => {
11+
const rollover = policy?.phases?.hot?.actions?.rollover;
12+
return Boolean(
13+
rollover &&
14+
rollover.max_age === defaultRolloverAction.max_age &&
15+
rollover.max_docs === defaultRolloverAction.max_docs &&
16+
rollover.max_size === defaultRolloverAction.max_size
17+
);
18+
};

x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/described_form_row/described_form_row.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ export const DescribedFormRow: FunctionComponent<Props> = ({
5555
const [uncontrolledIsContentVisible, setUncontrolledIsContentVisible] = useState<boolean>(
5656
() => switchProps?.initialValue ?? false
5757
);
58-
const isContentVisible = Boolean(switchProps?.checked ?? uncontrolledIsContentVisible);
58+
const isContentVisible = Boolean(
59+
switchProps === undefined || (switchProps?.checked ?? uncontrolledIsContentVisible)
60+
);
5961

6062
const renderToggle = () => {
6163
if (!switchProps) {

0 commit comments

Comments
 (0)