From b985572006a7f3ed942badf46f4e3be2f2d4322c Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Thu, 12 Dec 2024 15:13:49 +0100 Subject: [PATCH] [UA] Remove 7->8 multitype check (#203995) ## Summary Removes the 7->8.x logic for detecting and warning users about custom types. Specifically, we had a `GET index` call with `include_type_name` that is no longer supported and would return mappings in the following, deprecated, multitype form: ```jsonc { "mappings": { "": { "properties": { /* properties */ } } } } ``` Now you can only get: ```jsonc { "mappings": { "properties": { /* properties */ } } ``` ...including `include_type_name` is causing a 400 response from ES, blocking UA's ability to reindex. Existing code already handles both of these forms bc it had to for 7.last, this PR just removes logic targeting the former (and removes our outdated user-facing warning). ## Resources * 7->8 removal notice https://www.elastic.co/guide/en/elasticsearch/reference/7.17/removal-of-types.html * old docs https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-get-index.html --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit b525d00fde535645d7d60d3d98cd1f5f8cb0d4ad) # Conflicts: # .github/CODEOWNERS --- .../translations/translations/fr-FR.json | 2 - .../translations/translations/ja-JP.json | 2 - .../translations/translations/zh-CN.json | 2 - .../plugins/upgrade_assistant/common/types.ts | 6 +- .../reindex/flyout/warning_step.test.tsx | 10 +-- .../reindex/flyout/warning_step_checkbox.tsx | 36 ---------- .../reindex/flyout/warnings_step.tsx | 2 - .../lib/reindexing/index_settings.test.ts | 66 ------------------- .../server/lib/reindexing/index_settings.ts | 34 ++-------- .../server/lib/reindexing/reindex_actions.ts | 29 ++------ .../server/lib/reindexing/types.ts | 11 ---- .../reindex_indices/reindex_indices.test.ts | 8 +-- 12 files changed, 17 insertions(+), 191 deletions(-) diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json index 12bf5bae17c04..6da5e9f09d271 100644 --- a/x-pack/plugins/translations/translations/fr-FR.json +++ b/x-pack/plugins/translations/translations/fr-FR.json @@ -48785,8 +48785,6 @@ "xpack.upgradeAssistant.checkupTab.reindexing.flyout.flyoutHeader": "Réindexer {index}", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.learnMoreLinkLabel": "En savoir plus", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.acceptChangesTitle": "Accepter les modifications", - "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.customTypeNameWarningDetail": "Les types de mapping ne sont plus pris en charge dans Elastic 8.x. Assurez-vous qu'aucun code d'application ou script n'utilise {mappingType}.", - "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.customTypeNameWarningTitle": "Remplacer le type de mapping {mappingType} par {defaultType}", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.deprecatedIndexSettingsWarningDetail": "Les paramètres d'index déclassés ont été détectés :", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.deprecatedIndexSettingsWarningTitle": "Retirer les paramètres d'index déclassés", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.destructiveCallout.calloutDetail": "Sauvegardez l'index avant de continuer. Pour poursuivre avec la réindexation, acceptez chaque modification.", diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index e5b0cedbed2c0..49b24f069da22 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -48741,8 +48741,6 @@ "xpack.upgradeAssistant.checkupTab.reindexing.flyout.flyoutHeader": "再インデックス{index}", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.learnMoreLinkLabel": "詳細", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.acceptChangesTitle": "変更を承諾", - "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.customTypeNameWarningDetail": "マッピングタイプはElastic 8.xではサポートされていません。アプリケーションコードまたはスクリプトが{mappingType}に依存していないことを確認してください。", - "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.customTypeNameWarningTitle": "マッピングタイプ{mappingType}を{defaultType}で置き換えます", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.deprecatedIndexSettingsWarningDetail": "次の廃止予定のインデックス設定が検出されました。", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.deprecatedIndexSettingsWarningTitle": "廃止予定のインデックス設定を削除", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.destructiveCallout.calloutDetail": "続行する前に、インデックスをバックアップしてください。再インデックスを続行するには、各変更を承諾してください。", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index e60c7cca349c8..ca72f6c3c145a 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -48820,8 +48820,6 @@ "xpack.upgradeAssistant.checkupTab.reindexing.flyout.flyoutHeader": "重新索引 {index}", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.learnMoreLinkLabel": "了解详情", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.acceptChangesTitle": "接受更改", - "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.customTypeNameWarningDetail": "映射类型在 Elastic 8.x 中不再受支持。确保没有应用程序代码或脚本依赖 {mappingType}。", - "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.customTypeNameWarningTitle": "将映射类型 {mappingType} 替换为 {defaultType}", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.deprecatedIndexSettingsWarningDetail": "检测到以下弃用的索引设置:", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.deprecatedIndexSettingsWarningTitle": "移除弃用的索引设置", "xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.destructiveCallout.calloutDetail": "继续前备份索引。要继续重新索引,请接受每个更改。", diff --git a/x-pack/plugins/upgrade_assistant/common/types.ts b/x-pack/plugins/upgrade_assistant/common/types.ts index 781e4865ee568..54b175a428512 100644 --- a/x-pack/plugins/upgrade_assistant/common/types.ts +++ b/x-pack/plugins/upgrade_assistant/common/types.ts @@ -121,8 +121,8 @@ export interface ReindexOperation { export type ReindexSavedObject = SavedObject; -// 7.0 -> 8.0 warnings -export type ReindexWarningTypes = 'customTypeName' | 'indexSetting' | 'replaceIndexWithAlias'; +// 8.0 -> 9.0 warnings +export type ReindexWarningTypes = 'indexSetting' | 'replaceIndexWithAlias'; export interface ReindexWarning { warningType: ReindexWarningTypes; @@ -130,8 +130,6 @@ export interface ReindexWarning { * Optional metadata for deprecations * * @remark - * For example, for the "customTypeName" deprecation, - * we want to surface the typeName to the user. * For "indexSetting" we want to surface the deprecated settings. */ meta?: { diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warning_step.test.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warning_step.test.tsx index eedb05e8b809a..7c6f7d554082a 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warning_step.test.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warning_step.test.tsx @@ -52,12 +52,6 @@ describe('WarningsFlyoutStep', () => { const defaultPropsWithWarnings = { ...defaultProps, warnings: [ - { - warningType: 'customTypeName', - meta: { - typeName: 'my_mapping_type', - }, - }, { warningType: 'indexSetting', meta: { @@ -76,9 +70,7 @@ describe('WarningsFlyoutStep', () => { button.simulate('click'); expect(defaultPropsWithWarnings.continueReindex).not.toHaveBeenCalled(); - // first warning (customTypeName) - wrapper.find(`input#${idForWarning(0)}`).simulate('change'); - // second warning (indexSetting) + // first warning (indexSetting) wrapper.find(`input#${idForWarning(1)}`).simulate('change'); button.simulate('click'); diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warning_step_checkbox.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warning_step_checkbox.tsx index 7782d47fc5cc0..27bfdc6256781 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warning_step_checkbox.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warning_step_checkbox.tsx @@ -82,42 +82,6 @@ export interface WarningCheckboxProps { meta?: ReindexWarning['meta']; } -export const CustomTypeNameWarningCheckbox: React.FunctionComponent = ({ - isChecked, - onChange, - docLinks, - id, - meta, -}) => { - return ( - {meta!.typeName as string}, - defaultType: _doc, - }} - /> - } - description={ - {meta!.typeName as string}, - }} - /> - } - documentationUrl={docLinks.elasticsearch.typesRemoval} - /> - ); -}; - export const DeprecatedSettingWarningCheckbox: React.FunctionComponent = ({ isChecked, onChange, diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warnings_step.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warnings_step.tsx index 0de8449a7cc7e..d3ed1d0c16387 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warnings_step.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warnings_step.tsx @@ -27,7 +27,6 @@ import { } from '../../../../../../../common/types'; import { useAppContext } from '../../../../../app_context'; import { - CustomTypeNameWarningCheckbox, DeprecatedSettingWarningCheckbox, ReplaceIndexWithAliasWarningCheckbox, WarningCheckboxProps, @@ -40,7 +39,6 @@ interface CheckedIds { const warningToComponentMap: { [key in ReindexWarningTypes]: React.FunctionComponent; } = { - customTypeName: CustomTypeNameWarningCheckbox, indexSetting: DeprecatedSettingWarningCheckbox, replaceIndexWithAlias: ReplaceIndexWithAliasWarningCheckbox, }; diff --git a/x-pack/plugins/upgrade_assistant/server/lib/reindexing/index_settings.test.ts b/x-pack/plugins/upgrade_assistant/server/lib/reindexing/index_settings.test.ts index 4f58c1a2ea024..685bc443c324c 100644 --- a/x-pack/plugins/upgrade_assistant/server/lib/reindexing/index_settings.test.ts +++ b/x-pack/plugins/upgrade_assistant/server/lib/reindexing/index_settings.test.ts @@ -182,71 +182,5 @@ describe('transformFlatSettings', () => { }) ).toEqual([]); }); - - if (currentMajor === 7) { - describe('[7.x] customTypeName warning', () => { - it('returns customTypeName warning for non-_doc mapping types', () => { - expect( - getReindexWarnings({ - settings: {}, - mappings: { doc: {} }, - }) - ).toEqual([ - { - warningType: 'customTypeName', - meta: { - typeName: 'doc', - }, - }, - ]); - }); - it('does not return customTypeName warning for _doc mapping types', () => { - expect( - getReindexWarnings({ - settings: {}, - mappings: { _doc: {} }, - }) - ).toEqual([]); - }); - }); - - describe('[7.x] deprecatedSetting warning', () => { - it('returns deprecatedSetting warning for deprecated index settings', () => { - expect( - getReindexWarnings({ - settings: { - // Deprecated settings - 'index.force_memory_term_dictionary': '1024', - 'index.max_adjacency_matrix_filters': 'true', - 'index.soft_deletes.enabled': 'true', - }, - mappings: {}, - }) - ).toEqual([ - { - warningType: 'indexSetting', - meta: { - deprecatedSettings: [ - 'index.force_memory_term_dictionary', - 'index.max_adjacency_matrix_filters', - 'index.soft_deletes.enabled', - ], - }, - }, - ]); - }); - - it('does not return a deprecatedSetting warning for there are no deprecated index settings', () => { - expect( - getReindexWarnings({ - settings: { - 'index.number_of_replicas': '1', - }, - mappings: {}, - }) - ).toEqual([]); - }); - }); - } }); }); diff --git a/x-pack/plugins/upgrade_assistant/server/lib/reindexing/index_settings.ts b/x-pack/plugins/upgrade_assistant/server/lib/reindexing/index_settings.ts index 96d14bac8d63c..3344ecde4ab69 100644 --- a/x-pack/plugins/upgrade_assistant/server/lib/reindexing/index_settings.ts +++ b/x-pack/plugins/upgrade_assistant/server/lib/reindexing/index_settings.ts @@ -8,7 +8,7 @@ import { flow, omit } from 'lodash'; import { ReindexWarning } from '../../../common/types'; import { versionService } from '../version'; -import { FlatSettings, FlatSettingsWithTypeName } from './types'; +import { FlatSettings } from './types'; export interface ParsedIndexName { cleanIndexName: string; baseName: string; @@ -75,27 +75,8 @@ export const generateNewIndexName = (indexName: string): string => { : `${currentVersion}-${sourceName}`; }; -export const getCustomTypeWarning = ( - flatSettings: FlatSettingsWithTypeName | FlatSettings -): ReindexWarning | undefined => { - const DEFAULT_TYPE_NAME = '_doc'; - // In 7+, it's not possible to have more than one type, - // so always grab the first (and only) key. - const typeName = Object.getOwnPropertyNames(flatSettings.mappings)[0]; - const typeNameWarning = Boolean(typeName && typeName !== DEFAULT_TYPE_NAME); - - if (typeNameWarning) { - return { - warningType: 'customTypeName', - meta: { - typeName, - }, - }; - } -}; - export const getDeprecatedSettingWarning = ( - flatSettings: FlatSettingsWithTypeName | FlatSettings + flatSettings: FlatSettings ): ReindexWarning | undefined => { const { settings } = flatSettings; @@ -131,19 +112,12 @@ export const getDeprecatedSettingWarning = ( * Returns an array of warnings that should be displayed to user before reindexing begins. * @param flatSettings */ -export const getReindexWarnings = ( - flatSettings: FlatSettingsWithTypeName | FlatSettings -): ReindexWarning[] => { +export const getReindexWarnings = (flatSettings: FlatSettings): ReindexWarning[] => { const warnings = [] as ReindexWarning[]; - if (versionService.getMajorVersion() === 7) { - const customTypeWarning = getCustomTypeWarning(flatSettings); + if (versionService.getMajorVersion() === 8) { const deprecatedSettingWarning = getDeprecatedSettingWarning(flatSettings); - if (customTypeWarning) { - warnings.push(customTypeWarning); - } - if (deprecatedSettingWarning) { warnings.push(deprecatedSettingWarning); } diff --git a/x-pack/plugins/upgrade_assistant/server/lib/reindexing/reindex_actions.ts b/x-pack/plugins/upgrade_assistant/server/lib/reindexing/reindex_actions.ts index 01c73bf85765b..ce588e8bdb47a 100644 --- a/x-pack/plugins/upgrade_assistant/server/lib/reindexing/reindex_actions.ts +++ b/x-pack/plugins/upgrade_assistant/server/lib/reindexing/reindex_actions.ts @@ -20,9 +20,8 @@ import { ReindexStatus, ReindexStep, } from '../../../common/types'; -import { versionService } from '../version'; import { generateNewIndexName } from './index_settings'; -import { FlatSettings, FlatSettingsWithTypeName } from './types'; +import { FlatSettings } from './types'; // TODO: base on elasticsearch.requestTimeout? export const LOCK_WINDOW = moment.duration(90, 'seconds'); @@ -80,10 +79,7 @@ export interface ReindexActions { * Retrieve index settings (in flat, dot-notation style) and mappings. * @param indexName */ - getFlatSettings( - indexName: string, - withTypeName?: boolean - ): Promise; + getFlatSettings(indexName: string): Promise; } export const reindexActionsFactory = ( @@ -208,23 +204,10 @@ export const reindexActionsFactory = ( }, async getFlatSettings(indexName: string) { - let flatSettings; - - if (versionService.getMajorVersion() === 7) { - // On 7.x, we need to get index settings with mapping type - flatSettings = await esClient.indices.get({ - index: indexName, - flat_settings: true, - // This @ts-ignore is needed on master since the flag is deprecated on >7.x - // @ts-ignore - include_type_name: true, - }); - } else { - flatSettings = await esClient.indices.get({ - index: indexName, - flat_settings: true, - }); - } + const flatSettings = await esClient.indices.get({ + index: indexName, + flat_settings: true, + }); if (!flatSettings[indexName]) { return null; diff --git a/x-pack/plugins/upgrade_assistant/server/lib/reindexing/types.ts b/x-pack/plugins/upgrade_assistant/server/lib/reindexing/types.ts index 8d600849987db..09449413dabc1 100644 --- a/x-pack/plugins/upgrade_assistant/server/lib/reindexing/types.ts +++ b/x-pack/plugins/upgrade_assistant/server/lib/reindexing/types.ts @@ -26,14 +26,3 @@ export interface FlatSettings { _meta?: MetaProperties; }; } - -// Specific to 7.x-8 upgrade -export interface FlatSettingsWithTypeName { - settings: estypes.IndicesIndexState['settings']; - mappings?: { - [typeName: string]: { - properties?: MappingProperties; - _meta?: MetaProperties; - }; - }; -} diff --git a/x-pack/plugins/upgrade_assistant/server/routes/reindex_indices/reindex_indices.test.ts b/x-pack/plugins/upgrade_assistant/server/routes/reindex_indices/reindex_indices.test.ts index bb3ccaeb8b125..b02dd08f841d3 100644 --- a/x-pack/plugins/upgrade_assistant/server/routes/reindex_indices/reindex_indices.test.ts +++ b/x-pack/plugins/upgrade_assistant/server/routes/reindex_indices/reindex_indices.test.ts @@ -94,9 +94,9 @@ describe('reindex API', () => { }); mockReindexService.detectReindexWarnings.mockResolvedValueOnce([ { - warningType: 'customTypeName', + warningType: 'indexSetting', meta: { - typeName: 'my_mapping_type', + settingA: 'deprecated', }, }, ]); @@ -120,9 +120,9 @@ describe('reindex API', () => { expect(data.reindexOp).toEqual({ indexName: 'wowIndex', status: ReindexStatus.inProgress }); expect(data.warnings).toEqual([ { - warningType: 'customTypeName', + warningType: 'indexSetting', meta: { - typeName: 'my_mapping_type', + settingA: 'deprecated', }, }, ]);