Skip to content

Commit

Permalink
[ILM] Added readonly field in hot phase (#85419) (#85803)
Browse files Browse the repository at this point in the history
* [ILM] Added readonly field in hot phase

* [ILM] Added readonly field in warm phase

* Update x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared_fields/readonly_field.tsx

Co-authored-by: Alison Goryachev <alisonmllr20@gmail.com>

* Update x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/schema.ts

Co-authored-by: Alison Goryachev <alisonmllr20@gmail.com>

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

Co-authored-by: Alison Goryachev <alisonmllr20@gmail.com>

* Updated labels for the form

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Alison Goryachev <alisonmllr20@gmail.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Alison Goryachev <alisonmllr20@gmail.com>
  • Loading branch information
3 people authored Dec 14, 2020
1 parent b09a9a1 commit 1f21fe7
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ export const setup = async (arg?: { appServicesContext: Partial<AppServicesConte
const setFreeze = createFormToggleAction('freezeSwitch');
const freezeExists = () => exists('freezeSwitch');

const setReadonly = (phase: Phases) => async (value: boolean) => {
await createFormToggleAction(`${phase}-readonlySwitch`)(value);
};

const createSearchableSnapshotActions = (phase: Phases) => {
const fieldSelector = `searchableSnapshotField-${phase}`;
const licenseCalloutSelector = `${fieldSelector}.searchableSnapshotDisabledDueToLicense`;
Expand Down Expand Up @@ -239,6 +243,7 @@ export const setup = async (arg?: { appServicesContext: Partial<AppServicesConte
setIndexPriority: setIndexPriority('hot'),
setShrink: setShrink('hot'),
shrinkExists: shrinkExists('hot'),
setReadonly: setReadonly('hot'),
...createSearchableSnapshotActions('hot'),
},
warm: {
Expand All @@ -252,6 +257,7 @@ export const setup = async (arg?: { appServicesContext: Partial<AppServicesConte
setShrink: setShrink('warm'),
shrinkExists: shrinkExists('warm'),
...createForceMergeActions('warm'),
setReadonly: setReadonly('warm'),
setIndexPriority: setIndexPriority('warm'),
},
cold: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ describe('<EditPolicy />', () => {
await actions.hot.setForcemergeSegmentsCount('123');
await actions.hot.setBestCompression(true);
await actions.hot.setShrink('2');
await actions.hot.setReadonly(true);
await actions.hot.setIndexPriority('123');

await actions.savePolicy();
Expand All @@ -141,6 +142,7 @@ describe('<EditPolicy />', () => {
"index_codec": "best_compression",
"max_num_segments": 123,
},
"readonly": Object {},
"rollover": Object {
"max_age": "123h",
"max_docs": 123,
Expand Down Expand Up @@ -259,6 +261,7 @@ describe('<EditPolicy />', () => {
await actions.warm.toggleForceMerge(true);
await actions.warm.setForcemergeSegmentsCount('123');
await actions.warm.setBestCompression(true);
await actions.warm.setReadonly(true);
await actions.warm.setIndexPriority('123');
await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
Expand Down Expand Up @@ -292,6 +295,7 @@ describe('<EditPolicy />', () => {
"index_codec": "best_compression",
"max_num_segments": 123,
},
"readonly": Object {},
"set_priority": Object {
"priority": 123,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export interface SerializedHotPhase extends SerializedPhase {
max_docs?: number;
};
forcemerge?: ForcemergeAction;
readonly?: {};
shrink?: ShrinkAction;

set_priority?: {
priority: number | null;
};
Expand All @@ -81,6 +83,7 @@ export interface SerializedWarmPhase extends SerializedPhase {
allocate?: AllocateAction;
shrink?: ShrinkAction;
forcemerge?: ForcemergeAction;
readonly?: {};
set_priority?: {
priority: number | null;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
SetPriorityInputField,
SearchableSnapshotField,
useRolloverPath,
ReadonlyField,
ShrinkField,
} from '../shared_fields';

Expand Down Expand Up @@ -238,6 +239,7 @@ export const HotPhase: FunctionComponent = () => {
{<ForcemergeField phase="hot" />}
<ShrinkField phase="hot" />
{license.canUseSearchableSnapshot() && <SearchableSnapshotField phase="hot" />}
<ReadonlyField phase={'hot'} />
</>
)}
<SetPriorityInputField phase={hotProperty} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ export { SnapshotPoliciesField } from './snapshot_policies_field';
export { ShrinkField } from './shrink_field';

export { SearchableSnapshotField } from './searchable_snapshot_field';

export { ReadonlyField } from './readonly_field';
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiTextColor } from '@elastic/eui';
import { LearnMoreLink } from '../../learn_more_link';
import { ToggleFieldWithDescribedFormRow } from '../../described_form_row';

interface Props {
phase: 'hot' | 'warm';
}

export const ReadonlyField: React.FunctionComponent<Props> = ({ phase }) => {
return (
<ToggleFieldWithDescribedFormRow
title={
<h3>
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.readonlyTitle"
defaultMessage="Read only"
/>
</h3>
}
description={
<EuiTextColor color="subdued">
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.readonlyDescription"
defaultMessage="Enable to make the index and index metadata read only, disable to allow writes and metadata changes."
/>{' '}
<LearnMoreLink docPath="ilm-readonly.html" />
</EuiTextColor>
}
fullWidth
titleSize="xs"
switchProps={{
'data-test-subj': `${phase}-readonlySwitch`,
path: `_meta.${phase}.readonlyEnabled`,
}}
>
<div />
</ToggleFieldWithDescribedFormRow>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
SetPriorityInputField,
DataTierAllocationField,
ShrinkField,
ReadonlyField,
} from '../shared_fields';

const i18nTexts = {
Expand Down Expand Up @@ -173,6 +174,9 @@ export const WarmPhase: FunctionComponent = () => {
{!isUsingSearchableSnapshotInHotPhase && <ShrinkField phase="warm" />}

{!isUsingSearchableSnapshotInHotPhase && <ForcemergeField phase="warm" />}

<ReadonlyField phase={'warm'} />

{/* Data tier allocation section */}
<DataTierAllocationField
description={i18nTexts.dataTierAllocation.description}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ export const deserializer = (policy: SerializedPolicy): FormInternal => {
hot: {
useRollover: Boolean(hot?.actions?.rollover),
bestCompression: hot?.actions?.forcemerge?.index_codec === 'best_compression',
readonlyEnabled: Boolean(hot?.actions?.readonly),
},
warm: {
enabled: Boolean(warm),
warmPhaseOnRollover: warm === undefined ? true : Boolean(warm.min_age === '0ms'),
bestCompression: warm?.actions?.forcemerge?.index_codec === 'best_compression',
dataTierAllocationType: determineDataTierAllocationType(warm?.actions),
readonlyEnabled: Boolean(warm?.actions?.readonly),
},
cold: {
enabled: Boolean(cold),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const originalPolicy: SerializedPolicy = {
index_codec: 'best_compression',
max_num_segments: 22,
},
readonly: {},
set_priority: {
priority: 1,
},
Expand All @@ -63,6 +64,7 @@ const originalPolicy: SerializedPolicy = {
some: 'value',
},
},
readonly: {},
set_priority: {
priority: 10,
},
Expand Down Expand Up @@ -170,6 +172,22 @@ describe('deserializer and serializer', () => {
expect(result.phases.warm!.actions.forcemerge).toBeUndefined();
});

it('removes the readonly action if it is disabled in hot', () => {
formInternal._meta.hot.readonlyEnabled = false;

const result = serializer(formInternal);

expect(result.phases.hot!.actions.readonly).toBeUndefined();
});

it('removes the readonly action if it is disabled in warm', () => {
formInternal._meta.warm.readonlyEnabled = false;

const result = serializer(formInternal);

expect(result.phases.warm!.actions.readonly).toBeUndefined();
});

it('removes set priority if it is disabled in the form', () => {
delete formInternal.phases.hot!.actions.set_priority;
delete formInternal.phases.warm!.actions.set_priority;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export const schema: FormSchema<FormInternal> = {
label: i18nTexts.editPolicy.bestCompressionFieldLabel,
helpText: i18nTexts.editPolicy.bestCompressionFieldHelpText,
},
readonlyEnabled: {
defaultValue: false,
label: i18nTexts.editPolicy.readonlyEnabledFieldLabel,
},
},
warm: {
enabled: {
Expand Down Expand Up @@ -76,6 +80,10 @@ export const schema: FormSchema<FormInternal> = {
allocationNodeAttribute: {
label: i18nTexts.editPolicy.allocationNodeAttributeFieldLabel,
},
readonlyEnabled: {
defaultValue: false,
label: i18nTexts.editPolicy.readonlyEnabledFieldLabel,
},
},
cold: {
enabled: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,16 @@ export const createSerializer = (originalPolicy?: SerializedPolicy) => (
if (_meta.hot.bestCompression && hotPhaseActions.forcemerge) {
hotPhaseActions.forcemerge.index_codec = 'best_compression';
}

if (_meta.hot.readonlyEnabled) {
hotPhaseActions.readonly = hotPhaseActions.readonly ?? {};
} else {
delete hotPhaseActions.readonly;
}
} else {
delete hotPhaseActions.rollover;
delete hotPhaseActions.forcemerge;
delete hotPhaseActions.readonly;
}

if (!updatedPolicy.phases.hot!.actions?.set_priority) {
Expand Down Expand Up @@ -117,6 +124,12 @@ export const createSerializer = (originalPolicy?: SerializedPolicy) => (
warmPhase.actions.forcemerge!.index_codec = 'best_compression';
}

if (_meta.warm.readonlyEnabled) {
warmPhase.actions.readonly = warmPhase.actions.readonly ?? {};
} else {
delete warmPhase.actions.readonly;
}

if (!updatedPolicy.phases.warm?.actions?.set_priority) {
delete warmPhase.actions.set_priority;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const i18nTexts = {
forceMergeEnabledFieldLabel: i18n.translate('xpack.indexLifecycleMgmt.forcemerge.enableLabel', {
defaultMessage: 'Force merge data',
}),
readonlyEnabledFieldLabel: i18n.translate('xpack.indexLifecycleMgmt.readonlyFieldLabel', {
defaultMessage: 'Make index read only',
}),
maxNumSegmentsFieldLabel: i18n.translate(
'xpack.indexLifecycleMgmt.forceMerge.numberOfSegmentsLabel',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ interface HotPhaseMetaFields extends ForcemergeFields {
useRollover: boolean;
maxStorageSizeUnit?: string;
maxAgeUnit?: string;
readonlyEnabled: boolean;
}

interface WarmPhaseMetaFields extends DataAllocationMetaFields, MinAgeField, ForcemergeFields {
enabled: boolean;
warmPhaseOnRollover: boolean;
readonlyEnabled: boolean;
}

interface ColdPhaseMetaFields extends DataAllocationMetaFields, MinAgeField {
Expand Down

0 comments on commit 1f21fe7

Please sign in to comment.