-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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][POC] The POC for creating entity-centric indices using entity definitions #183205
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
697bb09
[OAM][POC] The POC for creating entity centric indices using asset de…
simianhacker 575f133
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 8b56d03
Use id generators
simianhacker 131bfcd
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine cd05235
Adding await
simianhacker 18a273a
Applying feedback from Tom
simianhacker 784cd84
fixing typo
simianhacker 972a131
Add awaits
simianhacker df69a9a
changing from /api/oam to /api/entities
simianhacker c5abf46
swapping out asset for entity
simianhacker 230d0c0
Renaming OAM to entities; renaming asset to entity
simianhacker c2953ea
changing index name to summary from entity
simianhacker 1998069
Moving kbn-oam-schema to kbn-entities-schema
simianhacker 8fb5651
Implimenting optional identity fields
simianhacker d7baba0
Merge branch 'main' of github.com:elastic/kibana into oam-poc
simianhacker 421d5ca
Fixing type check for index templates
simianhacker 4a53db8
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @kbn/entities-schema | ||
|
||
The entities schema for the asset model for Observability | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export * from './src/schema/entity_definition'; | ||
export * from './src/schema/entity'; | ||
export * from './src/schema/common'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../..', | ||
roots: ['<rootDir>/x-pack/packages/kbn-entities-schema'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/entities-schema", | ||
"owner": "@elastic/obs-knowledge-team" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@kbn/entities-schema", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "Elastic License 2.0" | ||
} |
106 changes: 106 additions & 0 deletions
106
x-pack/packages/kbn-entities-schema/src/schema/common.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* 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 { z } from 'zod'; | ||
import moment from 'moment'; | ||
|
||
export enum EntityType { | ||
service = 'service', | ||
host = 'host', | ||
pod = 'pod', | ||
node = 'node', | ||
} | ||
|
||
export const arrayOfStringsSchema = z.array(z.string()); | ||
|
||
export const entityTypeSchema = z.nativeEnum(EntityType); | ||
|
||
export enum BasicAggregations { | ||
avg = 'avg', | ||
max = 'max', | ||
min = 'min', | ||
sum = 'sum', | ||
cardinality = 'cardinality', | ||
last_value = 'last_value', | ||
std_deviation = 'std_deviation', | ||
} | ||
|
||
export const basicAggregationsSchema = z.nativeEnum(BasicAggregations); | ||
|
||
const metricNameSchema = z | ||
.string() | ||
.length(1) | ||
.regex(/[a-zA-Z]/) | ||
.toUpperCase(); | ||
|
||
export const filterSchema = z.optional(z.string()); | ||
|
||
export const basicMetricWithFieldSchema = z.object({ | ||
name: metricNameSchema, | ||
aggregation: basicAggregationsSchema, | ||
field: z.string(), | ||
filter: filterSchema, | ||
}); | ||
|
||
export const docCountMetricSchema = z.object({ | ||
name: metricNameSchema, | ||
aggregation: z.literal('doc_count'), | ||
filter: filterSchema, | ||
}); | ||
|
||
export const durationSchema = z | ||
.string() | ||
.regex(/\d+[m|d|s|h]/) | ||
.transform((val: string) => { | ||
const parts = val.match(/(\d+)([m|s|h|d])/); | ||
if (parts === null) { | ||
throw new Error('Unable to parse duration'); | ||
} | ||
const value = parseInt(parts[1], 10); | ||
const unit = parts[2] as 'm' | 's' | 'h' | 'd'; | ||
const duration = moment.duration(value, unit); | ||
return { ...duration, toJSON: () => val }; | ||
}); | ||
|
||
export const percentileMetricSchema = z.object({ | ||
name: metricNameSchema, | ||
aggregation: z.literal('percentile'), | ||
field: z.string(), | ||
percentile: z.number(), | ||
filter: filterSchema, | ||
}); | ||
|
||
export const metricSchema = z.discriminatedUnion('aggregation', [ | ||
basicMetricWithFieldSchema, | ||
docCountMetricSchema, | ||
percentileMetricSchema, | ||
]); | ||
|
||
export type Metric = z.infer<typeof metricSchema>; | ||
|
||
export const keyMetricSchema = z.object({ | ||
name: z.string(), | ||
metrics: z.array(metricSchema), | ||
equation: z.string(), | ||
}); | ||
|
||
export type KeyMetric = z.infer<typeof keyMetricSchema>; | ||
|
||
export const metadataSchema = z | ||
.object({ | ||
source: z.string(), | ||
destination: z.optional(z.string()), | ||
limit: z.optional(z.number().default(1000)), | ||
}) | ||
.or(z.string().transform((value) => ({ source: value, destination: value, limit: 1000 }))); | ||
|
||
export const identityFieldsSchema = z | ||
.object({ | ||
field: z.string(), | ||
optional: z.boolean(), | ||
}) | ||
.or(z.string().transform((value) => ({ field: value, optional: false }))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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 { z } from 'zod'; | ||
import { arrayOfStringsSchema } from './common'; | ||
|
||
export const entitySchema = z.intersection( | ||
z.object({ | ||
entity: z.object({ | ||
id: z.string(), | ||
indexPatterns: arrayOfStringsSchema, | ||
identityFields: arrayOfStringsSchema, | ||
metric: z.record(z.string(), z.number()), | ||
}), | ||
}), | ||
z.record(z.string(), z.string().or(z.number())) | ||
); |
42 changes: 42 additions & 0 deletions
42
x-pack/packages/kbn-entities-schema/src/schema/entity_definition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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 { z } from 'zod'; | ||
import { | ||
arrayOfStringsSchema, | ||
entityTypeSchema, | ||
keyMetricSchema, | ||
metadataSchema, | ||
filterSchema, | ||
durationSchema, | ||
identityFieldsSchema, | ||
} from './common'; | ||
|
||
export const entityDefinitionSchema = z.object({ | ||
id: z.string().regex(/^[\w-]+$/), | ||
name: z.string(), | ||
description: z.optional(z.string()), | ||
type: entityTypeSchema, | ||
filter: filterSchema, | ||
indexPatterns: arrayOfStringsSchema, | ||
identityFields: z.array(identityFieldsSchema), | ||
identityTemplate: z.string(), | ||
metadata: z.optional(z.array(metadataSchema)), | ||
metrics: z.optional(z.array(keyMetricSchema)), | ||
staticFields: z.optional(z.record(z.string(), z.string())), | ||
lookback: durationSchema, | ||
timestampField: z.string(), | ||
settings: z.optional( | ||
z.object({ | ||
syncField: z.optional(z.string()), | ||
syncDelay: z.optional(z.string()), | ||
frequency: z.optional(z.string()), | ||
}) | ||
), | ||
}); | ||
|
||
export type EntityDefinition = z.infer<typeof entityDefinitionSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "target/types", | ||
"types": [ | ||
"jest", | ||
"node" | ||
] | ||
}, | ||
"include": [ | ||
"**/*.ts" | ||
], | ||
"exclude": [ | ||
"target/**/*" | ||
], | ||
"kbn_references": [ | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
x-pack/plugins/observability_solution/asset_manager/common/constants_entities.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
|
||
export const ENTITY_VERSION = 'v1'; | ||
export const ENTITY_BASE_PREFIX = `.entities-observability.summary-${ENTITY_VERSION}`; | ||
export const ENTITY_TRANSFORM_PREFIX = `entities-observability-summary-${ENTITY_VERSION}`; | ||
export const ENTITY_DEFAULT_FREQUENCY = '1m'; | ||
export const ENTITY_DEFAULT_SYNC_DELAY = '60s'; | ||
export const ENTITY_API_PREFIX = '/api/entities'; |
39 changes: 39 additions & 0 deletions
39
...vability_solution/asset_manager/server/lib/entities/create_and_install_ingest_pipeline.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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 { ElasticsearchClient, Logger } from '@kbn/core/server'; | ||
import { EntityDefinition } from '@kbn/entities-schema'; | ||
import { generateProcessors } from './ingest_pipeline/generate_processors'; | ||
import { retryTransientEsErrors } from './helpers/retry'; | ||
import { EntitySecurityException } from './errors/entity_security_exception'; | ||
import { generateIngestPipelineId } from './ingest_pipeline/generate_ingest_pipeline_id'; | ||
|
||
export async function createAndInstallIngestPipeline( | ||
esClient: ElasticsearchClient, | ||
definition: EntityDefinition, | ||
logger: Logger | ||
) { | ||
const processors = generateProcessors(definition); | ||
const id = generateIngestPipelineId(definition); | ||
try { | ||
await retryTransientEsErrors( | ||
() => | ||
esClient.ingest.putPipeline({ | ||
id, | ||
processors, | ||
}), | ||
{ logger } | ||
); | ||
} catch (e) { | ||
logger.error(`Cannot create entity ingest pipeline for [${definition.id}] entity defintion`); | ||
if (e.meta?.body?.error?.type === 'security_exception') { | ||
throw new EntitySecurityException(e.meta.body.error.reason, definition); | ||
} | ||
throw e; | ||
} | ||
return id; | ||
} |
30 changes: 30 additions & 0 deletions
30
.../observability_solution/asset_manager/server/lib/entities/create_and_install_transform.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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 { ElasticsearchClient, Logger } from '@kbn/core/server'; | ||
import { EntityDefinition } from '@kbn/entities-schema'; | ||
import { generateTransform } from './transform/generate_transform'; | ||
import { retryTransientEsErrors } from './helpers/retry'; | ||
import { EntitySecurityException } from './errors/entity_security_exception'; | ||
|
||
export async function createAndInstallTransform( | ||
esClient: ElasticsearchClient, | ||
definition: EntityDefinition, | ||
logger: Logger | ||
) { | ||
const transform = generateTransform(definition); | ||
try { | ||
await retryTransientEsErrors(() => esClient.transform.putTransform(transform), { logger }); | ||
} catch (e) { | ||
logger.error(`Cannot create entity transform for [${definition.id}] entity definition`); | ||
if (e.meta?.body?.error?.type === 'security_exception') { | ||
throw new EntitySecurityException(e.meta.body.error.reason, definition); | ||
} | ||
throw e; | ||
} | ||
return transform.transform_id; | ||
} |
31 changes: 31 additions & 0 deletions
31
...gins/observability_solution/asset_manager/server/lib/entities/delete_entity_definition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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 { Logger, SavedObjectsClientContract } from '@kbn/core/server'; | ||
import { EntityDefinition } from '@kbn/entities-schema'; | ||
import { SO_ENTITY_DEFINITION_TYPE } from '../../saved_objects'; | ||
import { EntityDefinitionNotFound } from './errors/entity_not_found'; | ||
|
||
export async function deleteEntityDefinition( | ||
soClient: SavedObjectsClientContract, | ||
definition: EntityDefinition, | ||
logger: Logger | ||
) { | ||
const response = await soClient.find<EntityDefinition>({ | ||
type: SO_ENTITY_DEFINITION_TYPE, | ||
page: 1, | ||
perPage: 1, | ||
filter: `${SO_ENTITY_DEFINITION_TYPE}.attributes.id:(${definition.id})`, | ||
}); | ||
|
||
if (response.total === 0) { | ||
logger.error(`Unable to delete entity definition [${definition.id}] because it doesn't exist.`); | ||
throw new EntityDefinitionNotFound(`Entity defintion with [${definition.id}] not found.`); | ||
} | ||
|
||
await soClient.delete(SO_ENTITY_DEFINITION_TYPE, response.saved_objects[0].id); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can leave this 'asset' here just for historical interest 🪦