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] rename fields to snake case (#195895) #197527

Merged
merged 1 commit into from
Oct 23, 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 @@ -15,8 +15,8 @@ class ContainerEntity extends Serializable<EntityFields> {
super({
...fields,
'entity.type': 'container',
'entity.definitionId': 'builtin_containers_from_ecs_data',
'entity.identityFields': ['container.id'],
'entity.definition_id': 'builtin_containers_from_ecs_data',
'entity.identity_fields': ['container.id'],
});
}
}
Expand All @@ -36,7 +36,7 @@ export function containerEntity({
'source_data_stream.type': dataStreamType,
'agent.name': agentName,
'container.id': containerId,
'entity.displayName': containerId,
'entity.display_name': containerId,
'entity.id': entityId,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class HostEntity extends Serializable<EntityFields> {
super({
...fields,
'entity.type': 'host',
'entity.definitionId': 'builtin_hosts_from_ecs_data',
'entity.identityFields': ['host.name'],
'entity.definition_id': 'builtin_hosts_from_ecs_data',
'entity.identity_fields': ['host.name'],
});
}
}
Expand All @@ -36,7 +36,7 @@ export function hostEntity({
'source_data_stream.type': dataStreamType,
'agent.name': agentName,
'host.name': hostName,
'entity.displayName': hostName,
'entity.display_name': hostName,
'entity.id': entityId,
});
}
14 changes: 7 additions & 7 deletions packages/kbn-apm-synthtrace-client/src/lib/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export type EntityFields = Fields &
'source_data_stream.type': string | string[];
'source_data_stream.dataset': string | string[];
'event.ingested': string;
sourceIndex: string;
'entity.lastSeenTimestamp': string;
'entity.schemaVersion': string;
'entity.definitionVersion': string;
'entity.displayName': string;
'entity.identityFields': string | string[];
source_index: string;
'entity.last_seen_timestamp': string;
'entity.schema_version': string;
'entity.definition_version': string;
'entity.display_name': string;
'entity.identity_fields': string | string[];
'entity.id': string;
'entity.type': string;
'entity.definitionId': string;
'entity.definition_id': string;
[key: string]: any;
}>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class ServiceEntity extends Serializable<EntityFields> {
super({
...fields,
'entity.type': 'service',
'entity.definitionId': 'builtin_services_from_ecs_data',
'entity.identityFields': ['service.name'],
'entity.definition_id': 'builtin_services_from_ecs_data',
'entity.identity_fields': ['service.name'],
});
}
}
Expand All @@ -36,7 +36,7 @@ export function serviceEntity({
}) {
return new ServiceEntity({
'service.name': serviceName,
'entity.displayName': serviceName,
'entity.display_name': serviceName,
'service.environment': environment,
'source_data_stream.type': dataStreamType,
'agent.name': agentName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function lastSeenTimestampTransform() {
const timestamp = document['@timestamp'];
if (timestamp) {
const isoString = new Date(timestamp).toISOString();
document['entity.lastSeenTimestamp'] = isoString;
document['entity.last_seen_timestamp'] = isoString;
document['event.ingested'] = isoString;
delete document['@timestamp'];
}
Expand Down
13 changes: 6 additions & 7 deletions packages/kbn-investigation-shared/src/rest_specs/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ const metricsSchema = z.object({

const entitySchema = z.object({
id: z.string(),
definitionId: z.string(),
definitionVersion: z.string(),
displayName: z.string(),
firstSeenTimestamp: z.string(),
lastSeenTimestamp: z.string(),
identityFields: z.array(z.string()),
schemaVersion: z.string(),
definition_id: z.string(),
definition_version: z.string(),
display_name: z.string(),
last_seen_timestamp: z.string(),
identity_fields: z.array(z.string()),
schema_version: z.string(),
type: z.string(),
metrics: metricsSchema,
});
Expand Down
20 changes: 8 additions & 12 deletions x-pack/packages/kbn-entities-schema/src/schema/entity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@ import { entityLatestSchema, entityMetadataSchema } from './entity';

const entity = {
entity: {
lastSeenTimestamp: '2024-08-06T17:03:50.722Z',
schemaVersion: 'v1',
definitionVersion: '999.999.999',
displayName: 'message_processor',
identityFields: ['log.logger', 'event.category'],
last_seen_timestamp: '2024-08-06T17:03:50.722Z',
schema_version: 'v1',
definition_version: '999.999.999',
display_name: 'message_processor',
identity_fields: ['log.logger', 'event.category'],
id: '6UHVPiduEC2qk6rMjs1Jzg==',
metrics: {
logRate: 100,
errorRate: 0,
},
type: 'service',
firstSeenTimestamp: '2024-08-06T16:50:00.000Z',
definitionId: 'admin-console-services',
metrics: {},
definition_id: 'admin-console-services',
},
};

Expand All @@ -47,7 +43,7 @@ const metadata = {
ingested: '2024-08-06T17:06:24.444700Z',
category: '',
},
sourceIndex: ['kbn-data-forge-fake_stack.message_processor-2024-08-01'],
source_index: ['kbn-data-forge-fake_stack.message_processor-2024-08-01'],
log: {
logger: 'message_processor',
},
Expand Down
19 changes: 6 additions & 13 deletions x-pack/packages/kbn-entities-schema/src/schema/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { arrayOfStringsSchema } from './common';
export const entityBaseSchema = z.object({
id: z.string(),
type: z.string(),
identityFields: arrayOfStringsSchema,
displayName: z.string(),
identity_fields: arrayOfStringsSchema,
display_name: z.string(),
metrics: z.record(z.string(), z.number()),
definitionVersion: z.string(),
schemaVersion: z.string(),
definitionId: z.string(),
definition_version: z.string(),
schema_version: z.string(),
definition_id: z.string(),
});

export interface MetadataRecord {
Expand All @@ -34,15 +34,8 @@ export const entityLatestSchema = z
.object({
entity: entityBaseSchema.merge(
z.object({
lastSeenTimestamp: z.string(),
last_seen_timestamp: z.string(),
})
),
})
.and(entityMetadataSchema);

export const entityHistorySchema = z
.object({
'@timestamp': z.string(),
entity: entityBaseSchema,
})
.and(entityMetadataSchema);
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const entityDefinitionRuntimePrivileges = {
index: [
{
names: [ENTITY_INTERNAL_INDICES_PATTERN],
privileges: ['create_index', 'index', 'create_doc', 'auto_configure', 'read'],
privileges: ['create_index', 'delete_index', 'index', 'create_doc', 'auto_configure', 'read'],
},
{
names: [...BUILT_IN_ALLOWED_INDICES, ENTITY_INTERNAL_INDICES_PATTERN],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const builtInServicesFromEcsEntityDefinition: EntityDefinition =
identityFields: ['service.name'],
displayNameTemplate: '{{service.name}}',
metadata: [
{ source: '_index', destination: 'sourceIndex' },
{ source: '_index', destination: 'source_index' },
{
source: 'data_stream.type',
destination: 'source_data_stream.type',
Expand All @@ -38,7 +38,7 @@ export const builtInServicesFromEcsEntityDefinition: EntityDefinition =
source: 'data_stream.dataset',
destination: 'source_data_stream.dataset',
},
{ source: 'agent.name', aggregation: { type: 'terms', limit: 100 } },
'agent.name',
'service.environment',
'service.name',
'service.namespace',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function createAndInstallIngestPipelines(
id: latestId,
processors: latestProcessors,
_meta: {
definitionVersion: definition.version,
definition_version: definition.version,
managed: definition.managed,
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ export async function deleteIndices(
definition: EntityDefinition,
logger: Logger
) {
const index = generateLatestIndexName(definition);
try {
const index = generateLatestIndexName(definition);
await esClient.indices.delete({ index, ignore_unavailable: true });
} catch (e) {
logger.error(`Unable to remove entity definition index [${definition.id}}]`);
logger.error(
`Unable to remove entity definition index ${index} for definition [${definition.id}]`
);
throw e;
}
}

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 @@ -117,25 +117,25 @@ export function generateLatestProcessors(definition: EntityDefinition) {
},
{
set: {
field: 'entity.definitionId',
field: 'entity.definition_id',
value: definition.id,
},
},
{
set: {
field: 'entity.definitionVersion',
field: 'entity.definition_version',
value: definition.version,
},
},
{
set: {
field: 'entity.schemaVersion',
field: 'entity.schema_version',
value: ENTITY_SCHEMA_VERSION_V1,
},
},
{
set: {
field: 'entity.identityFields',
field: 'entity.identity_fields',
value: definition.identityFields.map((identityField) => identityField.field),
},
},
Expand Down Expand Up @@ -173,7 +173,7 @@ export function generateLatestProcessors(definition: EntityDefinition) {
// This must happen AFTER we lift the identity fields into the root of the document
{
set: {
field: 'entity.displayName',
field: 'entity.display_name',
value: definition.displayNameTemplate,
},
},
Expand Down
Loading