Skip to content

Commit 6e5455e

Browse files
committed
[ILM] Add shrink field to hot phase (#84087)
* moved shrink field to shared_fields and added it to the hot phase * updated test * update legacy jest test * removed configuration context for now * remove unused i18n and remove duplicated isRolloverEnabled check; * fixed shrink field to use new described field component * added test for removing shrink field in serialization and re-ordered fields in hot phase advanced
1 parent f8f6c3f commit 6e5455e

15 files changed

Lines changed: 140 additions & 81 deletions

File tree

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ export const setup = async (arg?: { appServicesContext: Partial<AppServicesConte
187187
await createFormSetValueAction(`${phase}-selectedReplicaCount`)(value);
188188
};
189189

190-
const setShrink = async (value: string) => {
191-
await createFormToggleAction('shrinkSwitch')(true);
192-
await createFormSetValueAction('warm-selectedPrimaryShardCount')(value);
190+
const setShrink = (phase: Phases) => async (value: string) => {
191+
await createFormToggleAction(`${phase}-shrinkSwitch`)(true);
192+
await createFormSetValueAction(`${phase}-selectedPrimaryShardCount`)(value);
193193
};
194194

195-
const shrinkExists = () => exists('shrinkSwitch');
195+
const shrinkExists = (phase: Phases) => () => exists(`${phase}-shrinkSwitch`);
196196

197197
const setFreeze = createFormToggleAction('freezeSwitch');
198198
const freezeExists = () => exists('freezeSwitch');
@@ -237,6 +237,8 @@ export const setup = async (arg?: { appServicesContext: Partial<AppServicesConte
237237
toggleRollover,
238238
...createForceMergeActions('hot'),
239239
setIndexPriority: setIndexPriority('hot'),
240+
setShrink: setShrink('hot'),
241+
shrinkExists: shrinkExists('hot'),
240242
...createSearchableSnapshotActions('hot'),
241243
},
242244
warm: {
@@ -247,8 +249,8 @@ export const setup = async (arg?: { appServicesContext: Partial<AppServicesConte
247249
setDataAllocation: setDataAllocation('warm'),
248250
setSelectedNodeAttribute: setSelectedNodeAttribute('warm'),
249251
setReplicas: setReplicas('warm'),
250-
setShrink,
251-
shrinkExists,
252+
setShrink: setShrink('warm'),
253+
shrinkExists: shrinkExists('warm'),
252254
...createForceMergeActions('warm'),
253255
setIndexPriority: setIndexPriority('warm'),
254256
},

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ describe('<EditPolicy />', () => {
125125
await actions.hot.toggleForceMerge(true);
126126
await actions.hot.setForcemergeSegmentsCount('123');
127127
await actions.hot.setBestCompression(true);
128+
await actions.hot.setShrink('2');
128129
await actions.hot.setIndexPriority('123');
129130

130131
await actions.savePolicy();
@@ -148,6 +149,9 @@ describe('<EditPolicy />', () => {
148149
"set_priority": Object {
149150
"priority": 123,
150151
},
152+
"shrink": Object {
153+
"number_of_shards": 2,
154+
},
151155
},
152156
"min_age": "0ms",
153157
},

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ describe('edit policy', () => {
487487
await setPolicyName(rendered, 'mypolicy');
488488
await activatePhase(rendered, 'warm');
489489
act(() => {
490-
findTestSubject(rendered, 'shrinkSwitch').simulate('click');
490+
findTestSubject(rendered, 'warm-shrinkSwitch').simulate('click');
491491
});
492492
rendered.update();
493493
await setPhaseAfter(rendered, 'warm', '1');
@@ -505,7 +505,7 @@ describe('edit policy', () => {
505505
await activatePhase(rendered, 'warm');
506506
await setPhaseAfter(rendered, 'warm', '1');
507507
act(() => {
508-
findTestSubject(rendered, 'shrinkSwitch').simulate('click');
508+
findTestSubject(rendered, 'warm-shrinkSwitch').simulate('click');
509509
});
510510
rendered.update();
511511
const shrinkInput = findTestSubject(rendered, 'warm-selectedPrimaryShardCount');

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export interface SerializedHotPhase extends SerializedPhase {
6565
max_docs?: number;
6666
};
6767
forcemerge?: ForcemergeAction;
68+
shrink?: ShrinkAction;
6869
set_priority?: {
6970
priority: number | null;
7071
};
@@ -78,9 +79,7 @@ export interface SerializedHotPhase extends SerializedPhase {
7879
export interface SerializedWarmPhase extends SerializedPhase {
7980
actions: {
8081
allocate?: AllocateAction;
81-
shrink?: {
82-
number_of_shards: number;
83-
};
82+
shrink?: ShrinkAction;
8483
forcemerge?: ForcemergeAction;
8584
set_priority?: {
8685
priority: number | null;
@@ -124,6 +123,10 @@ export interface AllocateAction {
124123
};
125124
}
126125

126+
export interface ShrinkAction {
127+
number_of_shards: number;
128+
}
129+
127130
export interface ForcemergeAction {
128131
max_num_segments: number;
129132
// only accepted value for index_codec

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
SetPriorityInputField,
3838
SearchableSnapshotField,
3939
useRolloverPath,
40+
ShrinkField,
4041
} from '../shared_fields';
4142

4243
import { maxSizeStoredUnits, maxAgeUnits } from './constants';
@@ -235,6 +236,7 @@ export const HotPhase: FunctionComponent = () => {
235236
{isRolloverEnabled && (
236237
<>
237238
{<ForcemergeField phase="hot" />}
239+
<ShrinkField phase="hot" />
238240
{license.canUseSearchableSnapshot() && <SearchableSnapshotField phase="hot" />}
239241
</>
240242
)}

x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared_fields/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ export { MinAgeInputField } from './min_age_input_field';
1616

1717
export { SnapshotPoliciesField } from './snapshot_policies_field';
1818

19+
export { ShrinkField } from './shrink_field';
20+
1921
export { SearchableSnapshotField } from './searchable_snapshot_field';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
import { FormattedMessage } from '@kbn/i18n/react';
7+
import { EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiTextColor } from '@elastic/eui';
8+
import React, { FunctionComponent } from 'react';
9+
10+
import { UseField, NumericField } from '../../../../../../shared_imports';
11+
12+
import { useEditPolicyContext } from '../../../edit_policy_context';
13+
import { i18nTexts } from '../../../i18n_texts';
14+
15+
import { LearnMoreLink, DescribedFormRow } from '../../';
16+
17+
interface Props {
18+
phase: 'hot' | 'warm';
19+
}
20+
21+
export const ShrinkField: FunctionComponent<Props> = ({ phase }) => {
22+
const path = `phases.${phase}.actions.shrink.number_of_shards`;
23+
const { policy } = useEditPolicyContext();
24+
return (
25+
<DescribedFormRow
26+
title={
27+
<h3>
28+
<FormattedMessage
29+
id="xpack.indexLifecycleMgmt.editPolicy.shrinkText"
30+
defaultMessage="Shrink"
31+
/>
32+
</h3>
33+
}
34+
description={
35+
<EuiTextColor color="subdued">
36+
<FormattedMessage
37+
id="xpack.indexLifecycleMgmt.editPolicy.shrinkIndexExplanationText"
38+
defaultMessage="Shrink the index into a new index with fewer primary shards."
39+
/>{' '}
40+
<LearnMoreLink docPath="indices-shrink-index.html#indices-shrink-index" />
41+
</EuiTextColor>
42+
}
43+
titleSize="xs"
44+
switchProps={{
45+
'aria-controls': 'shrinkContent',
46+
'data-test-subj': `${phase}-shrinkSwitch`,
47+
label: i18nTexts.editPolicy.shrinkLabel,
48+
'aria-label': i18nTexts.editPolicy.shrinkLabel,
49+
initialValue: Boolean(policy.phases[phase]?.actions?.shrink),
50+
}}
51+
fullWidth
52+
>
53+
<div id="shrinkContent" aria-live="polite" role="region">
54+
<EuiFlexGroup>
55+
<EuiFlexItem>
56+
<UseField
57+
path={path}
58+
component={NumericField}
59+
componentProps={{
60+
fullWidth: false,
61+
euiFieldProps: {
62+
'data-test-subj': `${phase}-selectedPrimaryShardCount`,
63+
min: 1,
64+
},
65+
}}
66+
/>
67+
</EuiFlexItem>
68+
</EuiFlexGroup>
69+
<EuiSpacer />
70+
</div>
71+
</DescribedFormRow>
72+
);
73+
};

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

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@ import { FormattedMessage } from '@kbn/i18n/react';
99
import { i18n } from '@kbn/i18n';
1010
import { get } from 'lodash';
1111

12-
import {
13-
EuiTextColor,
14-
EuiFlexGroup,
15-
EuiFlexItem,
16-
EuiSpacer,
17-
EuiDescribedFormGroup,
18-
EuiAccordion,
19-
} from '@elastic/eui';
12+
import { EuiSpacer, EuiDescribedFormGroup, EuiAccordion } from '@elastic/eui';
2013

2114
import { useFormData, UseField, ToggleField, NumericField } from '../../../../../../shared_imports';
2215

@@ -25,20 +18,18 @@ import { Phases } from '../../../../../../../common/types';
2518
import { useEditPolicyContext } from '../../../edit_policy_context';
2619
import { useConfigurationIssues } from '../../../form';
2720

28-
import { LearnMoreLink, ActiveBadge, DescribedFormRow } from '../../';
21+
import { ActiveBadge, DescribedFormRow } from '../../';
2922

3023
import {
3124
useRolloverPath,
3225
MinAgeInputField,
3326
ForcemergeField,
3427
SetPriorityInputField,
3528
DataTierAllocationField,
29+
ShrinkField,
3630
} from '../shared_fields';
3731

3832
const i18nTexts = {
39-
shrinkLabel: i18n.translate('xpack.indexLifecycleMgmt.warmPhase.shrinkIndexLabel', {
40-
defaultMessage: 'Shrink index',
41-
}),
4233
dataTierAllocation: {
4334
description: i18n.translate('xpack.indexLifecycleMgmt.warmPhase.dataTier.description', {
4435
defaultMessage: 'Move data to nodes optimized for less-frequent, read-only access.',
@@ -178,55 +169,8 @@ export const WarmPhase: FunctionComponent = () => {
178169
}}
179170
/>
180171
</DescribedFormRow>
181-
{!isUsingSearchableSnapshotInHotPhase && (
182-
<DescribedFormRow
183-
title={
184-
<h3>
185-
<FormattedMessage
186-
id="xpack.indexLifecycleMgmt.editPolicy.warmPhase.shrinkText"
187-
defaultMessage="Shrink"
188-
/>
189-
</h3>
190-
}
191-
description={
192-
<EuiTextColor color="subdued">
193-
<FormattedMessage
194-
id="xpack.indexLifecycleMgmt.editPolicy.warmPhase.shrinkIndexExplanationText"
195-
defaultMessage="Shrink the index into a new index with fewer primary shards."
196-
/>{' '}
197-
<LearnMoreLink docPath="indices-shrink-index.html#indices-shrink-index" />
198-
</EuiTextColor>
199-
}
200-
titleSize="xs"
201-
switchProps={{
202-
'aria-controls': 'shrinkContent',
203-
'data-test-subj': 'shrinkSwitch',
204-
label: i18nTexts.shrinkLabel,
205-
'aria-label': i18nTexts.shrinkLabel,
206-
initialValue: policy.phases.warm?.actions?.shrink != null,
207-
}}
208-
fullWidth
209-
>
210-
<div id="shrinkContent" aria-live="polite" role="region">
211-
<EuiSpacer />
212-
<EuiFlexGroup>
213-
<EuiFlexItem grow={false}>
214-
<UseField
215-
path="phases.warm.actions.shrink.number_of_shards"
216-
component={NumericField}
217-
componentProps={{
218-
euiFieldProps: {
219-
'data-test-subj': `${warmProperty}-selectedPrimaryShardCount`,
220-
min: 1,
221-
},
222-
}}
223-
/>
224-
</EuiFlexItem>
225-
</EuiFlexGroup>
226-
<EuiSpacer />
227-
</div>
228-
</DescribedFormRow>
229-
)}
172+
173+
{!isUsingSearchableSnapshotInHotPhase && <ShrinkField phase="warm" />}
230174

231175
{!isUsingSearchableSnapshotInHotPhase && <ForcemergeField phase="warm" />}
232176
{/* Data tier allocation section */}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
import { schema, deserializer, createSerializer, createPolicyNameValidations, Form } from './form';
4949

5050
import { useEditPolicyContext } from './edit_policy_context';
51+
5152
import { FormInternal } from './types';
5253

5354
export interface Props {

x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/deserializer_and_serializer.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,14 @@ describe('deserializer and serializer', () => {
290290
enabled: false,
291291
});
292292
});
293+
294+
it('removes shrink from hot and warm when unset', () => {
295+
delete formInternal.phases.hot!.actions!.shrink;
296+
delete formInternal.phases.warm!.actions!.shrink;
297+
298+
const result = serializer(formInternal);
299+
300+
expect(result.phases.hot!.actions.shrink).toBeUndefined();
301+
expect(result.phases.warm!.actions.shrink).toBeUndefined();
302+
});
293303
});

0 commit comments

Comments
 (0)