Skip to content

Commit

Permalink
[eem] prevent customization of builtin definitions (elastic#192593)
Browse files Browse the repository at this point in the history
We allow users to define `@platform` and `@custom` ingest
pipelines/index templates to customize entity definitions output. This
change prevents builtin definitions from being customized
  • Loading branch information
klacabane authored Sep 12, 2024
1 parent 756cd63 commit 88f363c
Show file tree
Hide file tree
Showing 15 changed files with 559 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { EntityDefinition } from '@kbn/entities-schema';
import { BUILT_IN_ID_PREFIX } from '../built_in';

export function isBuiltinDefinition(definition: EntityDefinition) {
return definition.id.startsWith(BUILT_IN_ID_PREFIX);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
* 2.0.
*/

import { entityDefinition } from '../helpers/fixtures/entity_definition';
import { entityDefinition, builtInEntityDefinition } from '../helpers/fixtures';
import { generateHistoryProcessors } from './generate_history_processors';

describe('generateHistoryProcessors(definition)', () => {
it('should genearte a valid pipeline', () => {
it('should generate a valid pipeline for custom definition', () => {
const processors = generateHistoryProcessors(entityDefinition);
expect(processors).toMatchSnapshot();
});

it('should generate a valid pipeline for builtin definition', () => {
const processors = generateHistoryProcessors(builtInEntityDefinition);
expect(processors).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
cleanScript,
} from '../helpers/ingest_pipeline_script_processor_helpers';
import { generateHistoryIndexName } from '../helpers/generate_component_id';
import { isBuiltinDefinition } from '../helpers/is_builtin_definition';

function mapDestinationToPainless(field: string) {
return `
Expand Down Expand Up @@ -46,6 +47,39 @@ function liftIdentityFieldsToDocumentRoot(definition: EntityDefinition) {
}));
}

function getCustomIngestPipelines(definition: EntityDefinition) {
if (isBuiltinDefinition(definition)) {
return [];
}

return [
{
pipeline: {
ignore_missing_pipeline: true,
name: `${definition.id}@platform`,
},
},
{
pipeline: {
ignore_missing_pipeline: true,
name: `${definition.id}-history@platform`,
},
},
{
pipeline: {
ignore_missing_pipeline: true,
name: `${definition.id}@custom`,
},
},
{
pipeline: {
ignore_missing_pipeline: true,
name: `${definition.id}-history@custom`,
},
},
];
}

export function generateHistoryProcessors(definition: EntityDefinition) {
return [
{
Expand Down Expand Up @@ -162,30 +196,6 @@ export function generateHistoryProcessors(definition: EntityDefinition) {
date_formats: ['UNIX_MS', 'ISO8601', "yyyy-MM-dd'T'HH:mm:ss.SSSXX"],
},
},
{
pipeline: {
ignore_missing_pipeline: true,
name: `${definition.id}@platform`,
},
},
{
pipeline: {
ignore_missing_pipeline: true,
name: `${definition.id}-history@platform`,
},
},

{
pipeline: {
ignore_missing_pipeline: true,
name: `${definition.id}@custom`,
},
},
{
pipeline: {
ignore_missing_pipeline: true,
name: `${definition.id}-history@custom`,
},
},
...getCustomIngestPipelines(definition),
];
}
Loading

0 comments on commit 88f363c

Please sign in to comment.