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] [Synthtrace] Adding Entities support (#196258) #196645

Merged
merged 2 commits into from
Oct 17, 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
2 changes: 1 addition & 1 deletion packages/kbn-apm-synthtrace-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ export { generateLongId, generateShortId } from './src/lib/utils/generate_id';
export { appendHash, hashKeysOf } from './src/lib/utils/hash';
export type { ESDocumentWithOperation, SynthtraceESAction, SynthtraceGenerator } from './src/types';
export { log, type LogDocument, LONG_FIELD_NAME } from './src/lib/logs';
export { type AssetDocument } from './src/lib/assets';
export { syntheticsMonitor, type SyntheticsMonitorDocument } from './src/lib/synthetics';
export { type EntityFields, entities } from './src/lib/entities';
27 changes: 0 additions & 27 deletions packages/kbn-apm-synthtrace-client/src/lib/assets/asset.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/kbn-apm-synthtrace-client/src/lib/assets/index.ts

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { EntityDataStreamType, EntityFields } from '.';
import { Serializable } from '../serializable';

class ContainerEntity extends Serializable<EntityFields> {
constructor(fields: EntityFields) {
super({
...fields,
'entity.type': 'container',
'entity.definitionId': 'latest',
});
}
}

export function containerEntity({
agentName,
dataStreamType,
dataStreamDataset,
containerId,
entityId,
}: {
agentName: string[];
dataStreamType: EntityDataStreamType[];
dataStreamDataset: string;
containerId: string;
entityId: string;
}) {
return new ContainerEntity({
'source_data_stream.type': dataStreamType,
'source_data_stream.dataset': dataStreamDataset,
'agent.name': agentName,
'container.id': containerId,
'entity.id': entityId,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { EntityDataStreamType, EntityFields } from '.';
import { Serializable } from '../serializable';

class HostEntity extends Serializable<EntityFields> {
constructor(fields: EntityFields) {
super({
...fields,
'entity.type': 'host',
'entity.definitionId': 'latest',
});
}
}

export function hostEntity({
agentName,
dataStreamType,
dataStreamDataset,
hostName,
entityId,
}: {
agentName: string[];
dataStreamType: EntityDataStreamType[];
dataStreamDataset: string;
hostName: string;
entityId: string;
}) {
return new HostEntity({
'source_data_stream.type': dataStreamType,
'source_data_stream.dataset': dataStreamDataset,
'agent.name': agentName,
'host.name': hostName,
'entity.id': entityId,
});
}
35 changes: 35 additions & 0 deletions packages/kbn-apm-synthtrace-client/src/lib/entities/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { Fields } from '../entity';
import { serviceEntity } from './service_entity';
import { hostEntity } from './host_entity';
import { containerEntity } from './container_entity';

export type EntityDataStreamType = 'metrics' | 'logs' | 'traces';

export type EntityFields = Fields &
Partial<{
'agent.name': string[];
'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[];
'entity.id': string;
'entity.type': string;
'entity.definitionId': string;
[key: string]: any;
}>;

export const entities = { serviceEntity, hostEntity, containerEntity };
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { EntityDataStreamType, EntityFields } from '.';
import { Serializable } from '../serializable';

class ServiceEntity extends Serializable<EntityFields> {
constructor(fields: EntityFields) {
super({
...fields,
'entity.type': 'service',
'entity.definitionId': 'latest',
});
}
}

export function serviceEntity({
agentName,
dataStreamType,
serviceName,
environment,
entityId,
}: {
agentName: string[];
serviceName: string;
dataStreamType: EntityDataStreamType[];
environment?: string;
entityId: string;
}) {
return new ServiceEntity({
'service.name': serviceName,
'service.environment': environment,
'source_data_stream.type': dataStreamType,
'agent.name': agentName,
'entity.id': entityId,
});
}
2 changes: 1 addition & 1 deletion packages/kbn-apm-synthtrace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export { InfraSynthtraceEsClient } from './src/lib/infra/infra_synthtrace_es_cli
export { InfraSynthtraceKibanaClient } from './src/lib/infra/infra_synthtrace_kibana_client';
export { MonitoringSynthtraceEsClient } from './src/lib/monitoring/monitoring_synthtrace_es_client';
export { LogsSynthtraceEsClient } from './src/lib/logs/logs_synthtrace_es_client';
export { AssetsSynthtraceEsClient } from './src/lib/assets/assets_synthtrace_es_client';
export { EntitiesSynthtraceEsClient } from './src/lib/entities/entities_synthtrace_es_client';
export { SyntheticsSynthtraceEsClient } from './src/lib/synthetics/synthetics_synthtrace_es_client';
export {
addObserverVersionTransform,
Expand Down
11 changes: 8 additions & 3 deletions packages/kbn-apm-synthtrace/src/cli/scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@ import {
InfraSynthtraceEsClient,
LogsSynthtraceEsClient,
SyntheticsSynthtraceEsClient,
EntitiesSynthtraceEsClient,
} from '../..';
import { AssetsSynthtraceEsClient } from '../lib/assets/assets_synthtrace_es_client';
import { Logger } from '../lib/utils/create_logger';
import { ScenarioReturnType } from '../lib/utils/with_client';
import { RunOptions } from './utils/parse_run_cli_flags';
import { EntitiesSynthtraceKibanaClient } from '../lib/apm/client/entities_synthtrace_kibana_client';

interface EsClients {
apmEsClient: ApmSynthtraceEsClient;
logsEsClient: LogsSynthtraceEsClient;
infraEsClient: InfraSynthtraceEsClient;
assetsEsClient: AssetsSynthtraceEsClient;
syntheticsEsClient: SyntheticsSynthtraceEsClient;
entitiesEsClient: EntitiesSynthtraceEsClient;
}

interface KibanaClients {
entitiesKibanaClient: EntitiesSynthtraceKibanaClient;
}

type Generate<TFields> = (options: {
Expand All @@ -33,6 +38,6 @@ type Generate<TFields> = (options: {
}) => ScenarioReturnType<TFields> | Array<ScenarioReturnType<TFields>>;

export type Scenario<TFields> = (options: RunOptions & { logger: Logger }) => Promise<{
bootstrap?: (options: EsClients) => Promise<void>;
bootstrap?: (options: EsClients & KibanaClients) => Promise<void>;
generate: Generate<TFields>;
}>;
15 changes: 11 additions & 4 deletions packages/kbn-apm-synthtrace/src/cli/utils/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import { getInfraEsClient } from './get_infra_es_client';
import { getKibanaClient } from './get_kibana_client';
import { getServiceUrls } from './get_service_urls';
import { RunOptions } from './parse_run_cli_flags';
import { getAssetsEsClient } from './get_assets_es_client';
import { getSyntheticsEsClient } from './get_synthetics_es_client';
import { getEntitiesEsClient } from './get_entities_es_client';
import { getEntitiesKibanaClient } from './get_entites_kibana_client';

export async function bootstrap(runOptions: RunOptions) {
const logger = createLogger(runOptions.logLevel);
Expand Down Expand Up @@ -57,12 +58,17 @@ export async function bootstrap(runOptions: RunOptions) {
concurrency: runOptions.concurrency,
});

const assetsEsClient = getAssetsEsClient({
const entitiesEsClient = getEntitiesEsClient({
target: esUrl,
logger,
concurrency: runOptions.concurrency,
});

const entitiesKibanaClient = getEntitiesKibanaClient({
target: kibanaUrl,
logger,
});

const syntheticsEsClient = getSyntheticsEsClient({
target: esUrl,
logger,
Expand All @@ -73,7 +79,7 @@ export async function bootstrap(runOptions: RunOptions) {
await apmEsClient.clean();
await logsEsClient.clean();
await infraEsClient.clean();
await assetsEsClient.clean();
await entitiesEsClient.clean();
await syntheticsEsClient.clean();
}

Expand All @@ -82,10 +88,11 @@ export async function bootstrap(runOptions: RunOptions) {
apmEsClient,
logsEsClient,
infraEsClient,
assetsEsClient,
entitiesEsClient,
syntheticsEsClient,
version,
kibanaUrl,
esUrl,
entitiesKibanaClient,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { LogDocument } from '@kbn/apm-synthtrace-client';
import { createAssetsAggregatorFactory } from '../../utils/create_assets_aggregator_factory';
import { EntitiesSynthtraceKibanaClient } from '../../lib/apm/client/entities_synthtrace_kibana_client';
import { Logger } from '../../lib/utils/create_logger';

export const createLogsAssetsAggregator = createAssetsAggregatorFactory<LogDocument>();
export function getEntitiesKibanaClient({ target, logger }: { target: string; logger: Logger }) {
const kibanaClient = new EntitiesSynthtraceKibanaClient({
logger,
target,
});

return kibanaClient;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
*/

import { Client } from '@elastic/elasticsearch';
import { AssetsSynthtraceEsClient } from '../../lib/assets/assets_synthtrace_es_client';
import { EntitiesSynthtraceEsClient } from '../../lib/entities/entities_synthtrace_es_client';
import { Logger } from '../../lib/utils/create_logger';
import { RunOptions } from './parse_run_cli_flags';
import { getEsClientTlsSettings } from './ssl';

export function getAssetsEsClient({
export function getEntitiesEsClient({
target,
logger,
concurrency,
Expand All @@ -26,7 +26,7 @@ export function getAssetsEsClient({
tls: getEsClientTlsSettings(target),
});

return new AssetsSynthtraceEsClient({
return new EntitiesSynthtraceEsClient({
client,
logger,
concurrency,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function startHistoricalDataUpload({
from: Date;
to: Date;
}) {
const { logger, esUrl, version } = await bootstrap(runOptions);
const { logger, esUrl, version, kibanaUrl } = await bootstrap(runOptions);

const cores = cpus().length;

Expand Down Expand Up @@ -93,6 +93,7 @@ export async function startHistoricalDataUpload({
workerId: workerIndex.toString(),
esUrl,
version,
kibanaUrl,
};
const worker = new Worker(Path.join(__dirname, './worker.js'), {
workerData,
Expand Down
Loading