Skip to content

Commit

Permalink
[ILM] Fix hot phase serialization (elastic#87213) (elastic#87707)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Jan 7, 2021
1 parent 3b723ce commit c006bc3
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const HotPhase: FunctionComponent = () => {
watch: isUsingDefaultRolloverPath,
});
const { isUsingRollover } = useConfigurationIssues();
const isUsingDefaultRollover = get(formData, isUsingDefaultRolloverPath);
const isUsingDefaultRollover: boolean = get(formData, isUsingDefaultRolloverPath);
const [showEmptyRolloverFieldsError, setShowEmptyRolloverFieldsError] = useState(false);

return (
Expand Down Expand Up @@ -145,145 +145,145 @@ export const HotPhase: FunctionComponent = () => {
}
fullWidth
>
<div
aria-live="polite"
role="region"
style={{ display: isUsingDefaultRollover === false ? undefined : 'none' }}
>
<UseField<boolean> path="_meta.hot.useRollover">
{(field) => (
<>
<EuiSwitch
label={field.label}
checked={field.value}
onChange={(e) => field.setValue(e.target.checked)}
data-test-subj="rolloverSwitch"
/>
&nbsp;
<EuiIconTip
type="questionInCircle"
content={
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.hotPhase.enableRolloverTipContent"
defaultMessage="Roll over to a new index when the
{isUsingDefaultRollover === false ? (
<div aria-live="polite" role="region">
<UseField<boolean> path="_meta.hot.customRollover.enabled">
{(field) => (
<>
<EuiSwitch
label={field.label}
checked={field.value}
onChange={(e) => field.setValue(e.target.checked)}
data-test-subj="rolloverSwitch"
/>
&nbsp;
<EuiIconTip
type="questionInCircle"
content={
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.hotPhase.enableRolloverTipContent"
defaultMessage="Roll over to a new index when the
current index meets one of the defined conditions."
/>
}
/>
</>
)}
</UseField>
{isUsingRollover && (
<>
<EuiSpacer size="m" />
{showEmptyRolloverFieldsError && (
<>
<EuiCallOut
title={i18nTexts.editPolicy.errors.rollOverConfigurationCallout.title}
data-test-subj="rolloverSettingsRequired"
color="danger"
>
<div>{i18nTexts.editPolicy.errors.rollOverConfigurationCallout.body}</div>
</EuiCallOut>
<EuiSpacer size="s" />
</>
)}
<EuiFlexGroup>
<EuiFlexItem style={{ maxWidth: 188 }}>
<UseField path={ROLLOVER_FORM_PATHS.maxSize}>
{(field) => {
const showErrorCallout = field.errors.some(
(e) => e.code === ROLLOVER_EMPTY_VALIDATION
);
if (showErrorCallout !== showEmptyRolloverFieldsError) {
setShowEmptyRolloverFieldsError(showErrorCallout);
}
return (
<NumericField
field={field}
euiFieldProps={{
'data-test-subj': `${hotProperty}-selectedMaxSizeStored`,
min: 1,
}}
/>
);
}}
</UseField>
</EuiFlexItem>
<EuiFlexItem style={{ maxWidth: 188 }}>
<UseField
key="_meta.hot.customRollover.maxStorageSizeUnit"
path="_meta.hot.customRollover.maxStorageSizeUnit"
component={SelectField}
componentProps={{
'data-test-subj': `${hotProperty}-selectedMaxSizeStoredUnits`,
hasEmptyLabelSpace: true,
euiFieldProps: {
options: maxSizeStoredUnits,
'aria-label': i18n.translate(
'xpack.indexLifecycleMgmt.hotPhase.maximumIndexSizeUnitsAriaLabel',
{
defaultMessage: 'Maximum index size units',
}
),
},
}}
/>
}
/>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer />
<EuiFlexGroup>
<EuiFlexItem style={{ maxWidth: 188 }}>
<UseField
path={ROLLOVER_FORM_PATHS.maxDocs}
component={NumericField}
componentProps={{
euiFieldProps: {
'data-test-subj': `${hotProperty}-selectedMaxDocuments`,
min: 1,
},
}}
/>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer />
<EuiFlexGroup>
<EuiFlexItem style={{ maxWidth: 188 }}>
<UseField
path={ROLLOVER_FORM_PATHS.maxAge}
component={NumericField}
componentProps={{
euiFieldProps: {
'data-test-subj': `${hotProperty}-selectedMaxAge`,
min: 1,
},
}}
/>
</EuiFlexItem>
<EuiFlexItem style={{ maxWidth: 188 }}>
<UseField
key="_meta.hot.customRollover.maxAgeUnit"
path="_meta.hot.customRollover.maxAgeUnit"
component={SelectField}
componentProps={{
'data-test-subj': `${hotProperty}-selectedMaxAgeUnits`,
hasEmptyLabelSpace: true,
euiFieldProps: {
'aria-label': i18n.translate(
'xpack.indexLifecycleMgmt.hotPhase.maximumAgeUnitsAriaLabel',
{
defaultMessage: 'Maximum age units',
}
),
options: maxAgeUnits,
},
}}
/>
</EuiFlexItem>
</EuiFlexGroup>
</>
)}
</UseField>
{isUsingRollover && (
<>
<EuiSpacer size="m" />
{showEmptyRolloverFieldsError && (
<>
<EuiCallOut
title={i18nTexts.editPolicy.errors.rollOverConfigurationCallout.title}
data-test-subj="rolloverSettingsRequired"
color="danger"
>
<div>{i18nTexts.editPolicy.errors.rollOverConfigurationCallout.body}</div>
</EuiCallOut>
<EuiSpacer size="s" />
</>
)}
<EuiFlexGroup>
<EuiFlexItem style={{ maxWidth: 188 }}>
<UseField path={ROLLOVER_FORM_PATHS.maxSize}>
{(field) => {
const showErrorCallout = field.errors.some(
(e) => e.code === ROLLOVER_EMPTY_VALIDATION
);
if (showErrorCallout !== showEmptyRolloverFieldsError) {
setShowEmptyRolloverFieldsError(showErrorCallout);
}
return (
<NumericField
field={field}
euiFieldProps={{
'data-test-subj': `${hotProperty}-selectedMaxSizeStored`,
min: 1,
}}
/>
);
}}
</UseField>
</EuiFlexItem>
<EuiFlexItem style={{ maxWidth: 188 }}>
<UseField
key="_meta.hot.maxStorageSizeUnit"
path="_meta.hot.maxStorageSizeUnit"
component={SelectField}
componentProps={{
'data-test-subj': `${hotProperty}-selectedMaxSizeStoredUnits`,
hasEmptyLabelSpace: true,
euiFieldProps: {
options: maxSizeStoredUnits,
'aria-label': i18n.translate(
'xpack.indexLifecycleMgmt.hotPhase.maximumIndexSizeUnitsAriaLabel',
{
defaultMessage: 'Maximum index size units',
}
),
},
}}
/>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer />
<EuiFlexGroup>
<EuiFlexItem style={{ maxWidth: 188 }}>
<UseField
path={ROLLOVER_FORM_PATHS.maxDocs}
component={NumericField}
componentProps={{
euiFieldProps: {
'data-test-subj': `${hotProperty}-selectedMaxDocuments`,
min: 1,
},
}}
/>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer />
<EuiFlexGroup>
<EuiFlexItem style={{ maxWidth: 188 }}>
<UseField
path={ROLLOVER_FORM_PATHS.maxAge}
component={NumericField}
componentProps={{
euiFieldProps: {
'data-test-subj': `${hotProperty}-selectedMaxAge`,
min: 1,
},
}}
/>
</EuiFlexItem>
<EuiFlexItem style={{ maxWidth: 188 }}>
<UseField
key="_meta.hot.maxAgeUnit"
path="_meta.hot.maxAgeUnit"
component={SelectField}
componentProps={{
'data-test-subj': `${hotProperty}-selectedMaxAgeUnits`,
hasEmptyLabelSpace: true,
euiFieldProps: {
'aria-label': i18n.translate(
'xpack.indexLifecycleMgmt.hotPhase.maximumAgeUnitsAriaLabel',
{
defaultMessage: 'Maximum age units',
}
),
options: maxAgeUnits,
},
}}
/>
</EuiFlexItem>
</EuiFlexGroup>
</>
)}
</div>
</div>
) : (
<div />
)}
</DescribedFormRow>
{isUsingRollover && (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const useRolloverPath = '_meta.hot.useRollover';
export const isUsingCustomRolloverPath = '_meta.hot.customRollover.enabled';

export const isUsingDefaultRolloverPath = '_meta.hot.isUsingDefaultRollover';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { FunctionComponent, createContext, useContext } from 'react';

import { useFormData } from '../../../../shared_imports';

import { isUsingDefaultRolloverPath, useRolloverPath } from '../constants';
import { isUsingDefaultRolloverPath, isUsingCustomRolloverPath } from '../constants';

export interface ConfigurationIssues {
/**
Expand All @@ -33,14 +33,20 @@ const pathToHotPhaseSearchableSnapshot =

export const ConfigurationIssuesProvider: FunctionComponent = ({ children }) => {
const [formData] = useFormData({
watch: [pathToHotPhaseSearchableSnapshot, useRolloverPath, isUsingDefaultRolloverPath],
watch: [
pathToHotPhaseSearchableSnapshot,
isUsingCustomRolloverPath,
isUsingDefaultRolloverPath,
],
});
const isUsingDefaultRollover = get(formData, isUsingDefaultRolloverPath);
const rolloverSwitchEnabled = get(formData, useRolloverPath);
// Provide default value, as path may become undefined if removed from the DOM
const isUsingCustomRollover = get(formData, isUsingCustomRolloverPath, true);

return (
<ConfigurationIssuesContext.Provider
value={{
isUsingRollover: isUsingDefaultRollover === false ? rolloverSwitchEnabled : true,
isUsingRollover: isUsingDefaultRollover === false ? isUsingCustomRollover : true,
isUsingSearchableSnapshotInHotPhase:
get(formData, pathToHotPhaseSearchableSnapshot) != null,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export const deserializer = (policy: SerializedPolicy): FormInternal => {

const _meta: FormInternal['_meta'] = {
hot: {
useRollover: Boolean(hot?.actions?.rollover),
isUsingDefaultRollover: isUsingDefaultRollover(policy),
customRollover: {
enabled: Boolean(hot?.actions?.rollover),
},
bestCompression: hot?.actions?.forcemerge?.index_codec === 'best_compression',
readonlyEnabled: Boolean(hot?.actions?.readonly),
},
Expand Down Expand Up @@ -53,13 +55,13 @@ export const deserializer = (policy: SerializedPolicy): FormInternal => {
if (draft.phases.hot.actions.rollover.max_size) {
const maxSize = splitSizeAndUnits(draft.phases.hot.actions.rollover.max_size);
draft.phases.hot.actions.rollover.max_size = maxSize.size;
draft._meta.hot.maxStorageSizeUnit = maxSize.units;
draft._meta.hot.customRollover.maxStorageSizeUnit = maxSize.units;
}

if (draft.phases.hot.actions.rollover.max_age) {
const maxAge = splitSizeAndUnits(draft.phases.hot.actions.rollover.max_age);
draft.phases.hot.actions.rollover.max_age = maxAge.size;
draft._meta.hot.maxAgeUnit = maxAge.units;
draft._meta.hot.customRollover.maxAgeUnit = maxAge.units;
}
}

Expand Down
Loading

0 comments on commit c006bc3

Please sign in to comment.