Skip to content

Commit bfa87d2

Browse files
[ILM] Add support for frozen phase in UI (#75968) (#76268)
* ILM public side changes to support frozen phase This is a very faithful duplication of the cold phase. We are also excluding the snapshot action as well as the unfollow action as these are features that require higher than basic license privilege. * added "frozen" to the server side schema * add frozen phases component * fix i18n and update jest tests * Slight restructuring to phase types and fix copy paste issues. - also fixed TS error introduced after TS v4 upgrade (delete) * fix hot phase type and remove type constraint from error messages * update validation logic Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 60c2737 commit bfa87d2

File tree

19 files changed

+527
-50
lines changed

19 files changed

+527
-50
lines changed

x-pack/plugins/index_lifecycle_management/__jest__/__snapshots__/extend_index_management.test.js.snap

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
DeletePhase,
1111
HotPhase,
1212
WarmPhase,
13+
FrozenPhase,
1314
} from '../services/policies/types';
1415

1516
export const defaultNewHotPhase: HotPhase = {
@@ -47,6 +48,16 @@ export const defaultNewColdPhase: ColdPhase = {
4748
phaseIndexPriority: '0',
4849
};
4950

51+
export const defaultNewFrozenPhase: FrozenPhase = {
52+
phaseEnabled: false,
53+
selectedMinimumAge: '0',
54+
selectedMinimumAgeUnits: 'd',
55+
selectedNodeAttrs: '',
56+
selectedReplicaCount: '',
57+
freezeEnabled: false,
58+
phaseIndexPriority: '0',
59+
};
60+
5061
export const defaultNewDeletePhase: DeletePhase = {
5162
phaseEnabled: false,
5263
selectedMinimumAge: '0',

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { EuiFieldNumber, EuiFlexGroup, EuiFlexItem, EuiFormRow, EuiSelect } from
1212
import { LearnMoreLink } from './learn_more_link';
1313
import { ErrableFormRow } from './form_errors';
1414
import { PhaseValidationErrors, propertyof } from '../../../services/policies/policy_validation';
15-
import { ColdPhase, DeletePhase, Phase, Phases, WarmPhase } from '../../../services/policies/types';
15+
import { PhaseWithMinAge, Phases } from '../../../services/policies/types';
1616

1717
function getTimingLabelForPhase(phase: keyof Phases) {
1818
// NOTE: Hot phase isn't necessary, because indices begin in the hot phase.
@@ -27,6 +27,11 @@ function getTimingLabelForPhase(phase: keyof Phases) {
2727
defaultMessage: 'Timing for cold phase',
2828
});
2929

30+
case 'frozen':
31+
return i18n.translate('xpack.indexLifecycleMgmt.editPolicy.phaseFrozen.minimumAgeLabel', {
32+
defaultMessage: 'Timing for frozen phase',
33+
});
34+
3035
case 'delete':
3136
return i18n.translate('xpack.indexLifecycleMgmt.editPolicy.phaseDelete.minimumAgeLabel', {
3237
defaultMessage: 'Timing for delete phase',
@@ -63,7 +68,7 @@ function getUnitsAriaLabelForPhase(phase: keyof Phases) {
6368
}
6469
}
6570

66-
interface Props<T extends Phase> {
71+
interface Props<T extends PhaseWithMinAge> {
6772
rolloverEnabled: boolean;
6873
errors?: PhaseValidationErrors<T>;
6974
phase: keyof Phases & string;
@@ -72,7 +77,7 @@ interface Props<T extends Phase> {
7277
isShowingErrors: boolean;
7378
}
7479

75-
export const MinAgeInput = <Phase extends WarmPhase | ColdPhase | DeletePhase>({
80+
export const MinAgeInput = <Phase extends PhaseWithMinAge>({
7681
rolloverEnabled,
7782
errors,
7883
phaseData,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { LearnMoreLink } from './learn_more_link';
2020
import { ErrableFormRow } from './form_errors';
2121
import { useLoadNodes } from '../../../services/api';
2222
import { NodeAttrsDetails } from './node_attrs_details';
23-
import { ColdPhase, Phase, Phases, WarmPhase } from '../../../services/policies/types';
23+
import { PhaseWithAllocationAction, Phases } from '../../../services/policies/types';
2424
import { PhaseValidationErrors, propertyof } from '../../../services/policies/policy_validation';
2525

2626
const learnMoreLink = (
@@ -38,14 +38,14 @@ const learnMoreLink = (
3838
</Fragment>
3939
);
4040

41-
interface Props<T extends Phase> {
41+
interface Props<T extends PhaseWithAllocationAction> {
4242
phase: keyof Phases & string;
4343
errors?: PhaseValidationErrors<T>;
4444
phaseData: T;
4545
setPhaseData: (dataKey: keyof T & string, value: string) => void;
4646
isShowingErrors: boolean;
4747
}
48-
export const NodeAllocation = <T extends WarmPhase | ColdPhase>({
48+
export const NodeAllocation = <T extends PhaseWithAllocationAction>({
4949
phase,
5050
setPhaseData,
5151
errors,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import { EuiFieldNumber, EuiTextColor, EuiDescribedFormGroup } from '@elastic/eu
1010
import { LearnMoreLink } from './';
1111
import { OptionalLabel } from './';
1212
import { ErrableFormRow } from './';
13-
import { ColdPhase, HotPhase, Phase, Phases, WarmPhase } from '../../../services/policies/types';
13+
import { PhaseWithIndexPriority, Phases } from '../../../services/policies/types';
1414
import { PhaseValidationErrors, propertyof } from '../../../services/policies/policy_validation';
1515

16-
interface Props<T extends Phase> {
16+
interface Props<T extends PhaseWithIndexPriority> {
1717
errors?: PhaseValidationErrors<T>;
1818
phase: keyof Phases & string;
1919
phaseData: T;
2020
setPhaseData: (dataKey: keyof T & string, value: any) => void;
2121
isShowingErrors: boolean;
2222
}
23-
export const SetPriorityInput = <T extends HotPhase | WarmPhase | ColdPhase>({
23+
export const SetPriorityInput = <T extends PhaseWithIndexPriority>({
2424
errors,
2525
phaseData,
2626
phase,

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828

2929
import { toasts } from '../../services/notification';
3030

31-
import { Policy, PolicyFromES } from '../../services/policies/types';
31+
import { Phases, Policy, PolicyFromES } from '../../services/policies/types';
3232
import {
3333
validatePolicy,
3434
ValidationErrors,
@@ -42,7 +42,7 @@ import {
4242
} from '../../services/policies/policy_serialization';
4343

4444
import { ErrableFormRow, LearnMoreLink, PolicyJsonFlyout } from './components';
45-
import { ColdPhase, DeletePhase, HotPhase, WarmPhase } from './phases';
45+
import { ColdPhase, DeletePhase, FrozenPhase, HotPhase, WarmPhase } from './phases';
4646

4747
interface Props {
4848
policies: PolicyFromES[];
@@ -118,7 +118,7 @@ export const EditPolicy: React.FunctionComponent<Props> = ({
118118
setIsShowingPolicyJsonFlyout(!isShowingPolicyJsonFlyout);
119119
};
120120

121-
const setPhaseData = (phase: 'hot' | 'warm' | 'cold' | 'delete', key: string, value: any) => {
121+
const setPhaseData = (phase: keyof Phases, key: string, value: any) => {
122122
setPolicy({
123123
...policy,
124124
phases: {
@@ -303,6 +303,16 @@ export const EditPolicy: React.FunctionComponent<Props> = ({
303303

304304
<EuiHorizontalRule />
305305

306+
<FrozenPhase
307+
errors={errors?.frozen}
308+
isShowingErrors={isShowingErrors && !!errors && Object.keys(errors.frozen).length > 0}
309+
setPhaseData={(key, value) => setPhaseData('frozen', key, value)}
310+
phaseData={policy.phases.frozen}
311+
hotPhaseRolloverEnabled={policy.phases.hot.rolloverEnabled}
312+
/>
313+
314+
<EuiHorizontalRule />
315+
306316
<DeletePhase
307317
errors={errors?.delete}
308318
isShowingErrors={isShowingErrors && !!errors && Object.keys(errors.delete).length > 0}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from '@elastic/eui';
2020

2121
import { ColdPhase as ColdPhaseInterface, Phases } from '../../../services/policies/types';
22-
import { PhaseValidationErrors, propertyof } from '../../../services/policies/policy_validation';
22+
import { PhaseValidationErrors } from '../../../services/policies/policy_validation';
2323

2424
import {
2525
LearnMoreLink,
@@ -36,9 +36,8 @@ const freezeLabel = i18n.translate('xpack.indexLifecycleMgmt.coldPhase.freezeInd
3636
defaultMessage: 'Freeze index',
3737
});
3838

39-
const coldProperty = propertyof<Phases>('cold');
40-
const phaseProperty = (propertyName: keyof ColdPhaseInterface) =>
41-
propertyof<ColdPhaseInterface>(propertyName);
39+
const coldProperty: keyof Phases = 'cold';
40+
const phaseProperty = (propertyName: keyof ColdPhaseInterface) => propertyName;
4241

4342
interface Props {
4443
setPhaseData: (key: keyof ColdPhaseInterface & string, value: string | boolean) => void;

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { FormattedMessage } from '@kbn/i18n/react';
99
import { EuiDescribedFormGroup, EuiSwitch, EuiTextColor, EuiFormRow } from '@elastic/eui';
1010

1111
import { DeletePhase as DeletePhaseInterface, Phases } from '../../../services/policies/types';
12-
import { PhaseValidationErrors, propertyof } from '../../../services/policies/policy_validation';
12+
import { PhaseValidationErrors } from '../../../services/policies/policy_validation';
1313

1414
import {
1515
ActiveBadge,
@@ -20,9 +20,8 @@ import {
2020
SnapshotPolicies,
2121
} from '../components';
2222

23-
const deleteProperty = propertyof<Phases>('delete');
24-
const phaseProperty = (propertyName: keyof DeletePhaseInterface) =>
25-
propertyof<DeletePhaseInterface>(propertyName);
23+
const deleteProperty: keyof Phases = 'delete';
24+
const phaseProperty = (propertyName: keyof DeletePhaseInterface) => propertyName;
2625

2726
interface Props {
2827
setPhaseData: (key: keyof DeletePhaseInterface & string, value: string | boolean) => void;

0 commit comments

Comments
 (0)