Skip to content

Commit

Permalink
[8.x] [Fleet] Use index.mapping.source.mode instead of _source.mode (#…
Browse files Browse the repository at this point in the history
…202729) (#204406)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Fleet] Use index.mapping.source.mode instead of _source.mode
(#202729)](#202729)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Nicolas
Chaulet","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-03T17:49:49Z","message":"[Fleet]
Use index.mapping.source.mode instead of _source.mode
(#202729)","sha":"6e5fc696a6f940d21af4ec5e4fd46d73a1007b71","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","backport:prev-minor","v8.18.0"],"title":"[Fleet]
Use index.mapping.source.mode instead of
_source.mode","number":202729,"url":"https://github.com/elastic/kibana/pull/202729","mergeCommit":{"message":"[Fleet]
Use index.mapping.source.mode instead of _source.mode
(#202729)","sha":"6e5fc696a6f940d21af4ec5e4fd46d73a1007b71"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202729","number":202729,"mergeCommit":{"message":"[Fleet]
Use index.mapping.source.mode instead of _source.mode
(#202729)","sha":"6e5fc696a6f940d21af4ec5e4fd46d73a1007b71"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Nicolas Chaulet <[email protected]>
  • Loading branch information
kibanamachine and nchaulet authored Dec 16, 2024
1 parent e737163 commit d3fcf47
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,13 @@ describe('EPM index template install', () => {

const packageTemplate = componentTemplates['metrics-package.dataset@package'].template;

if (!('mappings' in packageTemplate)) {
if (!('settings' in packageTemplate)) {
throw new Error('no mappings on package template');
}

expect(packageTemplate.mappings).toHaveProperty('_source');
expect(packageTemplate.mappings._source).toEqual({ mode: 'synthetic' });
expect(packageTemplate.settings?.index?.mapping).toHaveProperty('source');
// @ts-expect-error esclient mapping out-of-date
expect(packageTemplate.settings?.index?.mapping?.source).toEqual({ mode: 'synthetic' });
});

it('tests prepareTemplate to set source mode to synthetics if index_mode:time_series', async () => {
Expand All @@ -154,12 +155,13 @@ describe('EPM index template install', () => {

const packageTemplate = componentTemplates['metrics-package.dataset@package'].template;

if (!('mappings' in packageTemplate)) {
throw new Error('no mappings on package template');
if (!('settings' in packageTemplate)) {
throw new Error('no settings on package template');
}

expect(packageTemplate.mappings).toHaveProperty('_source');
expect(packageTemplate.mappings._source).toEqual({ mode: 'synthetic' });
expect(packageTemplate.settings?.index?.mapping).toHaveProperty('source');
// @ts-expect-error esclient mapping out-of-date
expect(packageTemplate.settings?.index?.mapping?.source).toEqual({ mode: 'synthetic' });
});

it('tests prepareTemplate to not set source mode to synthetics if index_mode:time_series and user disabled synthetic', async () => {
Expand Down Expand Up @@ -193,11 +195,11 @@ describe('EPM index template install', () => {

const packageTemplate = componentTemplates['metrics-package.dataset@package'].template;

if (!('mappings' in packageTemplate)) {
throw new Error('no mappings on package template');
if (!('settings' in packageTemplate)) {
throw new Error('no settings on package template');
}

expect(packageTemplate.mappings).not.toHaveProperty('_source');
expect(packageTemplate.settings?.index?.mapping).not.toHaveProperty('source');
});

it('tests prepareTemplate to not set source mode to synthetics if specified but user disabled it', async () => {
Expand Down Expand Up @@ -231,11 +233,11 @@ describe('EPM index template install', () => {

const packageTemplate = componentTemplates['metrics-package.dataset@package'].template;

if (!('mappings' in packageTemplate)) {
throw new Error('no mappings on package template');
if (!('settings' in packageTemplate)) {
throw new Error('no settings on package template');
}

expect(packageTemplate.mappings).not.toHaveProperty('_source');
expect(packageTemplate.settings?.index?.mapping).not.toHaveProperty('source');
});

it('tests prepareTemplate to set index_mode time series if index_mode:time_series', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,14 @@ export function buildComponentTemplates(params: {
templateSettings.index?.mapping?.total_fields?.limit
),
},
...(templateSettings.index?.mapping?.source || sourceModeSynthetic
? {
source: {
...templateSettings.index?.mapping?.source,
...(sourceModeSynthetic ? { mode: 'synthetic' } : {}),
},
}
: {}),
},
},
},
Expand All @@ -404,15 +412,7 @@ export function buildComponentTemplates(params: {
? { runtime: mappingsRuntimeFields }
: {}),
dynamic_templates: mappingsDynamicTemplates.length ? mappingsDynamicTemplates : undefined,
...omit(indexTemplateMappings, 'properties', 'dynamic_templates', '_source', 'runtime'),
...(indexTemplateMappings?._source || sourceModeSynthetic
? {
_source: {
...indexTemplateMappings?._source,
...(sourceModeSynthetic ? { mode: 'synthetic' } : {}),
},
}
: {}),
...omit(indexTemplateMappings, 'properties', 'dynamic_templates', 'runtime'),
},
...(lifecycle ? { lifecycle } : {}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1016,8 +1016,8 @@ const updateExistingDataStream = async ({
const existingDsConfig = Object.values(existingDs);
const currentBackingIndexConfig = existingDsConfig.at(-1);
const currentIndexMode = currentBackingIndexConfig?.settings?.index?.mode;
// @ts-expect-error Property 'mode' does not exist on type 'MappingSourceField'
const currentSourceType = currentBackingIndexConfig.mappings?._source?.mode;
// @ts-expect-error Property 'source.mode' does not exist on type 'IndicesMappingLimitSettings'
const currentSourceType = currentBackingIndexConfig?.settings?.index?.mapping?.source?.mode;

let settings: IndicesIndexSettings;
let mappings: MappingTypeMapping = {};
Expand Down Expand Up @@ -1126,7 +1126,7 @@ const updateExistingDataStream = async ({
// Trigger a rollover if the index mode or source type has changed
if (
currentIndexMode !== settings?.index?.mode ||
currentSourceType !== mappings?._source?.mode ||
currentSourceType !== settings?.index?.source?.mode ||
dynamicDimensionMappingsChanged
) {
if (options?.skipDataStreamRollover === true) {
Expand Down

0 comments on commit d3fcf47

Please sign in to comment.