Skip to content

Commit

Permalink
[8.x] [UA] Remove 7->8 multitype check (#203995) (#204038)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [[UA] Remove 7->8 multitype check
(#203995)](#203995)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Jean-Louis
Leysens","email":"jeanlouis.leysens@elastic.co"},"sourceCommit":{"committedDate":"2024-12-12T14:13:49Z","message":"[UA]
Remove 7->8 multitype check (#203995)\n\n## Summary\r\n\r\nRemoves the
7->8.x logic for detecting and warning users about custom\r\ntypes.
Specifically, we had a `GET index` call with `include_type_name`\r\nthat
is no longer supported and would return mappings in the
following,\r\ndeprecated, multitype form:\r\n\r\n```jsonc\r\n{\r\n
\"mappings\": {\r\n \"<type_name>\": { \"properties\": { /* properties
*/ } }\r\n }\r\n}\r\n```\r\n\r\nNow you can only
get:\r\n\r\n```jsonc\r\n{\r\n \"mappings\": {\r\n \"properties\": { /*
properties */ }\r\n}\r\n```\r\n\r\n...including `include_type_name` is
causing a 400 response from ES,\r\nblocking UA's ability to reindex.
Existing code already handles both of\r\nthese forms bc it had to for
7.last, this PR just removes logic\r\ntargeting the former (and removes
our outdated user-facing warning).\r\n\r\n## Resources\r\n* 7->8 removal
notice\r\nhttps://www.elastic.co/guide/en/elasticsearch/reference/7.17/removal-of-types.html\r\n*
old
docs\r\nhttps://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-get-index.html\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"b525d00fde535645d7d60d3d98cd1f5f8cb0d4ad","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","Feature:Upgrade
Assistant","v9.0.0","backport:version","v8.18.0","v8.17.1"],"number":203995,"url":"https://github.com/elastic/kibana/pull/203995","mergeCommit":{"message":"[UA]
Remove 7->8 multitype check (#203995)\n\n## Summary\r\n\r\nRemoves the
7->8.x logic for detecting and warning users about custom\r\ntypes.
Specifically, we had a `GET index` call with `include_type_name`\r\nthat
is no longer supported and would return mappings in the
following,\r\ndeprecated, multitype form:\r\n\r\n```jsonc\r\n{\r\n
\"mappings\": {\r\n \"<type_name>\": { \"properties\": { /* properties
*/ } }\r\n }\r\n}\r\n```\r\n\r\nNow you can only
get:\r\n\r\n```jsonc\r\n{\r\n \"mappings\": {\r\n \"properties\": { /*
properties */ }\r\n}\r\n```\r\n\r\n...including `include_type_name` is
causing a 400 response from ES,\r\nblocking UA's ability to reindex.
Existing code already handles both of\r\nthese forms bc it had to for
7.last, this PR just removes logic\r\ntargeting the former (and removes
our outdated user-facing warning).\r\n\r\n## Resources\r\n* 7->8 removal
notice\r\nhttps://www.elastic.co/guide/en/elasticsearch/reference/7.17/removal-of-types.html\r\n*
old
docs\r\nhttps://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-get-index.html\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"b525d00fde535645d7d60d3d98cd1f5f8cb0d4ad"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203995","number":203995,"mergeCommit":{"message":"[UA]
Remove 7->8 multitype check (#203995)\n\n## Summary\r\n\r\nRemoves the
7->8.x logic for detecting and warning users about custom\r\ntypes.
Specifically, we had a `GET index` call with `include_type_name`\r\nthat
is no longer supported and would return mappings in the
following,\r\ndeprecated, multitype form:\r\n\r\n```jsonc\r\n{\r\n
\"mappings\": {\r\n \"<type_name>\": { \"properties\": { /* properties
*/ } }\r\n }\r\n}\r\n```\r\n\r\nNow you can only
get:\r\n\r\n```jsonc\r\n{\r\n \"mappings\": {\r\n \"properties\": { /*
properties */ }\r\n}\r\n```\r\n\r\n...including `include_type_name` is
causing a 400 response from ES,\r\nblocking UA's ability to reindex.
Existing code already handles both of\r\nthese forms bc it had to for
7.last, this PR just removes logic\r\ntargeting the former (and removes
our outdated user-facing warning).\r\n\r\n## Resources\r\n* 7->8 removal
notice\r\nhttps://www.elastic.co/guide/en/elasticsearch/reference/7.17/removal-of-types.html\r\n*
old
docs\r\nhttps://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-get-index.html\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"b525d00fde535645d7d60d3d98cd1f5f8cb0d4ad"}},{"branch":"8.x","label":"v8.18.0","labelRegex":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
  • Loading branch information
jloleysens authored Dec 12, 2024
1 parent 5c3dd15 commit ee7bbf9
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48590,8 +48590,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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48436,8 +48436,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": "続行する前に、インデックスをバックアップしてください。再インデックスを続行するには、各変更を承諾してください。",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48538,8 +48538,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": "继续前备份索引。要继续重新索引,请接受每个更改。",
Expand Down
6 changes: 2 additions & 4 deletions x-pack/plugins/upgrade_assistant/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,15 @@ export interface ReindexOperation {

export type ReindexSavedObject = SavedObject<ReindexOperation>;

// 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;
/**
* 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?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ describe('WarningsFlyoutStep', () => {
const defaultPropsWithWarnings = {
...defaultProps,
warnings: [
{
warningType: 'customTypeName',
meta: {
typeName: 'my_mapping_type',
},
},
{
warningType: 'indexSetting',
meta: {
Expand All @@ -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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,42 +82,6 @@ export interface WarningCheckboxProps {
meta?: ReindexWarning['meta'];
}

export const CustomTypeNameWarningCheckbox: React.FunctionComponent<WarningCheckboxProps> = ({
isChecked,
onChange,
docLinks,
id,
meta,
}) => {
return (
<WarningCheckbox
isChecked={isChecked}
onChange={onChange}
warningId={id}
label={
<FormattedMessage
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.customTypeNameWarningTitle"
defaultMessage="Replace mapping type {mappingType} with {defaultType}"
values={{
mappingType: <EuiCode>{meta!.typeName as string}</EuiCode>,
defaultType: <EuiCode>_doc</EuiCode>,
}}
/>
}
description={
<FormattedMessage
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.customTypeNameWarningDetail"
defaultMessage="Mapping types are no longer supported in Elastic 8.x. Ensure no application code or scripts rely on {mappingType}."
values={{
mappingType: <EuiCode>{meta!.typeName as string}</EuiCode>,
}}
/>
}
documentationUrl={docLinks.elasticsearch.typesRemoval}
/>
);
};

export const DeprecatedSettingWarningCheckbox: React.FunctionComponent<WarningCheckboxProps> = ({
isChecked,
onChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
} from '../../../../../../../common/types';
import { useAppContext } from '../../../../../app_context';
import {
CustomTypeNameWarningCheckbox,
DeprecatedSettingWarningCheckbox,
ReplaceIndexWithAliasWarningCheckbox,
WarningCheckboxProps,
Expand All @@ -40,7 +39,6 @@ interface CheckedIds {
const warningToComponentMap: {
[key in ReindexWarningTypes]: React.FunctionComponent<WarningCheckboxProps>;
} = {
customTypeName: CustomTypeNameWarningCheckbox,
indexSetting: DeprecatedSettingWarningCheckbox,
replaceIndexWithAlias: ReplaceIndexWithAliasWarningCheckbox,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
});
});
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,8 +43,8 @@ export const transformFlatSettings = (flatSettings: FlatSettings) => {
* introduced by the upgrade assistant
*
* Examples:
* .reindex-v8-foo => .foo
* reindex-v8-foo => foo
* .reindex-v7-foo => .foo
* reindex-v7-foo => foo
*
* @param indexName
*/
Expand All @@ -63,8 +63,8 @@ export const sourceNameForIndex = (indexName: string): string => {
/**
* Provides the index name to re-index into
*
* .foo -> .reindexed-v8-foo
* foo => reindexed-v8-foo
* .foo -> .reindexed-v7-foo
* foo => reindexed-v7-foo
*/
export const generateNewIndexName = (indexName: string): string => {
const sourceName = sourceNameForIndex(indexName);
Expand All @@ -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;

Expand Down Expand Up @@ -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() === 8) {
const customTypeWarning = getCustomTypeWarning(flatSettings);
const deprecatedSettingWarning = getDeprecatedSettingWarning(flatSettings);

if (customTypeWarning) {
warnings.push(customTypeWarning);
}

if (deprecatedSettingWarning) {
warnings.push(deprecatedSettingWarning);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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<FlatSettings | FlatSettingsWithTypeName | null>;
getFlatSettings(indexName: string): Promise<FlatSettings | null>;
}

export const reindexActionsFactory = (
Expand Down Expand Up @@ -208,23 +204,10 @@ export const reindexActionsFactory = (
},

async getFlatSettings(indexName: string) {
let flatSettings;

if (versionService.getMajorVersion() === 8) {
// 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;
Expand Down
11 changes: 0 additions & 11 deletions x-pack/plugins/upgrade_assistant/server/lib/reindexing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ describe('reindex API', () => {
});
mockReindexService.detectReindexWarnings.mockResolvedValueOnce([
{
warningType: 'customTypeName',
warningType: 'indexSetting',
meta: {
typeName: 'my_mapping_type',
settingA: 'deprecated',
},
},
]);
Expand All @@ -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',
},
},
]);
Expand Down

0 comments on commit ee7bbf9

Please sign in to comment.