Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [ILM] Searchable snapshot default "enabled" on cloud (#88582) #88683

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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