Skip to content

Commit

Permalink
Added readonly action in cold phase (#96036)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
yuliacech and kibanamachine authored Apr 7, 2021
1 parent 98fdf7f commit 011b234
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ export const setup = async (arg?: {
setReplicas: setReplicas('cold'),
setFreeze: createSetFreeze('cold'),
freezeExists: createFreezeExists('cold'),
...createReadonlyActions('cold'),
hasErrorIndicator: () => exists('phaseErrorIndicator-cold'),
...createIndexPriorityActions('cold'),
...createSearchableSnapshotActions('cold'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,28 @@ describe('<EditPolicy /> searchable snapshots', () => {
component.update();
});

test('enabling searchable snapshot should hide force merge, freeze and shrink in subsequent phases', async () => {
test('enabling searchable snapshot should hide force merge, freeze, readonly and shrink in subsequent phases', async () => {
const { actions } = testBed;

await actions.warm.enable(true);
await actions.cold.enable(true);

expect(actions.warm.forceMergeFieldExists()).toBeTruthy();
expect(actions.warm.shrinkExists()).toBeTruthy();
expect(actions.warm.readonlyExists()).toBeTruthy();
expect(actions.cold.searchableSnapshotsExists()).toBeTruthy();
expect(actions.cold.freezeExists()).toBeTruthy();
expect(actions.cold.readonlyExists()).toBeTruthy();

await actions.hot.setSearchableSnapshot('my-repo');

expect(actions.warm.forceMergeFieldExists()).toBeFalsy();
expect(actions.warm.shrinkExists()).toBeFalsy();
expect(actions.warm.readonlyExists()).toBeFalsy();
// searchable snapshot in cold is still visible
expect(actions.cold.searchableSnapshotsExists()).toBeTruthy();
expect(actions.cold.freezeExists()).toBeFalsy();
expect(actions.cold.readonlyExists()).toBeFalsy();
});

test('disabling rollover toggle, but enabling default rollover', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ describe('<EditPolicy /> serialization', () => {
await actions.cold.setSelectedNodeAttribute('test:123');
await actions.cold.setReplicas('123');
await actions.cold.setFreeze(true);
await actions.cold.toggleReadonly(true);
await actions.cold.setIndexPriority('123');

await actions.savePolicy();
Expand All @@ -445,6 +446,7 @@ describe('<EditPolicy /> serialization', () => {
},
},
"freeze": Object {},
"readonly": Object {},
"set_priority": Object {
"priority": 123,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export interface SerializedWarmPhase extends SerializedPhase {
export interface SerializedColdPhase extends SerializedPhase {
actions: {
freeze?: {};
readonly?: {};
allocate?: AllocateAction;
set_priority?: {
priority: number | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
IndexPriorityField,
ReplicasField,
FreezeField,
ReadonlyField,
} from '../shared_fields';

import { Phase } from '../phase';
Expand All @@ -38,6 +39,9 @@ export const ColdPhase: FunctionComponent = () => {
{/* Freeze section */}
{!isUsingSearchableSnapshotInHotPhase && <FreezeField phase="cold" />}

{/* Readonly section */}
{!isUsingSearchableSnapshotInHotPhase && <ReadonlyField phase="cold" />}

{/* Data tier allocation section */}
<DataTierAllocationField
description={i18nTexts.dataTierAllocation.description}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { LearnMoreLink } from '../../learn_more_link';
import { ToggleFieldWithDescribedFormRow } from '../../described_form_row';

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

export const ReadonlyField: React.FunctionComponent<Props> = ({ phase }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({
'xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotCalloutBody',
{
defaultMessage:
'Force merge, shrink and freeze actions are not allowed when searchable snapshots are enabled in this phase.',
'Force merge, shrink, read only and freeze actions are not allowed when searchable snapshots are enabled in this phase.',
}
)}
data-test-subj="searchableSnapshotFieldsDisabledCallout"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const WarmPhase: FunctionComponent = () => {

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

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

{/* Data tier allocation section */}
<DataTierAllocationField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const createDeserializer = (isCloudEnabled: boolean) => (
enabled: Boolean(cold),
dataTierAllocationType: determineDataTierAllocationType(cold?.actions),
freezeEnabled: Boolean(cold?.actions?.freeze),
readonlyEnabled: Boolean(cold?.actions?.readonly),
},
frozen: {
enabled: Boolean(frozen),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const originalPolicy: SerializedPolicy = {
exclude: { test: 'my_value' },
},
freeze: {},
readonly: {},
set_priority: {
priority: 12,
},
Expand Down Expand Up @@ -206,6 +207,14 @@ describe('deserializer and serializer', () => {
expect(result.phases.warm!.actions.readonly).toBeUndefined();
});

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

const result = serializer(formInternal);

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

it('allows force merge and readonly actions to be configured in hot with default rollover enabled', () => {
formInternal._meta.hot.isUsingDefaultRollover = true;
formInternal._meta.hot.bestCompression = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ export const getSchema = (isCloudEnabled: boolean): FormSchema => ({
defaultMessage: 'Freeze index',
}),
},
readonlyEnabled: {
defaultValue: false,
label: i18nTexts.editPolicy.readonlyEnabledFieldLabel,
},
minAgeUnit: {
defaultValue: 'd',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ export const createSerializer = (originalPolicy?: SerializedPolicy) => (
delete coldPhase.actions.freeze;
}

/**
* COLD PHASE READ ONLY
*/
if (_meta.cold.readonlyEnabled) {
coldPhase.actions.readonly = coldPhase.actions.readonly ?? {};
} else {
delete coldPhase.actions.readonly;
}

/**
* COLD PHASE SET PRIORITY
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface WarmPhaseMetaFields extends DataAllocationMetaFields, MinAgeField, For
interface ColdPhaseMetaFields extends DataAllocationMetaFields, MinAgeField {
enabled: boolean;
freezeEnabled: boolean;
readonlyEnabled: boolean;
}

interface FrozenPhaseMetaFields extends DataAllocationMetaFields, MinAgeField {
Expand Down

0 comments on commit 011b234

Please sign in to comment.