Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eem] prevent customization of builtin definitions #192593

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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