diff --git a/packages/kbn-apm-synthtrace-client/src/lib/assets/index.ts b/packages/kbn-apm-synthtrace-client/src/lib/assets/index.ts index f449dd75972b7..6e6bd08908557 100644 --- a/packages/kbn-apm-synthtrace-client/src/lib/assets/index.ts +++ b/packages/kbn-apm-synthtrace-client/src/lib/assets/index.ts @@ -11,7 +11,7 @@ import { Fields } from '../entity'; import { Serializable } from '../serializable'; // Can I pull in types from asset-manager here? -type AssetKind = 'host' | 'pod' | 'container' | 'service'; +type AssetKind = 'host' | 'pod' | 'container' | 'service' | 'aws_rds'; export interface AssetKindDocument extends Fields { 'asset.kind': T; @@ -46,10 +46,13 @@ export class PodAsset extends Asset<'pod'> {} export class ContainerAsset extends Asset<'container'> {} +export class AWSRedisAsset extends Asset<'aws_rds'> {} + export class ServiceAsset extends Asset<'service'> {} export type AssetDocument = | AssetKindDocument<'host'> | AssetKindDocument<'pod'> | AssetKindDocument<'container'> - | AssetKindDocument<'service'>; + | AssetKindDocument<'service'> + | AssetKindDocument<'aws_rds'>; diff --git a/packages/kbn-apm-synthtrace-client/src/lib/infra/aws/rds.ts b/packages/kbn-apm-synthtrace-client/src/lib/infra/aws/rds.ts new file mode 100644 index 0000000000000..d003a913b04b4 --- /dev/null +++ b/packages/kbn-apm-synthtrace-client/src/lib/infra/aws/rds.ts @@ -0,0 +1,67 @@ +/* + * 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 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 or the Server + * Side Public License, v 1. + */ + +/* eslint-disable max-classes-per-file */ +import { AWSRedisAsset } from '../../assets'; +import { Entity, Fields } from '../../entity'; +import { Serializable } from '../../serializable'; + +interface AWSRdsDocument extends Fields { + 'aws.rds.db_instance.arn': string; + 'aws.rds.db_instance.identifier': string; + 'metricset.name'?: string; + 'event.dataset'?: string; +} + +export class AWSRds extends Entity { + metrics() { + return new AWSRdsMetrics({ + ...this.fields, + 'aws.rds.cpu.total.pct': 0.4, + 'aws.rds.database_connections': 5, + 'aws.rds.latency.read': 500 * 1000, + 'aws.rds.latency.write': 500 * 1000, + 'aws.rds.latency.insert': 500 * 1000, + 'aws.rds.latency.update': 500 * 1000, + 'aws.rds.latency.commit': 500 * 1000, + 'aws.rds.latency.dml': 500 * 1000, + 'aws.rds.queries': 100, + 'event.dataset': 'aws.rds', + }); + } + + asset() { + return new AWSRedisAsset({ + 'asset.kind': 'aws_rds', + 'asset.id': this.fields['aws.rds.db_instance.arn'], + 'asset.name': this.fields['aws.rds.db_instance.identifier'], + 'asset.ean': `aws_rds:${'aws.rds.db_instance.arn'}`, + }); + } +} + +export interface AWSRdsMetricsDocument extends AWSRdsDocument { + 'aws.rds.cpu.total.pct'?: number; + 'aws.rds.database_connections'?: number; + 'aws.rds.latency.dml'?: number; + 'aws.rds.latency.read'?: number; + 'aws.rds.latency.write'?: number; + 'aws.rds.latency.insert'?: number; + 'aws.rds.latency.update'?: number; + 'aws.rds.latency.commit'?: number; + 'aws.rds.queries'?: number; +} + +class AWSRdsMetrics extends Serializable {} + +export function awsRds(arn: string, name: string): AWSRds { + return new AWSRds({ + 'aws.rds.db_instance.arn': arn, + 'aws.rds.db_instance.identifier': name, + }); +} diff --git a/packages/kbn-apm-synthtrace-client/src/lib/infra/index.ts b/packages/kbn-apm-synthtrace-client/src/lib/infra/index.ts index 961225670e27b..b99e0d0780a44 100644 --- a/packages/kbn-apm-synthtrace-client/src/lib/infra/index.ts +++ b/packages/kbn-apm-synthtrace-client/src/lib/infra/index.ts @@ -9,11 +9,17 @@ import { container, ContainerMetricsDocument } from './container'; import { host, HostMetricsDocument } from './host'; import { pod, PodMetricsDocument } from './pod'; +import { awsRds, AWSRdsMetricsDocument } from './aws/rds'; -export type InfraDocument = HostMetricsDocument | PodMetricsDocument | ContainerMetricsDocument; +export type InfraDocument = + | HostMetricsDocument + | PodMetricsDocument + | ContainerMetricsDocument + | AWSRdsMetricsDocument; export const infra = { host, pod, container, + awsRds, }; diff --git a/packages/kbn-apm-synthtrace/src/lib/infra/infra_synthtrace_es_client.ts b/packages/kbn-apm-synthtrace/src/lib/infra/infra_synthtrace_es_client.ts index 031c40c9ccf19..6c42d7051a9b0 100644 --- a/packages/kbn-apm-synthtrace/src/lib/infra/infra_synthtrace_es_client.ts +++ b/packages/kbn-apm-synthtrace/src/lib/infra/infra_synthtrace_es_client.ts @@ -64,6 +64,8 @@ function getRoutingTransform() { document._index = 'metrics-kubernetes.container-default'; } else if ('kubernetes.pod.uid' in document) { document._index = 'metrics-kubernetes.pod-default'; + } else if ('aws.rds.db_instance.arn' in document) { + document._index = 'metrics-aws.rds-default'; } else { throw new Error('Cannot determine index for event'); } diff --git a/packages/kbn-apm-synthtrace/src/scenarios/infra_aws_rds.ts b/packages/kbn-apm-synthtrace/src/scenarios/infra_aws_rds.ts new file mode 100644 index 0000000000000..23cdd9403ec1e --- /dev/null +++ b/packages/kbn-apm-synthtrace/src/scenarios/infra_aws_rds.ts @@ -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 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 or the Server + * Side Public License, v 1. + */ +import { InfraDocument, infra, ApmFields } from '@kbn/apm-synthtrace-client'; +import { Scenario } from '../cli/scenario'; +import { withClient } from '../lib/utils/with_client'; + +const numRds = 50; +const scenario: Scenario = async (runOptions) => { + return { + generate: ({ range, clients: { infraEsClient } }) => { + const { logger } = runOptions; + + // Infra hosts Data logic + + const RDS = Array(numRds) + .fill(0) + .map((_, idx) => infra.awsRds(`redis-${idx}`, `redis-${idx}`)); + + const rds = range + .interval('30s') + .rate(1) + .generator((timestamp) => RDS.flatMap((item) => [item.metrics().timestamp(timestamp)])); + + return [ + withClient( + infraEsClient, + logger.perf('generating_infra_aws_rds', () => rds) + ), + ]; + }, + }; +}; + +export default scenario;