Skip to content

Commit

Permalink
fixed rds and aws cpu percentages. (#188768)
Browse files Browse the repository at this point in the history
## Summary

This PR fixes incorrect cpu percentage values in AWS and Redis metrics
displayed on the Infra inventory page. (#179807)
I also added synthtrace for redis based off #179809
<img width="2672" alt="Screenshot 2024-07-19 at 09 32 55"
src="https://github.com/user-attachments/assets/23dd4c83-a11c-4ad9-87df-b0bf620b8e31">
  • Loading branch information
bryce-b authored Jul 29, 2024
1 parent a7047c3 commit 80cd581
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/kbn-apm-synthtrace-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export { httpExitSpan } from './src/lib/apm/span';
export { DistributedTrace } from './src/lib/dsl/distributed_trace_client';
export { serviceMap } from './src/lib/dsl/service_map';
export type { Fields } from './src/lib/entity';
export { Entity } from './src/lib/entity';
export { infra, type InfraDocument } from './src/lib/infra';
export { parseInterval } from './src/lib/interval';
export { monitoring, type MonitoringDocument } from './src/lib/monitoring';
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-apm-synthtrace-client/src/lib/assets/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { Fields } from '../entity';
import { Serializable } from '../serializable';

type AssetType = 'host' | 'pod' | 'container' | 'service';
type AssetType = 'host' | 'pod' | 'container' | 'service' | 'aws_rds';

export interface AssetDocument extends Fields {
'asset.id': string;
Expand Down
49 changes: 49 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,49 @@
/*
* 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 { Entity, Fields } from '../../entity';
import { Serializable } from '../../serializable';

export interface AWSRdsDocument extends Fields {
'aws.rds.db_instance.arn': string;
'aws.rds.db_instance.identifier': string;
'metricset.name'?: string;
'event.dataset'?: string;
}

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 class AWSRds extends Entity<AWSRdsDocument> {
metrics(metricsFields: AWSRdsMetricsDocument) {
return new AWSRdsMetrics({
...this.fields,
...metricsFields,
});
}
}

export function awsRds(arn: string, name: string): AWSRds {
return new AWSRds({
'aws.rds.db_instance.arn': arn,
'aws.rds.db_instance.identifier': name,
'event.dataset': 'aws.rds',
});
}
5 changes: 4 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 @@ -10,16 +10,19 @@ import { dockerContainer, DockerContainerMetricsDocument } from './docker_contai
import { host, HostMetricsDocument } from './host';
import { k8sContainer, K8sContainerMetricsDocument } from './k8s_container';
import { pod, PodMetricsDocument } from './pod';
import { awsRds, AWSRdsMetricsDocument } from './aws/rds';

export type InfraDocument =
| HostMetricsDocument
| PodMetricsDocument
| DockerContainerMetricsDocument
| K8sContainerMetricsDocument;
| K8sContainerMetricsDocument
| AWSRdsMetricsDocument;

export const infra = {
host,
pod,
dockerContainer,
k8sContainer,
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
56 changes: 56 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,56 @@
/*
* 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, ApmFields, infra } 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({
...item.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,
})
.timestamp(timestamp),
])
);

return [
withClient(
infraEsClient,
logger.perf('generating_infra_aws_rds', () => rds)
),
];
},
};
};

export default scenario;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const cpu: MetricsUIAggregation = {
cpu: 'cpu_avg',
},
script: {
source: 'params.cpu / 100',
source: 'params.cpu',
lang: 'painless',
},
gap_policy: 'skip',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const awsEC2CpuUtilization = createTSVBModel(
},
{
id: 'convert-to-percent',
script: 'params.avg / 100',
script: 'params.avg',
type: 'calculation',
variables: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const cpu: MetricsUIAggregation = {
cpu: 'cpu_avg',
},
script: {
source: 'params.cpu / 100',
source: 'params.cpu',
lang: 'painless',
},
gap_policy: 'skip',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const awsRDSCpuTotal = createTSVBModel(
},
{
id: 'convert-to-percent',
script: 'params.avg / 100',
script: 'params.avg',
type: 'calculation',
variables: [
{
Expand Down

0 comments on commit 80cd581

Please sign in to comment.