From bdc80322b08a99c763142b93e07179bed431f4dd Mon Sep 17 00:00:00 2001 From: Elena Stoeva <59341489+ElenaStoeva@users.noreply.github.com> Date: Wed, 11 Dec 2024 09:06:46 +0000 Subject: [PATCH] [Index Management] Fix schema for index templates (#203552) Fixes https://github.com/elastic/kibana/issues/203553 ## Summary This PR fixes the template schema so that the server allows creating a template with undefined index mode. The issue is that when we exposed the index mode info in https://github.com/elastic/kibana/pull/197874, we assumed that, by default, the index mode is `standard` so `indexMode` was added as a required field. However, in https://github.com/elastic/kibana/pull/199521, we added the index mode field only if data streams toggle is enabled, so the `indexMode` is `undefined`. The PR also fixes a smaller issuer where Index mode is displayed even when it is undefined (when data streams are disabled): **Before:** Screenshot 2024-12-10 at 19 01 09 **Now:** Screenshot 2024-12-10 at 18 19 29 **How to test:** 1. Go to Index Management -> Index templates and start creating an index template. 2. Specify the name and the index pattern and disable the "Data streams" toggle. 3. Go to Review step and verify that index mode is not displayed in the summary and that creating the index template is successful. --- .../common/types/templates.ts | 2 +- .../template_form/steps/step_review.tsx | 22 +++++++++++-------- .../template_details/tabs/tab_summary.tsx | 22 +++++++++++-------- .../routes/api/templates/validate_schemas.ts | 2 +- .../index_management/lib/templates.helpers.ts | 1 - 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/x-pack/plugins/index_management/common/types/templates.ts b/x-pack/plugins/index_management/common/types/templates.ts index ab4614200c0b5..ffcc27ed08971 100644 --- a/x-pack/plugins/index_management/common/types/templates.ts +++ b/x-pack/plugins/index_management/common/types/templates.ts @@ -51,7 +51,7 @@ export interface TemplateDeserialized { priority?: number; // Composable template only allowAutoCreate: string; order?: number; // Legacy template only - indexMode: IndexMode; + indexMode?: IndexMode; ilmPolicy?: { name: string; }; diff --git a/x-pack/plugins/index_management/public/application/components/template_form/steps/step_review.tsx b/x-pack/plugins/index_management/public/application/components/template_form/steps/step_review.tsx index 593655da62fef..4e1901538cb93 100644 --- a/x-pack/plugins/index_management/public/application/components/template_form/steps/step_review.tsx +++ b/x-pack/plugins/index_management/public/application/components/template_form/steps/step_review.tsx @@ -271,15 +271,19 @@ export const StepReview: React.FunctionComponent = React.memo( {/* Index mode */} - - - - - {indexModeLabels[indexMode]} - + {indexMode && ( + <> + + + + + {indexModeLabels[indexMode]} + + + )} {/* Mappings */} diff --git a/x-pack/plugins/index_management/public/application/sections/home/template_list/template_details/tabs/tab_summary.tsx b/x-pack/plugins/index_management/public/application/sections/home/template_list/template_details/tabs/tab_summary.tsx index eed3335d01431..6958a32845fe6 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/template_list/template_details/tabs/tab_summary.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/template_list/template_details/tabs/tab_summary.tsx @@ -226,15 +226,19 @@ export const TabSummary: React.FunctionComponent = ({ templateDetails }) )} {/* Index mode */} - - - - - {indexModeLabels[indexMode]} - + {indexMode && ( + <> + + + + + {indexModeLabels[indexMode]} + + + )} {/* Allow auto create */} {isLegacy !== true && diff --git a/x-pack/plugins/index_management/server/routes/api/templates/validate_schemas.ts b/x-pack/plugins/index_management/server/routes/api/templates/validate_schemas.ts index cfd9c1d18e610..5bea0c36067c0 100644 --- a/x-pack/plugins/index_management/server/routes/api/templates/validate_schemas.ts +++ b/x-pack/plugins/index_management/server/routes/api/templates/validate_schemas.ts @@ -13,7 +13,7 @@ export const templateSchema = schema.object({ version: schema.maybe(schema.number()), order: schema.maybe(schema.number()), priority: schema.maybe(schema.number()), - indexMode: schema.string(), + indexMode: schema.maybe(schema.string()), // Not present for legacy templates allowAutoCreate: schema.maybe(schema.string()), template: schema.maybe( diff --git a/x-pack/test/api_integration/apis/management/index_management/lib/templates.helpers.ts b/x-pack/test/api_integration/apis/management/index_management/lib/templates.helpers.ts index a342df2d6287e..ea1e9a2d83bb1 100644 --- a/x-pack/test/api_integration/apis/management/index_management/lib/templates.helpers.ts +++ b/x-pack/test/api_integration/apis/management/index_management/lib/templates.helpers.ts @@ -59,7 +59,6 @@ export function templatesHelpers(getService: FtrProviderContext['getService']) { name, indexPatterns, version: 1, - indexMode: 'standard', template: { ...getTemplateMock(isMappingsSourceFieldEnabled) }, _kbnMeta: { isLegacy,