Skip to content

Commit

Permalink
hide readonly action if downsample enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Sep 15, 2022
1 parent f014ca4 commit dd9947a
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { HttpSetup } from '@kbn/core/public';
import {
createDownsampleActions,
createReadonlyActions,
createRolloverActions,
createSavePolicyAction,
createTogglePhaseAction,
} from '../../helpers';
import { initTestBed } from '../init_test_bed';
import { AppServicesContext } from '../../../../public/types';

type SetupReturn = ReturnType<typeof setupDownsampleTestBed>;

export type DownsampleTestBed = SetupReturn extends Promise<infer U> ? U : SetupReturn;

export const setupDownsampleTestBed = async (
httpSetup: HttpSetup,
args?: {
appServicesContext?: Partial<AppServicesContext>;
}
) => {
const testBed = await initTestBed(httpSetup, args);

return {
...testBed,
actions: {
togglePhase: createTogglePhaseAction(testBed),
savePolicy: createSavePolicyAction(testBed),
...createRolloverActions(testBed),
hot: {
...createReadonlyActions(testBed, 'hot'),
...createDownsampleActions(testBed, 'hot'),
},
warm: {
...createReadonlyActions(testBed, 'warm'),
...createDownsampleActions(testBed, 'warm'),
},
cold: {
...createReadonlyActions(testBed, 'cold'),
...createDownsampleActions(testBed, 'cold'),
},
frozen: {},
},
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { act } from 'react-dom/test-utils';
import { setupEnvironment } from '../../helpers';
import { DownsampleTestBed, setupDownsampleTestBed } from './downsample.helpers';

describe('<EditPolicy /> downsample', () => {
let testBed: DownsampleTestBed;
const { httpSetup, httpRequestsMockHelpers } = setupEnvironment();

beforeEach(async () => {
httpRequestsMockHelpers.setDefaultResponses();

await act(async () => {
testBed = await setupDownsampleTestBed(httpSetup);
});

const { component } = testBed;
component.update();
});

test('enabling downsample in warm should hide readonly in warm and cold', async () => {
const { actions } = testBed;

await actions.togglePhase('warm');
await actions.togglePhase('cold');

expect(actions.warm.downsample.exists()).toBeTruthy();
expect(actions.warm.readonlyExists()).toBeTruthy();
expect(actions.cold.downsample.exists()).toBeTruthy();
expect(actions.cold.readonlyExists()).toBeTruthy();

await actions.warm.downsample.toggle();

expect(actions.warm.readonlyExists()).toBeFalsy();
expect(actions.cold.readonlyExists()).toBeFalsy();
});

test('enabling downsample in hot should hide readonly in hot', async () => {
const { actions } = testBed;
await actions.rollover.toggleDefault();

expect(actions.hot.downsample.exists()).toBeTruthy();
expect(actions.hot.readonlyExists()).toBeTruthy();

await actions.hot.downsample.toggle();
expect(actions.hot.readonlyExists()).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { HttpSetup } from '@kbn/core/public';
import {
createDownsampleActions,
createForceMergeActions,
createMinAgeActions,
createReadonlyActions,
Expand Down Expand Up @@ -41,16 +42,19 @@ export const setupSearchableSnapshotsTestBed = async (
...createSearchableSnapshotActions(testBed, 'hot'),
...createForceMergeActions(testBed, 'hot'),
...createShrinkActions(testBed, 'hot'),
...createDownsampleActions(testBed, 'hot'),
},
warm: {
...createForceMergeActions(testBed, 'warm'),
...createShrinkActions(testBed, 'warm'),
...createReadonlyActions(testBed, 'warm'),
...createDownsampleActions(testBed, 'warm'),
},
cold: {
...createMinAgeActions(testBed, 'cold'),
...createSearchableSnapshotActions(testBed, 'cold'),
...createReadonlyActions(testBed, 'cold'),
...createDownsampleActions(testBed, 'cold'),
},
frozen: {
...createMinAgeActions(testBed, 'frozen'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,21 @@ describe('<EditPolicy /> searchable snapshots', () => {
expect(actions.warm.forceMergeExists()).toBeTruthy();
expect(actions.warm.shrinkExists()).toBeTruthy();
expect(actions.warm.readonlyExists()).toBeTruthy();
expect(actions.warm.downsample.exists()).toBeTruthy();
expect(actions.cold.searchableSnapshotsExists()).toBeTruthy();
expect(actions.cold.readonlyExists()).toBeTruthy();
expect(actions.cold.downsample.exists()).toBeTruthy();

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

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

test('disabling rollover toggle, but enabling default rollover', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,25 @@ const i18nTexts = {
};

export const ColdPhase: FunctionComponent = () => {
const { isUsingSearchableSnapshotInHotPhase } = useConfiguration();
const {
isUsingSearchableSnapshotInHotPhase,
isUsingDownsampleInHotPhase,
isUsingDownsampleInWarmPhase,
isUsingDownsampleInColdPhase,
} = useConfiguration();

return (
<Phase phase="cold" topLevelSettings={<SearchableSnapshotField phase="cold" />}>
<ReplicasField phase="cold" />

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

{!isUsingSearchableSnapshotInHotPhase && <DownsampleField phase="cold" />}

{/* Readonly section */}
{!isUsingSearchableSnapshotInHotPhase &&
!isUsingDownsampleInHotPhase &&
!isUsingDownsampleInWarmPhase &&
!isUsingDownsampleInColdPhase && <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 @@ -49,7 +49,7 @@ export const HotPhase: FunctionComponent = () => {
const [formData] = useFormData({
watch: [isUsingDefaultRolloverPath, ...rolloverFieldPaths],
});
const { isUsingRollover } = useConfiguration();
const { isUsingRollover, isUsingDownsampleInHotPhase } = useConfiguration();
const isUsingDefaultRollover: boolean = get(formData, isUsingDefaultRolloverPath);

const showEmptyRolloverFieldsError = useRolloverValueRequiredValidation();
Expand Down Expand Up @@ -176,8 +176,8 @@ export const HotPhase: FunctionComponent = () => {
{<ForcemergeField phase={'hot'} />}
<ShrinkField phase={'hot'} />
{license.canUseSearchableSnapshot() && <SearchableSnapshotField phase="hot" />}
<ReadonlyField phase={'hot'} />
<DownsampleField phase="hot" />
{!isUsingDownsampleInHotPhase && <ReadonlyField phase={'hot'} />}
</>
)}
<IndexPriorityField phase={'hot'} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ const i18nTexts = {
};

export const WarmPhase: FunctionComponent = () => {
const { isUsingSearchableSnapshotInHotPhase } = useConfiguration();
const {
isUsingSearchableSnapshotInHotPhase,
isUsingDownsampleInHotPhase,
isUsingDownsampleInWarmPhase,
} = useConfiguration();

return (
<Phase phase="warm">
Expand All @@ -41,10 +45,12 @@ export const WarmPhase: FunctionComponent = () => {

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

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

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

{!isUsingSearchableSnapshotInHotPhase &&
!isUsingDownsampleInHotPhase &&
!isUsingDownsampleInWarmPhase && <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 @@ -6,11 +6,15 @@
*/

import { i18n } from '@kbn/i18n';
import { PhaseWithDownsample } from '../../../../common/types';

export const isUsingCustomRolloverPath = '_meta.hot.customRollover.enabled';

export const isUsingDefaultRolloverPath = '_meta.hot.isUsingDefaultRollover';

export const isUsingDownsamplePath = (phase: PhaseWithDownsample) =>
`_meta.${phase}.downsample.enabled`;

/**
* These strings describe the path to their respective values in the serialized
* ILM form.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import React, { FunctionComponent, createContext, useContext } from 'react';

import { useFormData } from '../../../../shared_imports';

import { isUsingDefaultRolloverPath, isUsingCustomRolloverPath } from '../constants';
import {
isUsingDefaultRolloverPath,
isUsingCustomRolloverPath,
isUsingDownsamplePath,
} from '../constants';

export interface Configuration {
/**
Expand All @@ -26,6 +30,14 @@ export interface Configuration {
*/
isUsingSearchableSnapshotInHotPhase: boolean;
isUsingSearchableSnapshotInColdPhase: boolean;

/**
* When downsample enabled it implicitly makes index readonly,
* We should hide readonly action if downsample is enabled
*/
isUsingDownsampleInHotPhase: boolean;
isUsingDownsampleInWarmPhase: boolean;
isUsingDownsampleInColdPhase: boolean;
}

const ConfigurationContext = createContext<Configuration>(null as any);
Expand All @@ -43,6 +55,9 @@ export const ConfigurationProvider: FunctionComponent = ({ children }) => {
pathToColdPhaseSearchableSnapshot,
isUsingCustomRolloverPath,
isUsingDefaultRolloverPath,
isUsingDownsamplePath('hot'),
isUsingDownsamplePath('warm'),
isUsingDownsamplePath('cold'),
],
});
const isUsingDefaultRollover = get(formData, isUsingDefaultRolloverPath);
Expand All @@ -53,6 +68,9 @@ export const ConfigurationProvider: FunctionComponent = ({ children }) => {
isUsingRollover: isUsingDefaultRollover === false ? isUsingCustomRollover : true,
isUsingSearchableSnapshotInHotPhase: get(formData, pathToHotPhaseSearchableSnapshot) != null,
isUsingSearchableSnapshotInColdPhase: get(formData, pathToColdPhaseSearchableSnapshot) != null,
isUsingDownsampleInHotPhase: !!get(formData, isUsingDownsamplePath('hot')),
isUsingDownsampleInWarmPhase: !!get(formData, isUsingDownsamplePath('warm')),
isUsingDownsampleInColdPhase: !!get(formData, isUsingDownsamplePath('cold')),
};

return <ConfigurationContext.Provider value={context}>{children}</ConfigurationContext.Provider>;
Expand Down

0 comments on commit dd9947a

Please sign in to comment.