[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,33 +700,60 @@ describe('<EditPolicy />', () => {
|
||||||
|
|
||||||
describe('searchable snapshot', () => {
|
describe('searchable snapshot', () => {
|
||||||
describe('on cloud', () => {
|
describe('on cloud', () => {
|
||||||
beforeEach(async () => {
|
describe('new policy', () => {
|
||||||
httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]);
|
beforeEach(async () => {
|
||||||
httpRequestsMockHelpers.setListNodes({
|
// simulate creating a new policy
|
||||||
isUsingDeprecatedDataRoleConfig: false,
|
httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('')]);
|
||||||
nodesByAttributes: { test: ['123'] },
|
httpRequestsMockHelpers.setListNodes({
|
||||||
nodesByRoles: { data: ['123'] },
|
isUsingDeprecatedDataRoleConfig: false,
|
||||||
});
|
nodesByAttributes: { test: ['123'] },
|
||||||
httpRequestsMockHelpers.setListSnapshotRepos({ repositories: ['found-snapshots'] });
|
nodesByRoles: { data: ['123'] },
|
||||||
|
});
|
||||||
|
httpRequestsMockHelpers.setListSnapshotRepos({ repositories: ['found-snapshots'] });
|
||||||
|
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
testBed = await setup({ appServicesContext: { cloud: { isCloudEnabled: true } } });
|
testBed = await setup({ appServicesContext: { cloud: { isCloudEnabled: true } } });
|
||||||
});
|
});
|
||||||
|
|
||||||
const { component } = testBed;
|
const { component } = testBed;
|
||||||
component.update();
|
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({
|
||||||
|
isUsingDeprecatedDataRoleConfig: false,
|
||||||
|
nodesByAttributes: { test: ['123'] },
|
||||||
|
nodesByRoles: { data: ['123'] },
|
||||||
|
});
|
||||||
|
httpRequestsMockHelpers.setListSnapshotRepos({ repositories: ['found-snapshots'] });
|
||||||
|
|
||||||
test('correctly sets snapshot repository default to "found-snapshots"', async () => {
|
await act(async () => {
|
||||||
const { actions } = testBed;
|
testBed = await setup({ appServicesContext: { cloud: { isCloudEnabled: true } } });
|
||||||
await actions.cold.enable(true);
|
});
|
||||||
await actions.cold.toggleSearchableSnapshot(true);
|
|
||||||
await actions.savePolicy();
|
const { component } = testBed;
|
||||||
const latestRequest = server.requests[server.requests.length - 1];
|
component.update();
|
||||||
const request = JSON.parse(JSON.parse(latestRequest.requestBody).body);
|
});
|
||||||
expect(request.phases.cold.actions.searchable_snapshot.snapshot_repository).toEqual(
|
test('correctly sets snapshot repository default to "found-snapshots"', async () => {
|
||||||
'found-snapshots'
|
const { actions } = testBed;
|
||||||
);
|
await actions.cold.enable(true);
|
||||||
|
await actions.cold.toggleSearchableSnapshot(true);
|
||||||
|
await actions.savePolicy();
|
||||||
|
const latestRequest = server.requests[server.requests.length - 1];
|
||||||
|
const request = JSON.parse(JSON.parse(latestRequest.requestBody).body);
|
||||||
|
expect(request.phases.cold.actions.searchable_snapshot.snapshot_repository).toEqual(
|
||||||
|
'found-snapshots'
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('on non-enterprise license', () => {
|
describe('on non-enterprise license', () => {
|
||||||
|
|
|
@ -51,7 +51,7 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
|
||||||
const {
|
const {
|
||||||
services: { cloud },
|
services: { cloud },
|
||||||
} = useKibana();
|
} = useKibana();
|
||||||
const { getUrlForApp, policy, license } = useEditPolicyContext();
|
const { getUrlForApp, policy, license, isNewPolicy } = useEditPolicyContext();
|
||||||
const { isUsingSearchableSnapshotInHotPhase, isUsingRollover } = useConfigurationIssues();
|
const { isUsingSearchableSnapshotInHotPhase, isUsingRollover } = useConfigurationIssues();
|
||||||
|
|
||||||
const searchableSnapshotPath = `phases.${phase}.actions.searchable_snapshot.snapshot_repository`;
|
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 [formData] = useFormData({ watch: searchableSnapshotPath });
|
||||||
const searchableSnapshotRepo = get(formData, searchableSnapshotPath);
|
const searchableSnapshotRepo = get(formData, searchableSnapshotPath);
|
||||||
|
|
||||||
|
const isColdPhase = phase === 'cold';
|
||||||
const isDisabledDueToLicense = !license.canUseSearchableSnapshot();
|
const isDisabledDueToLicense = !license.canUseSearchableSnapshot();
|
||||||
const isDisabledInColdDueToHotPhase = phase === 'cold' && isUsingSearchableSnapshotInHotPhase;
|
const isDisabledInColdDueToHotPhase = isColdPhase && isUsingSearchableSnapshotInHotPhase;
|
||||||
const isDisabledInColdDueToRollover = phase === 'cold' && !isUsingRollover;
|
const isDisabledInColdDueToRollover = isColdPhase && !isUsingRollover;
|
||||||
|
|
||||||
const isDisabled =
|
const isDisabled =
|
||||||
isDisabledDueToLicense || isDisabledInColdDueToHotPhase || isDisabledInColdDueToRollover;
|
isDisabledDueToLicense || isDisabledInColdDueToHotPhase || isDisabledInColdDueToRollover;
|
||||||
|
|
||||||
const [isFieldToggleChecked, setIsFieldToggleChecked] = useState(() =>
|
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(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -32,7 +32,7 @@ export const EditPolicyContextProvider = ({
|
||||||
return <EditPolicyContext.Provider value={value}>{children}</EditPolicyContext.Provider>;
|
return <EditPolicyContext.Provider value={value}>{children}</EditPolicyContext.Provider>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useEditPolicyContext = () => {
|
export const useEditPolicyContext = (): EditPolicyContextValue => {
|
||||||
const ctx = useContext(EditPolicyContext);
|
const ctx = useContext(EditPolicyContext);
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
throw new Error('useEditPolicyContext can only be called inside of EditPolicyContext!');
|
throw new Error('useEditPolicyContext can only be called inside of EditPolicyContext!');
|
||||||
|
|
Loading…
Reference in a new issue