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] Add versioning for entity definitions #187692

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
5 changes: 5 additions & 0 deletions x-pack/packages/kbn-entities-schema/src/schema/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,8 @@ export const identityFieldsSchema = z
optional: z.boolean(),
})
.or(z.string().transform((value) => ({ field: value, optional: false })));

const semVerRegex = new RegExp(/^[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}$/);
export const semVerSchema = z.string().refine((maybeSemVer) => semVerRegex.test(maybeSemVer), {
message: 'The string does not match the semver pattern of 1.1.1',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
message: 'The string does not match the semver pattern of 1.1.1',
message: 'The string does use Semantic Versioning (Semver) format of {major}.{minor}.{patch} (e.g., 1.0.0), ensure each part contains only digits.',

});
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import {
filterSchema,
durationSchema,
identityFieldsSchema,
semVerSchema,
} from './common';

export const entityDefinitionSchema = z.object({
id: z.string().regex(/^[\w-]+$/),
version: semVerSchema,
name: z.string(),
description: z.optional(z.string()),
type: z.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BUILT_IN_ID_PREFIX } from './constants';

export const builtInServicesEntityDefinition: EntityDefinition = entityDefinitionSchema.parse({
id: `${BUILT_IN_ID_PREFIX}services`,
version: '1.0.0',
miltonhultgren marked this conversation as resolved.
Show resolved Hide resolved
name: 'Services from logs',
type: 'service',
managed: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export async function createAndInstallHistoryIngestPipeline(
esClient.ingest.putPipeline({
id: historyId,
processors: historyProcessors,
_meta: {
definitionVersion: definition.version,
miltonhultgren marked this conversation as resolved.
Show resolved Hide resolved
},
}),
{ logger }
);
Expand All @@ -49,6 +52,9 @@ export async function createAndInstallLatestIngestPipeline(
esClient.ingest.putPipeline({
id: latestId,
processors: latestProcessors,
_meta: {
definitionVersion: definition.version,
miltonhultgren marked this conversation as resolved.
Show resolved Hide resolved
},
}),
{ logger }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { entityDefinitionSchema } from '@kbn/entities-schema';
export const entityDefinition = entityDefinitionSchema.parse({
id: 'admin-console-services',
version: '999.999.999',
name: 'Services for Admin Console',
type: 'service',
indexPatterns: ['kbn-data-forge-fake_stack.*'],
Expand Down

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 @@ -63,6 +63,18 @@ export function generateHistoryProcessors(definition: EntityDefinition) {
value: definition.id,
},
},
{
set: {
field: 'entity.definitionVersion',
value: definition.version,
},
},
{
set: {
field: 'entity.schemaVersion',
value: 'v1',
miltonhultgren marked this conversation as resolved.
Show resolved Hide resolved
},
},
{
set: {
field: 'entity.displayName',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ export function generateLatestProcessors(definition: EntityDefinition) {
value: definition.id,
},
},
{
set: {
field: 'entity.definitionVersion',
value: definition.version,
},
},
{
set: {
field: 'entity.schemaVersion',
value: 'v1',
miltonhultgren marked this conversation as resolved.
Show resolved Hide resolved
},
},
...(definition.staticFields != null
? Object.keys(definition.staticFields).map((field) => ({
set: { field, value: definition.staticFields![field] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ const assertHasCreatedDefinition = (
expect(esClient.ingest.putPipeline).toBeCalledWith({
id: generateHistoryIngestPipelineId(builtInServicesEntityDefinition),
processors: expect.anything(),
_meta: {
definitionVersion: '1.0.0',
},
});
expect(esClient.ingest.putPipeline).toBeCalledWith({
id: generateLatestIngestPipelineId(builtInServicesEntityDefinition),
processors: expect.anything(),
_meta: {
definitionVersion: '1.0.0',
},
});

expect(esClient.transform.putTransform).toBeCalledTimes(2);
Expand Down

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 @@ -32,6 +32,9 @@ export function generateHistoryTransform(

return {
transform_id: generateHistoryTransformId(definition),
_meta: {
definitionVersion: definition.version,
miltonhultgren marked this conversation as resolved.
Show resolved Hide resolved
},
defer_validation: true,
source: {
index: definition.indexPatterns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export function generateLatestTransform(
): TransformPutTransformRequest {
return {
transform_id: generateLatestTransformId(definition),
_meta: {
definitionVersion: definition.version,
miltonhultgren marked this conversation as resolved.
Show resolved Hide resolved
},
defer_validation: true,
source: {
index: `${generateHistoryIndexName(definition)}.*`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const entityDefinition: SavedObjectsType = {
dynamic: false,
properties: {
id: { type: 'keyword' },
version: { type: 'keyword' },
miltonhultgren marked this conversation as resolved.
Show resolved Hide resolved
name: { type: 'text' },
description: { type: 'text' },
type: { type: 'keyword' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export const entitiesEntityComponentTemplateConfig: ClusterPutComponentTemplateR
ignore_above: 1024,
type: 'keyword',
},
definitionVersion: {
ignore_above: 1024,
type: 'keyword',
},
schemaVersion: {
ignore_above: 1024,
type: 'keyword',
},
lastSeenTimestamp: {
type: 'date',
},
Expand Down
Loading