Skip to content

Commit

Permalink
[Fleet] Honor source_mode defined in a package datastream when instal…
Browse files Browse the repository at this point in the history
…ling it
  • Loading branch information
nchaulet committed Dec 5, 2022
1 parent 4f76854 commit a95fa89
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,38 @@ describe('EPM index template install', () => {
expect(indexTemplate.priority).toBe(templatePriorityDatasetIsPrefixTrue);
expect(indexTemplate.index_patterns).toEqual([templateIndexPatternDatasetIsPrefixTrue]);
});

it('tests prepareTemplate to set source mode to synthetics if specified', async () => {
const dataStreamDatasetIsPrefixTrue = {
type: 'metrics',
dataset: 'package.dataset',
title: 'test data stream',
release: 'experimental',
package: 'package',
path: 'path',
ingest_pipeline: 'default',
dataset_is_prefix: true,
elasticsearch: {
source_mode: 'synthetic',
},
} as RegistryDataStream;
const pkg = {
name: 'package',
version: '0.0.1',
};

const { componentTemplates } = prepareTemplate({
pkg,
dataStream: dataStreamDatasetIsPrefixTrue,
});

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

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

expect(packageTemplate.mappings).toHaveProperty('_source');
expect(packageTemplate.mappings._source).toEqual({ mode: 'synthetic' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,17 @@ export function buildComponentTemplates(params: {
mappings: {
properties: mappingsProperties,
dynamic_templates: mappingsDynamicTemplates.length ? mappingsDynamicTemplates : undefined,
...omit(indexTemplateMappings, 'properties', 'dynamic_templates'),
...omit(indexTemplateMappings, 'properties', 'dynamic_templates', '_source'),
...(indexTemplateMappings?._source || registryElasticsearch?.source_mode
? {
_source: {
...indexTemplateMappings?._source,
...(registryElasticsearch?.source_mode === 'synthetic'
? { mode: 'synthetic' }
: {}),
},
}
: {}),
},
},
_meta,
Expand Down

0 comments on commit a95fa89

Please sign in to comment.