Skip to content

Commit

Permalink
[ILM] Searchable snapshot default "enabled" on cloud (#88582)
Browse files Browse the repository at this point in the history
* default searchable snapshot to enabled on cloud when creating a new policy

* added test for searchable snapshot on new policy on cloud
  • Loading branch information
jloleysens authored Jan 19, 2021
1 parent 7c9b114 commit fbf600d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -700,33 +700,60 @@ describe('<EditPolicy />', () => {

describe('searchable snapshot', () => {
describe('on cloud', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]);
httpRequestsMockHelpers.setListNodes({
isUsingDeprecatedDataRoleConfig: false,
nodesByAttributes: { test: ['123'] },
nodesByRoles: { data: ['123'] },
});
httpRequestsMockHelpers.setListSnapshotRepos({ repositories: ['found-snapshots'] });
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 } } });
});
await act(async () => {
testBed = await setup({ appServicesContext: { cloud: { isCloudEnabled: true } } });
});

const { component } = testBed;
component.update();
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({
isUsingDeprecatedDataRoleConfig: false,
nodesByAttributes: { test: ['123'] },
nodesByRoles: { data: ['123'] },
});
httpRequestsMockHelpers.setListSnapshotRepos({ repositories: ['found-snapshots'] });

test('correctly sets snapshot repository default to "found-snapshots"', async () => {
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'
);
await act(async () => {
testBed = await setup({ appServicesContext: { cloud: { isCloudEnabled: true } } });
});

const { component } = testBed;
component.update();
});
test('correctly sets snapshot repository default to "found-snapshots"', async () => {
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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,28 @@ 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`;

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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
Expand Down

0 comments on commit fbf600d

Please sign in to comment.