Skip to content

Commit

Permalink
draft of aws rds synthtrace scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
crespocarlos committed Apr 2, 2024
1 parent 3fd71e7 commit 86319b2
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/kbn-apm-synthtrace-client/src/lib/assets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends AssetKind> extends Fields {
'asset.kind': T;
Expand Down Expand Up @@ -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'>;
67 changes: 67 additions & 0 deletions packages/kbn-apm-synthtrace-client/src/lib/infra/aws/rds.ts
Original file line number Diff line number Diff line change
@@ -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<AWSRdsDocument> {
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<AWSRdsMetricsDocument> {}

export function awsRds(arn: string, name: string): AWSRds {
return new AWSRds({
'aws.rds.db_instance.arn': arn,
'aws.rds.db_instance.identifier': name,
});
}
8 changes: 7 additions & 1 deletion packages/kbn-apm-synthtrace-client/src/lib/infra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
39 changes: 39 additions & 0 deletions packages/kbn-apm-synthtrace/src/scenarios/infra_aws_rds.ts
Original file line number Diff line number Diff line change
@@ -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<InfraDocument | ApmFields> = 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;

0 comments on commit 86319b2

Please sign in to comment.