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] Allow multiple searchable snapshot actions #92789

Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ interface ParsedError {
cause: string[];
}

const getCause = (obj: any = {}, causes: string[] = []): string[] => {
export const getEsCause = (obj: any = {}, causes: string[] = []): string[] => {
const updated = [...causes];

if (obj.caused_by) {
updated.push(obj.caused_by.reason);

// Recursively find all the "caused by" reasons
return getCause(obj.caused_by, updated);
return getEsCause(obj.caused_by, updated);
}

return updated.filter(Boolean);
Expand All @@ -27,7 +27,7 @@ const getCause = (obj: any = {}, causes: string[] = []): string[] => {
export const parseEsError = (err: string): ParsedError => {
try {
const { error } = JSON.parse(err);
const cause = getCause(error);
const cause = getEsCause(error);
return {
message: error.reason,
cause,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { ApiError } from '@elastic/elasticsearch';
import { ResponseError } from '@elastic/elasticsearch/lib/errors';
import { IKibanaResponse, KibanaResponseFactory } from 'kibana/server';
import { getEsCause } from './es_error_parser';

interface EsErrorHandlerParams {
error: ApiError;
Expand All @@ -34,7 +35,15 @@ export const handleEsError = ({
const { statusCode, body } = error as ResponseError;
return response.customError({
statusCode,
body: { message: body.error?.reason },
body: {
message: body.error?.reason,
attributes: {
// The full original ES error object
error: body.error,
// We assume that this is an ES error object with a nested caused by chain if we can see the "caused_by" field at the top-level
causes: body.error?.caused_by ? getEsCause(body.error) : undefined,
},
},
});
}
// Case: default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>

const isColdPhase = phase === 'cold';
const isDisabledDueToLicense = !license.canUseSearchableSnapshot();
const isDisabledInColdDueToHotPhase = isColdPhase && isUsingSearchableSnapshotInHotPhase;

const isDisabled = isDisabledDueToLicense || isDisabledInColdDueToHotPhase;

const [isFieldToggleChecked, setIsFieldToggleChecked] = useState(() =>
Boolean(
Expand All @@ -74,10 +71,10 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
);

useEffect(() => {
if (isDisabled) {
if (isDisabledDueToLicense) {
setIsFieldToggleChecked(false);
}
}, [isDisabled]);
}, [isDisabledDueToLicense]);

const renderField = () => (
<SearchableSnapshotDataProvider>
Expand Down Expand Up @@ -254,7 +251,7 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
'xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotCalloutBody',
{
defaultMessage:
'Force merge, shrink, freeze and cold phase searchable snapshots are not allowed when searchable snapshots are enabled in the hot phase.',
'Force merge, shrink and freeze actions are not allowed when searchable snapshots are enabled in this phase.',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this message needs to be a bit different (maybe the validation too?) eg. shrinking in warm would not be allowed if searchable_snapshot is configured in hot (these actions are not allowed to follow searchable_snapshot, irrespective if they're configured in the same phase or a later phase)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, at the moment the form hides force merge, shrink and freeze only in subsequent phases to hot because in hot searchable snapshot is the last action:

https://github.com/elastic/elasticsearch/blob/fe6f50e121807692b3a84695687cb1ed1176ea63/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java#L69

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But perhaps we need to slightly re-word to state that more clearly, force merge etc. are not allowed in subsequent phases. I might be misunderstanding you so let me know what you think :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! Makes sense, thanks @jloleysens! (when the frozen tier comes to life we'll need to adjust this message and the validation - as the cold phase searchable_snapshot can precede the frozen phase actions)

}
)}
data-test-subj="searchableSnapshotFieldsDisabledCallout"
Expand All @@ -278,20 +275,6 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
)}
</EuiCallOut>
);
} else if (isDisabledInColdDueToHotPhase) {
infoCallout = (
<EuiCallOut
size="s"
data-test-subj="searchableSnapshotFieldsEnabledInHotCallout"
title={i18n.translate(
'xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotDisabledCalloutBody',
{
defaultMessage:
'Cannot create a searchable snapshot in cold when it is configured in hot phase.',
}
)}
/>
);
}

return infoCallout ? (
Expand All @@ -308,7 +291,7 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
data-test-subj={`searchableSnapshotField-${phase}`}
switchProps={{
checked: isFieldToggleChecked,
disabled: isDisabled,
disabled: isDisabledDueToLicense,
onChange: setIsFieldToggleChecked,
'data-test-subj': 'searchableSnapshotToggle',
label: i18n.translate(
Expand Down Expand Up @@ -339,7 +322,7 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
fieldNotices={renderInfoCallout()}
fullWidth
>
{isDisabled ? <div /> : renderField}
{isDisabledDueToLicense ? <div /> : renderField}
</DescribedFormRow>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { fatalErrors, toasts } from './notification';
function createToastConfig(error: IHttpFetchError, errorTitle: string) {
if (error && error.body) {
// Error body shape is defined by the API.
const { error: errorString, statusCode, message } = error.body;
const { error: errorString, statusCode, message: errorMessage, attributes } = error.body;
const message = attributes?.causes?.length
? attributes.causes[attributes.causes.length - 1]
: errorMessage;

return {
title: errorTitle,
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -9449,8 +9449,6 @@
"xpack.indexLifecycleMgmt.editPolicy.saveAsNewPolicyMessage": "新規ポリシーとして保存します",
"xpack.indexLifecycleMgmt.editPolicy.saveButton": "ポリシーを保存",
"xpack.indexLifecycleMgmt.editPolicy.saveErrorMessage": "ライフサイクルポリシー {lifecycleName} の保存中にエラーが発生しました",
"xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotCalloutBody": "検索可能なスナップショットがホットフェーズで有効な場合には、強制、マージ、縮小、凍結、コールドフェーズの検索可能なスナップショットは許可されません。",
"xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotDisabledCalloutBody": "ホットフェーズで構成されているときには、コールドフェーズで検索可能なスナップショットを作成できません。",
"xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotFieldDescription": "選択したリポジトリで管理されたインデックスのスナップショットを作成し、検索可能なスナップショットとしてマウントします。{learnMoreLink}。",
"xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotFieldLabel": "検索可能なスナップショットリポジドリ",
"xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotFieldTitle": "検索可能スナップショット",
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -9473,8 +9473,6 @@
"xpack.indexLifecycleMgmt.editPolicy.saveAsNewPolicyMessage": "另存为新策略",
"xpack.indexLifecycleMgmt.editPolicy.saveButton": "保存策略",
"xpack.indexLifecycleMgmt.editPolicy.saveErrorMessage": "保存生命周期策略 {lifecycleName} 时出错",
"xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotCalloutBody": "在热阶段启用可搜索快照时,不允许强制合并、缩小、冻结可搜索快照以及将其置入冷阶段。",
"xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotDisabledCalloutBody": "无法在冷阶段创建在热阶段配置的可搜索快照。",
"xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotFieldDescription": "在所选存储库中拍取受管索引的快照,并将其安装为可搜索快照。{learnMoreLink}。",
"xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotFieldLabel": "可搜索快照存储库",
"xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotFieldTitle": "可搜索快照",
Expand Down