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

[8.x] [eem] remove history transforms (#193999) #195680

Merged
merged 1 commit into from
Oct 9, 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
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
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({
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(
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;
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 @@ -18,11 +18,10 @@ export const builtInServicesFromEcsEntityDefinition: EntityDefinition =
type: 'service',
managed: true,
indexPatterns: ['logs-*', 'filebeat*', 'traces-apm*'],
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
Loading