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] remove history transforms #193999

Merged
merged 34 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7359805
remove history transform
klacabane Sep 25, 2024
46423e5
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Sep 25, 2024
be50f9d
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Sep 26, 2024
87f2632
fix tests
klacabane Sep 26, 2024
c1cf4c7
Merge branch 'main' into 173-remove-history-transforms
klacabane Sep 26, 2024
f01a8a0
fix aggs
klacabane Sep 26, 2024
8d0df93
latest lookbackPeriod
klacabane Sep 26, 2024
eef049e
remove ccs index
klacabane Sep 26, 2024
238a3c9
fix tests
klacabane Sep 26, 2024
1d9441e
fix tests
klacabane Sep 26, 2024
6cb7e26
fix security tests
klacabane Sep 26, 2024
9f43b89
update validate_transform_ids
klacabane Sep 26, 2024
32f33f7
remove deprecated files
klacabane Sep 27, 2024
97c0270
fix tests
klacabane Sep 27, 2024
7ea3236
fix tests
klacabane Sep 27, 2024
eb3a923
fix test
klacabane Sep 27, 2024
c2a163d
fix test
klacabane Sep 28, 2024
31cd18a
update snapshots
klacabane Sep 28, 2024
3f28a24
Merge branch 'main' into 173-remove-history-transforms
klacabane Sep 28, 2024
ad391ae
Merge branch 'main' into 173-remove-history-transforms
klacabane Sep 30, 2024
b2e80c0
Merge branch 'main' into 173-remove-history-transforms
klacabane Oct 2, 2024
e379a12
remove interval
klacabane Oct 4, 2024
5f458dd
Merge branch 'main' into 173-remove-history-transforms
klacabane Oct 4, 2024
5fc1130
Merge branch 'main' into 173-remove-history-transforms
klacabane Oct 7, 2024
6a457c4
remove firstSeenTimestamp investigate_app
klacabane Oct 7, 2024
60d9ec4
Merge branch 'main' into 173-remove-history-transforms
klacabane Oct 7, 2024
f2afe29
Merge branch 'main' into 173-remove-history-transforms
klacabane Oct 8, 2024
5ddf79b
Merge branch 'main' into 173-remove-history-transforms
hop-dev Oct 8, 2024
ef2abd2
fix entity analytics tests
klacabane Oct 9, 2024
73f0a7d
Merge branch 'main' into 173-remove-history-transforms
klacabane Oct 9, 2024
6d189dd
remove interval option
klacabane Oct 9, 2024
55dae11
Merge branch 'main' into 173-remove-history-transforms
klacabane Oct 9, 2024
99ebedc
Merge branch 'main' into 173-remove-history-transforms
klacabane Oct 9, 2024
02ca50e
Merge branch 'main' into 173-remove-history-transforms
klacabane Oct 9, 2024
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
Expand Up @@ -91,7 +91,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"endpoint:unified-user-artifact-manifest": "71c7fcb52c658b21ea2800a6b6a76972ae1c776e",
"endpoint:user-artifact-manifest": "1c3533161811a58772e30cdc77bac4631da3ef2b",
"enterprise_search_telemetry": "9ac912e1417fc8681e0cd383775382117c9e3d3d",
"entity-definition": "61be3e95966045122b55e181bb39658b1dc9bbe9",
"entity-definition": "e3811fd5fbb878d170067c0d6897a2e63010af36",
"entity-discovery-api-key": "c267a65c69171d1804362155c1378365f5acef88",
"entity-engine-status": "0738aa1a06d3361911740f8f166071ea43a00927",
"epm-packages": "8042d4a1522f6c4e6f5486e791b3ffe3a22f88fd",
Expand Down

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

30 changes: 2 additions & 28 deletions x-pack/packages/kbn-entities-schema/src/schema/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { durationSchema, metadataSchema, semVerSchema, historySettingsSchema } from './common';
import { durationSchema, metadataSchema, semVerSchema } from './common';

describe('schemas', () => {
describe('metadataSchema', () => {
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('schemas', () => {
expect(result.data).toEqual({
source: 'host.name',
destination: 'hostName',
aggregation: { type: 'terms', limit: 1000 },
aggregation: { type: 'terms', limit: 10, lookbackPeriod: undefined },
});
});

Expand Down Expand Up @@ -139,30 +139,4 @@ describe('schemas', () => {
expect(result).toMatchSnapshot();
});
});

describe('historySettingsSchema', () => {
it('should return default values when not defined', () => {
let result = historySettingsSchema.safeParse(undefined);
expect(result.success).toBeTruthy();
expect(result.data).toEqual({ lookbackPeriod: '1h' });

result = historySettingsSchema.safeParse({ syncDelay: '1m' });
expect(result.success).toBeTruthy();
expect(result.data).toEqual({ syncDelay: '1m', lookbackPeriod: '1h' });
});

it('should return user defined values when defined', () => {
const result = historySettingsSchema.safeParse({
lookbackPeriod: '30m',
syncField: 'event.ingested',
syncDelay: '5m',
});
expect(result.success).toBeTruthy();
expect(result.data).toEqual({
lookbackPeriod: '30m',
syncField: 'event.ingested',
syncDelay: '5m',
});
});
});
});
10 changes: 7 additions & 3 deletions x-pack/packages/kbn-entities-schema/src/schema/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ export const keyMetricSchema = z.object({
export type KeyMetric = z.infer<typeof keyMetricSchema>;

export const metadataAggregation = z.union([
z.object({ type: z.literal('terms'), limit: z.number().default(1000) }),
z.object({
type: z.literal('terms'),
limit: z.number().default(10),
lookbackPeriod: z.optional(durationSchema),
}),
z.object({
type: z.literal('top_value'),
sort: z.record(z.string(), z.union([z.literal('asc'), z.literal('desc')])),
Expand All @@ -99,13 +103,13 @@ export const metadataSchema = z
destination: z.optional(z.string()),
aggregation: z
.optional(metadataAggregation)
.default({ type: z.literal('terms').value, limit: 1000 }),
.default({ type: z.literal('terms').value, limit: 10, lookbackPeriod: undefined }),
})
.or(
z.string().transform((value) => ({
source: value,
destination: value,
aggregation: { type: z.literal('terms').value, limit: 1000 },
aggregation: { type: z.literal('terms').value, limit: 10, lookbackPeriod: undefined },
}))
)
.transform((metadata) => ({
Expand Down
1 change: 0 additions & 1 deletion x-pack/packages/kbn-entities-schema/src/schema/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const entityLatestSchema = z
entity: entityBaseSchema.merge(
z.object({
lastSeenTimestamp: z.string(),
firstSeenTimestamp: z.string(),
})
),
})
Expand Down
39 changes: 22 additions & 17 deletions x-pack/packages/kbn-entities-schema/src/schema/entity_definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {
durationSchema,
identityFieldsSchema,
semVerSchema,
historySettingsSchema,
durationSchemaWithMinimum,
} from './common';

export const entityDefinitionSchema = z.object({
Expand All @@ -32,22 +30,17 @@ export const entityDefinitionSchema = z.object({
metrics: z.optional(z.array(keyMetricSchema)),
staticFields: z.optional(z.record(z.string(), z.string())),
managed: z.optional(z.boolean()).default(false),
history: z.object({
Copy link
Member

Choose a reason for hiding this comment

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

Q: Since we're dropping this (previously required) field.

What would occur in the event of a rollback (if we have to revert to the current version after deploying the version including these changes, and having created a few entities)?

Will the newly formatted entities be considered corrupt by Kibana?
If so, can Kibana self-recover? Or will users suffer from data loss?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a few difference regarding how the fields are aggregated in the new version, but overall entities keep the same schema (minus one field that's removed in the new version), so rollback/rollforward would be seamless as far as stored documents goes.

The entity definitions installed in the new version would be somewhat broken in the rolled back environment (few apis won't be able to interact with those). I didn't implement a good story for this since 1. this is tech preview 2. we don't have released product built on these yet.

Where can I read about our rollback strategy ?

Copy link
Member

Choose a reason for hiding this comment

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

@kobelb, @rudolf, with those premises (unreleased tech preview), is it OK to make these changes in our SO schema?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@afharo @kobelb @rudolf are we fine with this ?

Copy link
Contributor

Choose a reason for hiding this comment

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

At the end of the day making breaking changes to internal APIs or disrupting the UI during a rollback is a product decision. The team responsible for it is best able to make this tradeoff. The important thing is that we do weigh up such customer impact instead of just shipping something. It sounds like the team has done this 👍🏻

latest: z.object({
timestampField: z.string(),
interval: durationSchemaWithMinimum(1),
settings: historySettingsSchema,
lookbackPeriod: z.optional(durationSchema).default('24h'),
settings: z.optional(
z.object({
syncField: z.optional(z.string()),
syncDelay: z.optional(durationSchema),
frequency: z.optional(durationSchema),
})
),
}),
latest: z.optional(
z.object({
settings: z.optional(
z.object({
syncField: z.optional(z.string()),
syncDelay: z.optional(durationSchema),
frequency: z.optional(durationSchema),
})
),
})
),
installStatus: z.optional(
z.union([
z.literal('installing'),
Expand All @@ -57,6 +50,18 @@ export const entityDefinitionSchema = z.object({
])
),
installStartedAt: z.optional(z.string()),
installedComponents: z.optional(
Copy link
Contributor Author

@klacabane klacabane Sep 30, 2024

Choose a reason for hiding this comment

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

this allows cleaning up versions of definitions that contain history components

z.array(
z.object({
type: z.union([
z.literal('transform'),
z.literal('ingest_pipeline'),
z.literal('template'),
]),
id: z.string(),
})
)
),
});

export const entityDefinitionUpdateSchema = entityDefinitionSchema
Expand All @@ -69,7 +74,7 @@ export const entityDefinitionUpdateSchema = entityDefinitionSchema
.partial()
.merge(
z.object({
history: z.optional(entityDefinitionSchema.shape.history.partial()),
latest: z.optional(entityDefinitionSchema.shape.latest.partial()),
version: semVerSchema,
})
);
Expand Down
8 changes: 3 additions & 5 deletions x-pack/plugins/entity_manager/common/constants_entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export const ENTITY_LATEST_PREFIX_V1 =
`${ENTITY_BASE_PREFIX}-${ENTITY_SCHEMA_VERSION_V1}-${ENTITY_LATEST}` as const;

// Transform constants
export const ENTITY_DEFAULT_HISTORY_FREQUENCY = '1m';
export const ENTITY_DEFAULT_HISTORY_SYNC_DELAY = '60s';
export const ENTITY_DEFAULT_LATEST_FREQUENCY = '30s';
export const ENTITY_DEFAULT_LATEST_SYNC_DELAY = '1s';
export const ENTITY_DEFAULT_METADATA_LIMIT = 1000;
export const ENTITY_DEFAULT_LATEST_FREQUENCY = '1m';
export const ENTITY_DEFAULT_LATEST_SYNC_DELAY = '60s';
export const ENTITY_DEFAULT_METADATA_LIMIT = 10;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

took the opportunity to reduce the default limit

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export const builtInContainersFromEcsEntityDefinition: EntityDefinition =
indexPatterns: ['filebeat-*', 'logs-*', 'metrics-*', 'metricbeat-*'],
identityFields: ['container.id'],
displayNameTemplate: '{{container.id}}',
history: {
latest: {
timestampField: '@timestamp',
interval: '5m',
lookbackPeriod: '10m',
settings: {
frequency: '5m',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const builtInHostsFromEcsEntityDefinition: EntityDefinition = entityDefin
indexPatterns: ['filebeat-*', 'logs-*', 'metrics-*', 'metricbeat-*'],
identityFields: ['host.name'],
displayNameTemplate: '{{host.name}}',
history: {
latest: {
timestampField: '@timestamp',
interval: '5m',
lookbackPeriod: '10m',
settings: {
frequency: '5m',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ export const builtInServicesFromEcsEntityDefinition: EntityDefinition =
'metrics-apm.service_transaction.1m*',
'metrics-apm.service_summary.1m*',
],
history: {
latest: {
timestampField: '@timestamp',
interval: '1m',
lookbackPeriod: '10m',
settings: {
lookbackPeriod: '10m',
frequency: '2m',
syncDelay: '2m',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,15 @@

import { ElasticsearchClient, Logger } from '@kbn/core/server';
import { EntityDefinition } from '@kbn/entities-schema';
import {
generateHistoryIngestPipelineId,
generateLatestIngestPipelineId,
} from './helpers/generate_component_id';
import { generateLatestIngestPipelineId } from './helpers/generate_component_id';
import { retryTransientEsErrors } from './helpers/retry';
import { generateHistoryProcessors } from './ingest_pipeline/generate_history_processors';
import { generateLatestProcessors } from './ingest_pipeline/generate_latest_processors';

export async function createAndInstallHistoryIngestPipeline(
export async function createAndInstallIngestPipelines(
esClient: ElasticsearchClient,
definition: EntityDefinition,
logger: Logger
) {
try {
const historyProcessors = generateHistoryProcessors(definition);
const historyId = generateHistoryIngestPipelineId(definition);
await retryTransientEsErrors(
() =>
esClient.ingest.putPipeline({
id: historyId,
processors: historyProcessors,
_meta: {
definitionVersion: definition.version,
managed: definition.managed,
},
}),
{ logger }
);
} catch (e) {
logger.error(
`Cannot create entity history ingest pipelines for [${definition.id}] entity defintion`
);
throw e;
}
}
export async function createAndInstallLatestIngestPipeline(
esClient: ElasticsearchClient,
definition: EntityDefinition,
logger: Logger
) {
): Promise<Array<{ type: 'ingest_pipeline'; id: string }>> {
try {
const latestProcessors = generateLatestProcessors(definition);
const latestId = generateLatestIngestPipelineId(definition);
Expand All @@ -62,9 +31,10 @@ export async function createAndInstallLatestIngestPipeline(
}),
{ logger }
);
return [{ type: 'ingest_pipeline', id: latestId }];
} catch (e) {
logger.error(
`Cannot create entity latest ingest pipelines for [${definition.id}] entity defintion`
`Cannot create entity latest ingest pipelines for [${definition.id}] entity definition`
);
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,20 @@ import { ElasticsearchClient, Logger } from '@kbn/core/server';
import { EntityDefinition } from '@kbn/entities-schema';
import { retryTransientEsErrors } from './helpers/retry';
import { generateLatestTransform } from './transform/generate_latest_transform';
import {
generateBackfillHistoryTransform,
generateHistoryTransform,
} from './transform/generate_history_transform';

export async function createAndInstallHistoryTransform(
export async function createAndInstallTransforms(
esClient: ElasticsearchClient,
definition: EntityDefinition,
logger: Logger
) {
try {
const historyTransform = generateHistoryTransform(definition);
await retryTransientEsErrors(() => esClient.transform.putTransform(historyTransform), {
logger,
});
} catch (e) {
logger.error(`Cannot create entity history transform for [${definition.id}] entity definition`);
throw e;
}
}

export async function createAndInstallHistoryBackfillTransform(
esClient: ElasticsearchClient,
definition: EntityDefinition,
logger: Logger
) {
try {
const historyTransform = generateBackfillHistoryTransform(definition);
await retryTransientEsErrors(() => esClient.transform.putTransform(historyTransform), {
logger,
});
} catch (e) {
logger.error(
`Cannot create entity history backfill transform for [${definition.id}] entity definition`
);
throw e;
}
}

export async function createAndInstallLatestTransform(
esClient: ElasticsearchClient,
definition: EntityDefinition,
logger: Logger
) {
): Promise<Array<{ type: 'transform'; id: string }>> {
try {
const latestTransform = generateLatestTransform(definition);
await retryTransientEsErrors(() => esClient.transform.putTransform(latestTransform), {
logger,
});
return [{ type: 'transform', id: latestTransform.transform_id }];
} catch (e) {
logger.error(`Cannot create entity latest transform for [${definition.id}] entity definition`);
logger.error(`Cannot create entity history transform for [${definition.id}] entity definition`);
throw e;
}
}
Loading