[ILM] Searchable snapshot default "enabled" on cloud (#88582)
* default searchable snapshot to enabled on cloud when creating a new policy * added test for searchable snapshot on new policy on cloud
This commit is contained in:
parent
7c9b11476d
commit
fbf600d7fc
|
@ -700,6 +700,33 @@ describe('<EditPolicy />', () => {
|
|||
|
||||
describe('searchable snapshot', () => {
|
||||
describe('on cloud', () => {
|
||||
describe('new policy', () => {
|
||||
beforeEach(async () => {
|
||||
// simulate creating a new policy
|
||||
httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('')]);
|
||||
httpRequestsMockHelpers.setListNodes({
|
||||
isUsingDeprecatedDataRoleConfig: false,
|
||||
nodesByAttributes: { test: ['123'] },
|
||||
nodesByRoles: { data: ['123'] },
|
||||
});
|
||||
httpRequestsMockHelpers.setListSnapshotRepos({ repositories: ['found-snapshots'] });
|
||||
|
||||
await act(async () => {
|
||||
testBed = await setup({ appServicesContext: { cloud: { isCloudEnabled: true } } });
|
||||
});
|
||||
|
||||
const { component } = testBed;
|
||||
component.update();
|
||||
});
|
||||
test('defaults searchable snapshot to true on cloud', async () => {
|
||||
const { find, actions } = testBed;
|
||||
await actions.cold.enable(true);
|
||||
expect(
|
||||
find('searchableSnapshotField-cold.searchableSnapshotToggle').props()['aria-checked']
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
describe('existing policy', () => {
|
||||
beforeEach(async () => {
|
||||
httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]);
|
||||
httpRequestsMockHelpers.setListNodes({
|
||||
|
@ -716,7 +743,6 @@ describe('<EditPolicy />', () => {
|
|||
const { component } = testBed;
|
||||
component.update();
|
||||
});
|
||||
|
||||
test('correctly sets snapshot repository default to "found-snapshots"', async () => {
|
||||
const { actions } = testBed;
|
||||
await actions.cold.enable(true);
|
||||
|
@ -729,6 +755,7 @@ describe('<EditPolicy />', () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('on non-enterprise license', () => {
|
||||
beforeEach(async () => {
|
||||
httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]);
|
||||
|
|
|
@ -51,7 +51,7 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
|
|||
const {
|
||||
services: { cloud },
|
||||
} = useKibana();
|
||||
const { getUrlForApp, policy, license } = useEditPolicyContext();
|
||||
const { getUrlForApp, policy, license, isNewPolicy } = useEditPolicyContext();
|
||||
const { isUsingSearchableSnapshotInHotPhase, isUsingRollover } = useConfigurationIssues();
|
||||
|
||||
const searchableSnapshotPath = `phases.${phase}.actions.searchable_snapshot.snapshot_repository`;
|
||||
|
@ -59,15 +59,20 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
|
|||
const [formData] = useFormData({ watch: searchableSnapshotPath });
|
||||
const searchableSnapshotRepo = get(formData, searchableSnapshotPath);
|
||||
|
||||
const isColdPhase = phase === 'cold';
|
||||
const isDisabledDueToLicense = !license.canUseSearchableSnapshot();
|
||||
const isDisabledInColdDueToHotPhase = phase === 'cold' && isUsingSearchableSnapshotInHotPhase;
|
||||
const isDisabledInColdDueToRollover = phase === 'cold' && !isUsingRollover;
|
||||
const isDisabledInColdDueToHotPhase = isColdPhase && isUsingSearchableSnapshotInHotPhase;
|
||||
const isDisabledInColdDueToRollover = isColdPhase && !isUsingRollover;
|
||||
|
||||
const isDisabled =
|
||||
isDisabledDueToLicense || isDisabledInColdDueToHotPhase || isDisabledInColdDueToRollover;
|
||||
|
||||
const [isFieldToggleChecked, setIsFieldToggleChecked] = useState(() =>
|
||||
Boolean(policy.phases[phase]?.actions?.searchable_snapshot?.snapshot_repository)
|
||||
Boolean(
|
||||
// New policy on cloud should have searchable snapshot on in cold phase
|
||||
(isColdPhase && isNewPolicy && cloud?.isCloudEnabled) ||
|
||||
policy.phases[phase]?.actions?.searchable_snapshot?.snapshot_repository
|
||||
)
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
@ -32,7 +32,7 @@ export const EditPolicyContextProvider = ({
|
|||
return <EditPolicyContext.Provider value={value}>{children}</EditPolicyContext.Provider>;
|
||||
};
|
||||
|
||||
export const useEditPolicyContext = () => {
|
||||
export const useEditPolicyContext = (): EditPolicyContextValue => {
|
||||
const ctx = useContext(EditPolicyContext);
|
||||
if (!ctx) {
|
||||
throw new Error('useEditPolicyContext can only be called inside of EditPolicyContext!');
|
||||
|
|
Loading…
Reference in a new issue