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

[ILM] Show forcemerge in hot when rollover is searchable snapshot is enabled #85292

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 @@ -324,7 +324,7 @@ describe('edit policy', () => {
});
});
describe('hot phase', () => {
test('should show errors when trying to save with no max size and no max age', async () => {
test('should show errors when trying to save with no max size, no max age and no max docs', async () => {
const rendered = mountWithIntl(component);
expect(findTestSubject(rendered, 'rolloverSettingsRequired').exists()).toBeFalsy();
await setPolicyName(rendered, 'mypolicy');
Expand All @@ -338,6 +338,11 @@ describe('edit policy', () => {
maxAgeInput.simulate('change', { target: { value: '' } });
});
waitForFormLibValidation(rendered);
const maxDocsInput = findTestSubject(rendered, 'hot-selectedMaxDocuments');
await act(async () => {
maxDocsInput.simulate('change', { target: { value: '' } });
});
waitForFormLibValidation(rendered);
await save(rendered);
expect(findTestSubject(rendered, 'rolloverSettingsRequired').exists()).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useFormData, UseField, SelectField, NumericField } from '../../../../..

import { i18nTexts } from '../../../i18n_texts';

import { ROLLOVER_EMPTY_VALIDATION, useConfigurationIssues } from '../../../form';
import { ROLLOVER_EMPTY_VALIDATION } from '../../../form';

import { useEditPolicyContext } from '../../../edit_policy_context';

Expand All @@ -51,8 +51,6 @@ export const HotPhase: FunctionComponent = () => {
const isRolloverEnabled = get(formData, useRolloverPath);
const [showEmptyRolloverFieldsError, setShowEmptyRolloverFieldsError] = useState(false);

const { isUsingSearchableSnapshotInHotPhase } = useConfigurationIssues();

return (
<>
<EuiDescribedFormGroup
Expand Down Expand Up @@ -143,7 +141,7 @@ export const HotPhase: FunctionComponent = () => {
<UseField path={ROLLOVER_FORM_PATHS.maxSize}>
{(field) => {
const showErrorCallout = field.errors.some(
(e) => e.validationType === ROLLOVER_EMPTY_VALIDATION
(e) => e.code === ROLLOVER_EMPTY_VALIDATION
);
if (showErrorCallout !== showEmptyRolloverFieldsError) {
setShowEmptyRolloverFieldsError(showErrorCallout);
Expand Down Expand Up @@ -236,8 +234,8 @@ export const HotPhase: FunctionComponent = () => {
</ToggleFieldWithDescribedFormRow>
{isRolloverEnabled && (
<>
{<ForcemergeField phase="hot" />}
{license.canUseSearchableSnapshot() && <SearchableSnapshotField phase="hot" />}
{!isUsingSearchableSnapshotInHotPhase && <ForcemergeField phase="hot" />}
</>
)}
<SetPriorityInputField phase={hotProperty} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { i18n } from '@kbn/i18n';

import { FormSchema, fieldValidators } from '../../../../shared_imports';
import { defaultSetPriority, defaultPhaseIndexPriority } from '../../../constants';
import { ROLLOVER_FORM_PATHS } from '../constants';

const rolloverFormPaths = Object.values(ROLLOVER_FORM_PATHS);

import { FormInternal } from '../types';

Expand Down Expand Up @@ -127,6 +130,7 @@ export const schema: FormSchema<FormInternal> = {
validator: ifExistsNumberGreaterThanZero,
},
],
fieldsToValidateOnChange: rolloverFormPaths,
},
max_docs: {
label: i18n.translate('xpack.indexLifecycleMgmt.hotPhase.maximumDocumentsLabel', {
Expand All @@ -141,6 +145,7 @@ export const schema: FormSchema<FormInternal> = {
},
],
serializer: serializers.stringToNumber,
fieldsToValidateOnChange: rolloverFormPaths,
},
max_size: {
label: i18n.translate('xpack.indexLifecycleMgmt.hotPhase.maximumIndexSizeLabel', {
Expand All @@ -154,6 +159,7 @@ export const schema: FormSchema<FormInternal> = {
validator: ifExistsNumberGreaterThanZero,
},
],
fieldsToValidateOnChange: rolloverFormPaths,
},
},
forcemerge: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,31 @@ export const ROLLOVER_EMPTY_VALIDATION = 'ROLLOVER_EMPTY_VALIDATION';
* This validator checks that and updates form values by setting errors states imperatively to
* indicate this error state.
*/
export const rolloverThresholdsValidator: ValidationFunc = ({ form }) => {
export const rolloverThresholdsValidator: ValidationFunc = ({ form, path }) => {
const fields = form.getFields();
if (
!(
fields[ROLLOVER_FORM_PATHS.maxAge].value ||
fields[ROLLOVER_FORM_PATHS.maxDocs].value ||
fields[ROLLOVER_FORM_PATHS.maxSize].value
fields[ROLLOVER_FORM_PATHS.maxAge]?.value ||
fields[ROLLOVER_FORM_PATHS.maxDocs]?.value ||
fields[ROLLOVER_FORM_PATHS.maxSize]?.value
)
) {
fields[ROLLOVER_FORM_PATHS.maxAge].setErrors([
{
validationType: ROLLOVER_EMPTY_VALIDATION,
if (path === ROLLOVER_FORM_PATHS.maxAge) {
return {
code: ROLLOVER_EMPTY_VALIDATION,
message: i18nTexts.editPolicy.errors.maximumAgeRequiredMessage,
},
]);
fields[ROLLOVER_FORM_PATHS.maxDocs].setErrors([
{
validationType: ROLLOVER_EMPTY_VALIDATION,
};
} else if (path === ROLLOVER_FORM_PATHS.maxDocs) {
return {
code: ROLLOVER_EMPTY_VALIDATION,
message: i18nTexts.editPolicy.errors.maximumDocumentsRequiredMessage,
},
]);
fields[ROLLOVER_FORM_PATHS.maxSize].setErrors([
{
validationType: ROLLOVER_EMPTY_VALIDATION,
};
} else {
return {
code: ROLLOVER_EMPTY_VALIDATION,
message: i18nTexts.editPolicy.errors.maximumSizeRequiredMessage,
},
]);
};
}
} else {
fields[ROLLOVER_FORM_PATHS.maxAge].clearErrors(ROLLOVER_EMPTY_VALIDATION);
fields[ROLLOVER_FORM_PATHS.maxDocs].clearErrors(ROLLOVER_EMPTY_VALIDATION);
Expand Down